Skip to content

Commit 901dfb6

Browse files
authored
Merge pull request #53 from dotkernel/issue-52-v5
Issue #52: `v5` maintenance mode
2 parents 4b6b84d + 72a65aa commit 901dfb6

12 files changed

Lines changed: 69 additions & 55 deletions

File tree

.laminas-ci.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ignore_php_platform_requirements": {
3+
"8.4": true
4+
},
5+
"backwardCompatibilityCheck": true
6+
}

OSSMETADATA

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
osslifecycle=active
1+
osslifecycle=maintenance

README.md

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ DotKernel dependency injection service.
44

55
This 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

2321
Install `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

2727
After 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

3537
You 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

4953
use 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

6369
The `#[Inject]` attribute is telling `AttributedServiceFactory` to inject the services specified as parameters.
6470
Valid 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

6874
use Dot\AnnotatedServices\Attribute\Inject;
6975

70-
#[Inject(
71-
"config.debug",
72-
)]
76+
```php
77+
#[Inject(
78+
"config.debug",
79+
)]
80+
```
7381

7482
which will inject `$container->get('config')['debug'];`.
7583

@@ -81,30 +89,34 @@ which will inject `$container->get('config')['debug'];`.
8189

8290
You 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

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

92102
The `name` field has to be the fully qualified class name.
93103

94104
Every 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)

SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
| Version | Supported | PHP Version |
77
|---------|--------------------|------------------------------------------------------------------------------------------------------------------------|
8-
| 5.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/5.0.0) |
9-
| 4.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.1.7) |
8+
| 5.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/5.2.0) |
9+
| 4.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.2.0) |
1010
| <= 3.x | :x: | |
1111

1212

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
"service"
2121
],
2222
"require": {
23-
"php": "~8.2.0 || ~8.3.0",
23+
"php": "~8.2.0 || ~8.3.0 || ~8.4.0",
2424
"doctrine/orm": "^2.9 || ^3.0",
2525
"psr/container": "^1.0 || ^2.0"
2626
},
2727
"require-dev": {
2828
"phpunit/phpunit": "^10.5",
2929
"vimeo/psalm": "^5.20",
30-
"laminas/laminas-coding-standard": "^2.5"
30+
"laminas/laminas-coding-standard": "^3.0"
3131
},
3232
"autoload": {
3333
"psr-4": {

docs/book/index.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/book/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../README.md

docs/book/v4/factories/repository.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Inject entity repositories
22

3-
43
## Prepare repository
54

65
`dot-annotated-services` determines the entity a repository is related to by looking at the `@Entity` annotation, added to the repository class.
@@ -22,7 +21,6 @@ class ExampleRepository extends Doctrine\ORM\EntityRepository
2221

2322
Each entity repository must extend `Doctrine\ORM\EntityRepository`.
2423

25-
2624
## Register repository
2725

2826
Open the ConfigProvider of the module where your repository resides.

docs/book/v4/factories/service.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Inject class dependencies
22

3-
43
## Prepare class
54

65
`dot-annotated-services` determines the dependencies by looking at the `@Inject` annotation, added to the constructor of a class.
@@ -49,7 +48,6 @@ If your class needs the value of a specific configuration key, you can specify t
4948
}
5049
```
5150

52-
5351
## Register class
5452

5553
Open the ConfigProvider of the module where your class resides.

docs/book/v5/factories/repository.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Inject entity repositories
22

3-
43
## Prepare repository
54

65
`dot-annotated-services` determines the entity a repository is related to by looking at the `#[Entity]` attribute, added to the repository class.
@@ -20,7 +19,6 @@ class ExampleRepository extends Doctrine\ORM\EntityRepository
2019

2120
Each entity repository must extend `Doctrine\ORM\EntityRepository`.
2221

23-
2422
## Register repository
2523

2624
Open the ConfigProvider of the module where your repository resides.

0 commit comments

Comments
 (0)