Skip to content

Commit a938e86

Browse files
authored
Merge pull request #44 from dotkernel/try-laminas-ci
Try Laminas CI
2 parents b292ed8 + 2ce6ed1 commit a938e86

13 files changed

Lines changed: 60 additions & 197 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: "Continuous Integration"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
tags:
8+
9+
jobs:
10+
ci:
11+
uses: laminas/workflow-continuous-integration/.github/workflows/continuous-integration.yml@1.x

.github/workflows/cs-tests.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

.github/workflows/static-analysis.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

.github/workflows/unit-test.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

README.md

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,102 +17,94 @@ This package can clean up your code, by getting rid of all the factories you wri
1717

1818
[![SymfonyInsight](https://insight.symfony.com/projects/a0d7016e-fc3f-46b8-9b36-571ff060d744/big.svg)](https://insight.symfony.com/projects/a0d7016e-fc3f-46b8-9b36-571ff060d744)
1919

20-
2120
## Installation
2221

2322
Install `dot-annotated-services` by running the following command in your project directory:
2423

2524
composer require dotkernel/dot-annotated-services
2625

27-
2826
After installing, register `dot-annotated-services` in your project by adding the below line to your configuration aggregate (usually: `config/config.php`):
2927

3028
Dot\AnnotatedServices\ConfigProvider::class,
3129

32-
3330
## Usage
3431

3532
### Using the AttributedServiceFactory
3633

3734
You can register services in the service manager using `AttributedServiceFactory` as seen in the below example:
3835

39-
```php
40-
return [
41-
'factories' => [
42-
ServiceClass::class => AttributedServiceFactory::class,
43-
],
44-
];
45-
```
46-
36+
return [
37+
'factories' => [
38+
ServiceClass::class => AttributedServiceFactory::class,
39+
],
40+
];
4741

4842
### NOTE
43+
4944
> You can use only the fully qualified class name as the service key
5045
5146
The next step is to add the `#[Inject]` attribute to the service constructor with the service FQCNs to inject:
5247

53-
```php
5448
use Dot\AnnotatedServices\Attribute\Inject;
5549

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-
```
50+
#[Inject(
51+
App\Srevice\Dependency1::class,
52+
App\Srevice\Dependency2::class,
53+
"config",
54+
)]
55+
public function __construct(
56+
protected App\Srevice\Dependency1 $dep1,
57+
protected App\Srevice\Dependency2 $dep2,
58+
protected array $config
59+
) {
60+
}
6861

6962
The `#[Inject]` attribute is telling `AttributedServiceFactory` to inject the services specified as parameters.
7063
Valid service names should be provided, as registered in the service manager.
7164

7265
To inject an array value from the service manager, you can use dot notation as below
7366

74-
```php
7567
use Dot\AnnotatedServices\Attribute\Inject;
7668

77-
#[Inject(
78-
"config.debug",
79-
)]
80-
```
69+
#[Inject(
70+
"config.debug",
71+
)]
72+
8173
which will inject `$container->get('config')['debug'];`.
8274

75+
### NOTE
8376

84-
### NOTE
8577
> Even if using dot notation, `AttributedServiceFactory` will check first if a service name exists with that name.
8678
79+
### Using the AttributedRepositoryFactory
8780

88-
### Using the AttributedRepositoryFactory
8981
You can register doctrine repositories and inject them using the `AttributedRepositoryFactory` as below:
90-
```php
91-
return [
92-
'factories' => [
93-
ExampleRepository::class => AttributedRepositoryFactory::class,
94-
],
95-
];
96-
```
82+
83+
return [
84+
'factories' => [
85+
ExampleRepository::class => AttributedRepositoryFactory::class,
86+
],
87+
];
9788

9889
The next step is to add the `#[Entity]` attribute in the repository class.
9990

10091
The `name` field has to be the fully qualified class name.
10192

10293
Every repository should extend `Doctrine\ORM\EntityRepository`.
103-
```php
104-
use Api\App\Entity\Example;
105-
use Doctrine\ORM\EntityRepository;
106-
use Dot\AnnotatedServices\Attribute\Entity;
10794

108-
#[Entity(name: Example::class)]
109-
class ExampleRepository extends EntityRepository
110-
{
111-
}
112-
```
95+
use Api\App\Entity\Example;
96+
use Doctrine\ORM\EntityRepository;
97+
use Dot\AnnotatedServices\Attribute\Entity;
98+
99+
#[Entity(name: Example::class)]
100+
class ExampleRepository extends EntityRepository
101+
{
102+
}
113103

114104
### NOTE
105+
115106
Starting from version `5.0` of `dot-annotated-services`:
107+
116108
- services can only be injected using the `#[Inject]` attribute (`@Inject` and `@Service` annotations are no longer supported)
117109
- repository-entity relation can only be established using the `#[Entity]` attribute (`@Entity` annotation is no longer supported)
118110
- dependencies injected via the`#[Entity]`/`#[Inject]` attributes are not cached

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
],
2222
"require": {
2323
"php": "~8.2.0 || ~8.3.0",
24-
"doctrine/orm": "^2.0 || ^3.0",
24+
"doctrine/orm": "^2.9 || ^3.0",
2525
"psr/container": "^1.0 || ^2.0"
2626
},
2727
"require-dev": {

docs/book/v4/cache.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
`dot-annotated-services` reads class annotations using [doctrine/annotations](https://github.com/doctrine/annotations) and caches them using [doctrine/cache](https://github.com/doctrine/cache).
44

5-
65
## Configuration
76

87
In 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.
@@ -19,7 +18,9 @@ You can add this configuration values to your application's Doctrine config file
1918
],
2019
];
2120
```
21+
2222
where `AnnotationsCacheFactory` is a custom factory that needs to return a [Doctrine Cache Driver](https://github.com/doctrine/cache/tree/1.13.x/lib/Doctrine/Common/Cache):
23+
2324
```php
2425
<?php
2526

docs/book/v4/configuration.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
After installation, register `dot-annotated-services` in your project by adding the below line to your configuration aggregator (usually: `config/config.php`):
44

55
Dot\AnnotatedServices\ConfigProvider::class,
6-

docs/book/v4/factories.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66

77
Injects entity repositories into a class.
88

9-
109
### Exceptions thrown
10+
1111
- `Dot\AnnotatedServices\Exception\RuntimeException` if repository does not exist
1212
- `Dot\AnnotatedServices\Exception\RuntimeException` if repository does not extend `Doctrine\ORM\EntityRepository`
1313
- `Dot\AnnotatedServices\Exception\RuntimeException` if repository does not have `@Entity` annotation
1414
- `Psr\Container\NotFoundExceptionInterface` if `Doctrine\ORM\EntityManagerInterface` does not exist in the service container
1515
- `Psr\Container\ContainerExceptionInterface` if service manager is unable to provide an instance of `Doctrine\ORM\EntityManagerInterface`
1616

17-
1817
## AttributedServiceFactory
1918

2019
Injects class dependencies into classes.
@@ -24,15 +23,14 @@ If it does not find one, it will try to load the dependency as a config tree, ch
2423

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

27-
2826
### Exceptions thrown
27+
2928
- `Dot\AnnotatedServices\Exception\RuntimeException` if service does not exist
3029
- `Dot\AnnotatedServices\Exception\RuntimeException` if service does not have `@Inject` annotation on it's constructor
3130
- `ReflectionException` on failure of creating a ReflectionClass of the dependency
3231
- `Psr\Container\NotFoundExceptionInterface` if a dependency does not exist in the service container
3332
- `Psr\Container\ContainerExceptionInterface` if service manager is unable to provide an instance of a dependency
3433

35-
3634
## AnnotatedServiceAbstractFactory
3735

3836
Using this approach, no service manager configuration is required. It uses the registered abstract factory to create annotated services.
@@ -66,4 +64,5 @@ class Example
6664
}
6765
}
6866
```
67+
6968
And that's it, you don't need to configure the service manager with this class, creation will happen automatically.

docs/book/v4/usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
Version `4.x` of `dot-annotated-services` is the last version that uses [doctrine/annotations](https://github.com/doctrine/annotations) to parse and inject dependencies.
44

55
You can use it to:
6+
67
- [Inject class dependencies](factories/service.md)
78
- [Inject entity repositories](factories/repository.md)

0 commit comments

Comments
 (0)