{"id":20103167,"url":"https://github.com/dotkernel/dot-annotated-services","last_synced_at":"2025-10-11T20:13:11.480Z","repository":{"id":41416621,"uuid":"79565561","full_name":"dotkernel/dot-annotated-services","owner":"dotkernel","description":"DotKernel service creation component through laminas-servicemanager and annotations","archived":false,"fork":false,"pushed_at":"2025-03-04T15:32:41.000Z","size":453,"stargazers_count":8,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"4.0","last_synced_at":"2025-05-06T08:47:52.541Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.dotkernel.org/dot-annotated-services/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dotkernel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-01-20T14:25:48.000Z","updated_at":"2025-03-04T15:30:53.000Z","dependencies_parsed_at":"2024-03-07T08:29:48.559Z","dependency_job_id":"57db6f55-3196-4325-80ed-50608633eafc","html_url":"https://github.com/dotkernel/dot-annotated-services","commit_stats":{"total_commits":42,"total_committers":8,"mean_commits":5.25,"dds":0.5476190476190477,"last_synced_commit":"6cf2d356e0938d5bcfd1af63276956f9ac312520"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/dotkernel/dot-annotated-services","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-annotated-services","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-annotated-services/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-annotated-services/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-annotated-services/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotkernel","download_url":"https://codeload.github.com/dotkernel/dot-annotated-services/tar.gz/refs/heads/4.0","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-annotated-services/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008577,"owners_count":26084480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T17:34:32.607Z","updated_at":"2025-10-11T20:13:11.446Z","avatar_url":"https://github.com/dotkernel.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dot-annotated-services\n\nDotkernel component used to create services through [Laminas Service Manager](https://github.com/laminas/laminas-servicemanager) and inject them with dependencies just using method annotations.\nIt can also create services without the need to write factories.\nAnnotation parsing can be cached, to improve performance.\n\nThis package can clean up your code, by getting rid of all the factories you write, sometimes just to inject a dependency or two.\n\n## Documentation\n\nDocumentation is available at: https://docs.dotkernel.org/dot-annotated-services/.\n\n## Badges\n\n![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-annotated-services%2Fblob%2F4.0%2FOSSMETADATA)\n![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.3.0)\n\n[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/issues)\n[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/network)\n[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/stargazers)\n[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/blob/4.0/LICENSE.md)\n\n[![Build Static](https://github.com/dotkernel/dot-annotated-services/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-annotated-services/actions/workflows/continuous-integration.yml)\n[![codecov](https://codecov.io/gh/dotkernel/dot-annotated-services/graph/badge.svg?token=ZBZDEA3LY8)](https://codecov.io/gh/dotkernel/dot-annotated-services)\n[![PHPStan](https://github.com/dotkernel/dot-annotated-services/actions/workflows/static-analysis.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-annotated-services/actions/workflows/static-analysis.yml)\n\n## Installation\n\nRun the following command in your project directory\n\n```shell\ncomposer require dotkernel/dot-annotated-services\n```\n\nAfter installing, add the `ConfigProvider` class to your configuration aggregate.\n\n## Usage\n\n### Using the AnnotatedServiceFactory\n\nYou can register services in the service manager using the `AnnotatedServiceFactory` as below.\n\n```php\nreturn [\n    'factories' =\u003e [\n        ServiceClass::class =\u003e AnnotatedServiceFactory::class,\n    ],\n];\n```\n\n\u003e You can use only the fully qualified class name as the service key.\n\nThe next step is to annotate the service constructor or setters with the service names to inject.\n\n```php\nuse Dot\\AnnotatedServices\\Annotation\\Inject;\n\n/**\n * @Inject({\n *     Dependency1::class,\n *     Dependency2::class,\n *     \"config\"\n * })\n */\npublic function __construct(\n    protected Dependency1 $dep1,\n    protected Dependency2 $dep2,\n    protected array $config\n) {\n}\n```\n\nThe annotation `@Inject` is telling the factory to inject the services between curly braces.\nValid service names should be provided, as registered in the service manager.\n\nTo inject an array value from the service manager, you can use dot notation as below,\n\n```php\nuse Dot\\AnnotatedServices\\Annotation\\Inject;\n\n/**\n * @Inject({\"config.debug\"})\n */\n```\n\nwhich will inject `$container-\u003eget('config')['debug'];`\n\n\u003e Even if using dot annotation, the annotated factory will check first if a service name exists with that name.\n\nYou can use the inject annotation on setters too, they will be called at creation time and injected with the configured dependencies.\n\n### Using the AnnotatedRepositoryFactory\n\nYou can register doctrine repositories and inject them using the AnnotatedRepositoryFactory as below.\n\n```php\nreturn [\n    'factories' =\u003e [\n        ExampleRepository::class =\u003e AnnotatedRepositoryFactory::class,\n    ],\n];\n```\n\nThe next step is to add the `@Entity` annotation in the repository class.\n\nThe `name` field has to be the fully qualified class name.\n\nEvery repository should extend `Doctrine\\ORM\\EntityRepository`.\n\n```php\nuse Doctrine\\ORM\\EntityRepository;\nuse Dot\\AnnotatedServices\\Annotation\\Entity;\n\n/**\n * @Entity(name=\"App\\Entity\\Example\")\n */\nclass ExampleRepository extends EntityRepository\n{\n}\n```\n\n### Using the abstract factory\n\nUsing this approach, no service manager configuration is required. It uses the registered abstract factory to create annotated services.\n\nIn order to tell the abstract factory which services are to be created, you need to annotate the service class with the `@Service` annotation.\n\n```php\nuse Dot\\AnnotatedServices\\Annotation\\Service;\n\n/*\n * @Service\n */\nclass ServiceClass\n{\n    // configure injections as described in the previous section\n}\n```\n\nAnd that's it, you don't need to configure the service manager with this class, creation will happen automatically.\n\n## Cache annotations\n\nThis package is built on top of `doctrine/annotation` and `doctrine/cache`.\nIn order to cache annotations, you should register a service factory at key `AbstractAnnotatedFactory::CACHE_SERVICE` that should return a valid `Doctrine\\Common\\Cache\\Cache` cache driver.\nSee [Cache Drivers](https://github.com/doctrine/cache/tree/master/lib/Doctrine/Common/Cache) for available implementations offered by doctrine.\n\nBelow, we give an example, as defined in our frontend and admin starter applications:\n\n```php\nreturn [\n    'annotations_cache_dir' =\u003e __DIR__ . '/../../data/cache/annotations',\n    'dependencies' =\u003e [\n        'factories' =\u003e [\n            // used by dot-annotated-services to cache annotations\n            // needs to return a cache instance from Doctrine\\Common\\Cache\n            AbstractAnnotatedFactory::CACHE_SERVICE =\u003e AnnotationsCacheFactory::class,\n        ]\n    ],\n];\n```\n\n```php\nnamespace Frontend\\App\\Factory;\n\nuse Doctrine\\Common\\Cache\\FilesystemCache;\nuse Psr\\Container\\ContainerInterface;\n\nclass AnnotationsCacheFactory\n{\n    public function __invoke(ContainerInterface $container)\n    {\n        //change this to suite your caching needs\n        return new FilesystemCache($container-\u003eget('config')['annotations_cache_dir']);\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotkernel%2Fdot-annotated-services","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotkernel%2Fdot-annotated-services","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotkernel%2Fdot-annotated-services/lists"}