dot-annotated-services is based on three reusable factories - AnnotatedRepositoryFactory, AnnotatedServiceFactory and AnnotatedServiceAbstractFactory - able to inject any dependency into a class.
Injects entity repositories into a class.
Dot\AnnotatedServices\Exception\RuntimeExceptionif repository does not existDot\AnnotatedServices\Exception\RuntimeExceptionif repository does not extendDoctrine\ORM\EntityRepositoryDot\AnnotatedServices\Exception\RuntimeExceptionif repository does not have@EntityannotationPsr\Container\NotFoundExceptionInterfaceifDoctrine\ORM\EntityManagerInterfacedoes not exist in the service containerPsr\Container\ContainerExceptionInterfaceif service manager is unable to provide an instance ofDoctrine\ORM\EntityManagerInterface
Injects class dependencies into classes.
If a dependency is specified using the dot notation, AttributedServiceFactory will try to load a service having that specific alias.
If it does not find one, it will try to load the dependency as a config tree, checking each segment if it's available in the service container.
You can use the @Inject annotation on setters too, they will be called at creation time and injected with the configured dependencies.
Dot\AnnotatedServices\Exception\RuntimeExceptionif service does not existDot\AnnotatedServices\Exception\RuntimeExceptionif service does not have@Injectannotation on it's constructorReflectionExceptionon failure of creating a ReflectionClass of the dependencyPsr\Container\NotFoundExceptionInterfaceif a dependency does not exist in the service containerPsr\Container\ContainerExceptionInterfaceif service manager is unable to provide an instance of a dependency
Using this approach, no service manager configuration is required. It uses the registered abstract factory to create annotated services.
To tell the abstract factory which services are to be created, you need to annotate the service class with the @Service annotation.
<?php
declare(strict_types=1);
namespace YourApp\Service;
/**
* @Dot\AnnotatedServices\Annotation\Service
*/
class Example
{
/**
* @Dot\AnnotatedServices\Annotation\Inject({
* YourApp\Repository\Dependency1::class,
* YourApp\Repository\Dependency2::class,
* "config.example"
* })
*/
public function __construct(
protected YourApp\Repository\Dependency1 $dependency1,
protected YourApp\Helper\Dependency2 $dependency2,
protected array $exampleConfig,
) {
}
}And that's it, you don't need to configure the service manager with this class, creation will happen automatically.