Skip to content

Commit b6fba38

Browse files
committed
added documentation
1 parent c8fe20f commit b6fba38

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,34 @@ which will inject `$container->get('config')['debug'];`
7171

7272
You can use the inject annotation on setters too, they will be called at creation time and injected with the configured dependencies.
7373

74+
### Using the AnnotatedRepositoryFactory
75+
You can register doctrine repositories and inject them using the AnnotatedRepositoryFactory as below:
76+
```php
77+
return [
78+
'factories' => [
79+
ExampleRepository::class => AnnotatedRepositoryFactory::class,
80+
],
81+
];
82+
```
83+
84+
The next step is to add the `@Entity` annotation in the repository class.
85+
86+
The `name` field has to be the fully qualified class name.
87+
88+
Every repository should extend `Doctrine\ORM\EntityRepository`.
89+
```php
90+
use Doctrine\ORM\EntityRepository;
91+
92+
/**
93+
* @Entity(name="App\Entity\Example")
94+
*/
95+
class ExampleRepository extends EntityRepository
96+
{
97+
98+
}
99+
```
100+
101+
74102
### Using the abstract factory
75103

76104
Using this approach, no service manager configuration is required. It uses the registered abstract factory to create annotated services.

tests/AnnotatedServiceFactoryTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ public function testReturnService()
105105
$inject = new Inject(['test']);
106106
$this->annotationReader->method('getMethodAnnotation')->willReturn($inject);
107107

108-
$this->subject
109-
->method('createAnnotationReader')
110-
->willReturn($this->annotationReader);
108+
$this->subject->method('createAnnotationReader')->willReturn($this->annotationReader);
111109
$this->subject->method('getReflectionClass')->willReturn($refClass);
112110

113111
$service = $this->subject->__invoke($this->container, $requestedName);

0 commit comments

Comments
 (0)