@@ -4,8 +4,8 @@ DotKernel dependency injection service.
44
55This package can clean up your code, by getting rid of all the factories you write, sometimes just to inject a dependency or two.
66
7- ![ OSS Lifecycle] ( https://img.shields.io/osslifecycle/dotkernel/dot -annotated-services )
8- ![ PHP from Packagist (specify version)] ( https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/5.1 .0 )
7+ ![ OSS Lifecycle] ( https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot -annotated-services%2Fblob%2F5.0%2FOSSMETADATA )
8+ ![ PHP from Packagist (specify version)] ( https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/5.2 .0 )
99
1010[ ![ GitHub issues] ( https://img.shields.io/github/issues/dotkernel/dot-annotated-services )] ( https://github.com/dotkernel/dot-annotated-services/issues )
1111[ ![ GitHub forks] ( https://img.shields.io/github/forks/dotkernel/dot-annotated-services )] ( https://github.com/dotkernel/dot-annotated-services/network )
@@ -16,29 +16,33 @@ This package can clean up your code, by getting rid of all the factories you wri
1616[ ![ codecov] ( https://codecov.io/gh/dotkernel/dot-annotated-services/graph/badge.svg?token=ZBZDEA3LY8 )] ( https://codecov.io/gh/dotkernel/dot-annotated-services )
1717[ ![ docs-build] ( https://github.com/dotkernel/dot-annotated-services/actions/workflows/docs-build.yml/badge.svg )] ( https://github.com/dotkernel/dot-annotated-services/actions/workflows/docs-build.yml )
1818
19- [ ![ SymfonyInsight] ( https://insight.symfony.com/projects/a0d7016e-fc3f-46b8-9b36-571ff060d744/big.svg )] ( https://insight.symfony.com/projects/a0d7016e-fc3f-46b8-9b36-571ff060d744 )
20-
2119## Installation
2220
2321Install ` dot-annotated-services ` by running the following command in your project directory:
2422
25- composer require dotkernel/dot-annotated-services
23+ ``` shell
24+ composer require dotkernel/dot-annotated-services
25+ ```
2626
2727After installing, register ` dot-annotated-services ` in your project by adding the below line to your configuration aggregate (usually: ` config/config.php ` ):
2828
29- Dot\AnnotatedServices\ConfigProvider::class,
29+ ``` php
30+ Dot\AnnotatedServices\ConfigProvider::class,
31+ ```
3032
3133## Usage
3234
3335### Using the AttributedServiceFactory
3436
3537You can register services in the service manager using ` AttributedServiceFactory ` as seen in the below example:
3638
37- return [
38- 'factories' => [
39- ServiceClass::class => AttributedServiceFactory::class,
40- ],
41- ];
39+ ``` php
40+ return [
41+ 'factories' => [
42+ ServiceClass::class => AttributedServiceFactory::class,
43+ ],
44+ ];
45+ ```
4246
4347### NOTE
4448
@@ -48,17 +52,19 @@ The next step is to add the `#[Inject]` attribute to the service constructor wit
4852
4953use Dot\AnnotatedServices\Attribute\Inject;
5054
51- #[Inject(
52- App\Srevice\Dependency1::class,
53- App\Srevice\Dependency2::class,
54- "config",
55- )]
56- public function __construct(
57- protected App\Srevice\Dependency1 $dep1,
58- protected App\Srevice\Dependency2 $dep2,
59- protected array $config
60- ) {
61- }
55+ ``` php
56+ #[Inject(
57+ App\Srevice\Dependency1::class,
58+ App\Srevice\Dependency2::class,
59+ "config",
60+ )]
61+ public function __construct(
62+ protected App\Srevice\Dependency1 $dep1,
63+ protected App\Srevice\Dependency2 $dep2,
64+ protected array $config
65+ ) {
66+ }
67+ ```
6268
6369The ` #[Inject] ` attribute is telling ` AttributedServiceFactory ` to inject the services specified as parameters.
6470Valid service names should be provided, as registered in the service manager.
@@ -67,9 +73,11 @@ To inject an array value from the service manager, you can use dot notation as b
6773
6874use Dot\AnnotatedServices\Attribute\Inject;
6975
70- #[Inject(
71- "config.debug",
72- )]
76+ ``` php
77+ #[Inject(
78+ "config.debug",
79+ )]
80+ ```
7381
7482which will inject ` $container->get('config')['debug']; ` .
7583
@@ -81,30 +89,34 @@ which will inject `$container->get('config')['debug'];`.
8189
8290You can register doctrine repositories and inject them using the ` AttributedRepositoryFactory ` as below:
8391
84- return [
85- 'factories' => [
86- ExampleRepository::class => AttributedRepositoryFactory::class,
87- ],
88- ];
92+ ``` php
93+ return [
94+ 'factories' => [
95+ ExampleRepository::class => AttributedRepositoryFactory::class,
96+ ],
97+ ];
98+ ```
8999
90100The next step is to add the ` #[Entity] ` attribute in the repository class.
91101
92102The ` name ` field has to be the fully qualified class name.
93103
94104Every repository should extend ` Doctrine\ORM\EntityRepository ` .
95105
96- use Api\App\Entity\Example;
97- use Doctrine\ORM\EntityRepository;
98- use Dot\AnnotatedServices\Attribute\Entity;
99-
100- #[Entity(name: Example::class)]
101- class ExampleRepository extends EntityRepository
102- {
103- }
106+ ``` php
107+ use Api\App\Entity\Example;
108+ use Doctrine\ORM\EntityRepository;
109+ use Dot\AnnotatedServices\Attribute\Entity;
110+
111+ #[Entity(name: Example::class)]
112+ class ExampleRepository extends EntityRepository
113+ {
114+ }
115+ ```
104116
105117### NOTE
106118
107- Starting from version ` 5.0 ` of ` dot-annotated-services ` :
119+ In version ` 5.0 ` of ` dot-annotated-services ` :
108120
109121- services can only be injected using the ` #[Inject] ` attribute (` @Inject ` and ` @Service ` annotations are no longer supported)
110122- repository-entity relation can only be established using the ` #[Entity] ` attribute (` @Entity ` annotation is no longer supported)
0 commit comments