From 718a2bd35b5fc9464743bb4cd4b3a3dd055a3e0d Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Wed, 23 Oct 2024 08:06:02 +0300 Subject: [PATCH 1/3] Issue #52: v5 maintenance mode Signed-off-by: alexmerlin --- OSSMETADATA | 2 +- README.md | 90 +++++++++++++++++++++++----------------- composer.json | 4 +- docs/book/index.md | 2 +- docs/book/v5/overview.md | 4 ++ mkdocs.yml | 2 +- 6 files changed, 60 insertions(+), 44 deletions(-) mode change 100644 => 120000 docs/book/index.md diff --git a/OSSMETADATA b/OSSMETADATA index b96d4a4..8bff0a1 100644 --- a/OSSMETADATA +++ b/OSSMETADATA @@ -1 +1 @@ -osslifecycle=active +osslifecycle=maintenance diff --git a/README.md b/README.md index 38e9117..aeddfee 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ DotKernel dependency injection service. This package can clean up your code, by getting rid of all the factories you write, sometimes just to inject a dependency or two. -![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-annotated-services) -![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/5.1.0) +![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-annotated-services%2Fblob%2F5.0%2FOSSMETADATA) +![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/5.2.0) [![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/issues) [![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/network) @@ -16,17 +16,19 @@ This package can clean up your code, by getting rid of all the factories you wri [![codecov](https://codecov.io/gh/dotkernel/dot-annotated-services/graph/badge.svg?token=ZBZDEA3LY8)](https://codecov.io/gh/dotkernel/dot-annotated-services) [![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) -[![SymfonyInsight](https://insight.symfony.com/projects/a0d7016e-fc3f-46b8-9b36-571ff060d744/big.svg)](https://insight.symfony.com/projects/a0d7016e-fc3f-46b8-9b36-571ff060d744) - ## Installation Install `dot-annotated-services` by running the following command in your project directory: - composer require dotkernel/dot-annotated-services +```shell +composer require dotkernel/dot-annotated-services +``` After installing, register `dot-annotated-services` in your project by adding the below line to your configuration aggregate (usually: `config/config.php`): - Dot\AnnotatedServices\ConfigProvider::class, +```php +Dot\AnnotatedServices\ConfigProvider::class, +``` ## Usage @@ -34,11 +36,13 @@ After installing, register `dot-annotated-services` in your project by adding th You can register services in the service manager using `AttributedServiceFactory` as seen in the below example: - return [ - 'factories' => [ - ServiceClass::class => AttributedServiceFactory::class, - ], - ]; +```php +return [ + 'factories' => [ + ServiceClass::class => AttributedServiceFactory::class, + ], +]; +``` ### NOTE @@ -48,17 +52,19 @@ The next step is to add the `#[Inject]` attribute to the service constructor wit use Dot\AnnotatedServices\Attribute\Inject; - #[Inject( - App\Srevice\Dependency1::class, - App\Srevice\Dependency2::class, - "config", - )] - public function __construct( - protected App\Srevice\Dependency1 $dep1, - protected App\Srevice\Dependency2 $dep2, - protected array $config - ) { - } +```php +#[Inject( + App\Srevice\Dependency1::class, + App\Srevice\Dependency2::class, + "config", +)] +public function __construct( + protected App\Srevice\Dependency1 $dep1, + protected App\Srevice\Dependency2 $dep2, + protected array $config +) { +} +``` The `#[Inject]` attribute is telling `AttributedServiceFactory` to inject the services specified as parameters. 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 use Dot\AnnotatedServices\Attribute\Inject; - #[Inject( - "config.debug", - )] +```php +#[Inject( + "config.debug", +)] +``` which will inject `$container->get('config')['debug'];`. @@ -81,11 +89,13 @@ which will inject `$container->get('config')['debug'];`. You can register doctrine repositories and inject them using the `AttributedRepositoryFactory` as below: - return [ - 'factories' => [ - ExampleRepository::class => AttributedRepositoryFactory::class, - ], - ]; +```php +return [ + 'factories' => [ + ExampleRepository::class => AttributedRepositoryFactory::class, + ], +]; +``` The next step is to add the `#[Entity]` attribute in the repository class. @@ -93,18 +103,20 @@ The `name` field has to be the fully qualified class name. Every repository should extend `Doctrine\ORM\EntityRepository`. - use Api\App\Entity\Example; - use Doctrine\ORM\EntityRepository; - use Dot\AnnotatedServices\Attribute\Entity; - - #[Entity(name: Example::class)] - class ExampleRepository extends EntityRepository - { - } +```php +use Api\App\Entity\Example; +use Doctrine\ORM\EntityRepository; +use Dot\AnnotatedServices\Attribute\Entity; + +#[Entity(name: Example::class)] +class ExampleRepository extends EntityRepository +{ +} +``` ### NOTE -Starting from version `5.0` of `dot-annotated-services`: +In version `5.0` of `dot-annotated-services`: - services can only be injected using the `#[Inject]` attribute (`@Inject` and `@Service` annotations are no longer supported) - repository-entity relation can only be established using the `#[Entity]` attribute (`@Entity` annotation is no longer supported) diff --git a/composer.json b/composer.json index 81727e7..3146ed8 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,14 @@ "service" ], "require": { - "php": "~8.2.0 || ~8.3.0", + "php": "~8.2.0 || ~8.3.0 || ~8.4.0", "doctrine/orm": "^2.9 || ^3.0", "psr/container": "^1.0 || ^2.0" }, "require-dev": { "phpunit/phpunit": "^10.5", "vimeo/psalm": "^5.20", - "laminas/laminas-coding-standard": "^2.5" + "laminas/laminas-coding-standard": "^3.0" }, "autoload": { "psr-4": { diff --git a/docs/book/index.md b/docs/book/index.md deleted file mode 100644 index ae42a26..0000000 --- a/docs/book/index.md +++ /dev/null @@ -1 +0,0 @@ -../../README.md diff --git a/docs/book/index.md b/docs/book/index.md new file mode 120000 index 0000000..fe84005 --- /dev/null +++ b/docs/book/index.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/docs/book/v5/overview.md b/docs/book/v5/overview.md index 801130d..2e84616 100644 --- a/docs/book/v5/overview.md +++ b/docs/book/v5/overview.md @@ -3,3 +3,7 @@ `dot-annotated-services` is DotKernel's dependency injection service. By providing reusable factories for service and repository injection, it reduces code complexity in projects. + +> `dot-annotated-services` v5 has been abandoned in favor of [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection), which uses PHP attributes instead of annotations. +> +> Going forward, if you want to use annotations in your projects, use [dot-annotated-services v4](../v4/overview.md), else use `dot-dependency-injection`. diff --git a/mkdocs.yml b/mkdocs.yml index 4e3b4dc..d7ef439 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -2,7 +2,7 @@ docs_dir: docs/book site_dir: docs/html extra: project: Packages - current_version: v5 + current_version: v4 versions: - v5 - v4 From 733b8e4eb74b3195f870abad132d24c0e4423f9a Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Wed, 23 Oct 2024 08:10:04 +0300 Subject: [PATCH 2/3] Linting + added .laminas-ci.json Signed-off-by: alexmerlin --- .laminas-ci.json | 6 ++++++ docs/book/v4/factories/repository.md | 2 -- docs/book/v4/factories/service.md | 2 -- docs/book/v5/factories/repository.md | 2 -- docs/book/v5/factories/service.md | 2 -- docs/book/v5/overview.md | 2 +- 6 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 .laminas-ci.json diff --git a/.laminas-ci.json b/.laminas-ci.json new file mode 100644 index 0000000..82cd446 --- /dev/null +++ b/.laminas-ci.json @@ -0,0 +1,6 @@ +{ + "ignore_php_platform_requirements": { + "8.4": true + }, + "backwardCompatibilityCheck": true +} diff --git a/docs/book/v4/factories/repository.md b/docs/book/v4/factories/repository.md index e7bdec0..d467775 100644 --- a/docs/book/v4/factories/repository.md +++ b/docs/book/v4/factories/repository.md @@ -1,6 +1,5 @@ # Inject entity repositories - ## Prepare repository `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 Each entity repository must extend `Doctrine\ORM\EntityRepository`. - ## Register repository Open the ConfigProvider of the module where your repository resides. diff --git a/docs/book/v4/factories/service.md b/docs/book/v4/factories/service.md index 6790658..d3d9e63 100644 --- a/docs/book/v4/factories/service.md +++ b/docs/book/v4/factories/service.md @@ -1,6 +1,5 @@ # Inject class dependencies - ## Prepare class `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 } ``` - ## Register class Open the ConfigProvider of the module where your class resides. diff --git a/docs/book/v5/factories/repository.md b/docs/book/v5/factories/repository.md index 74ede58..ba31aee 100644 --- a/docs/book/v5/factories/repository.md +++ b/docs/book/v5/factories/repository.md @@ -1,6 +1,5 @@ # Inject entity repositories - ## Prepare repository `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 Each entity repository must extend `Doctrine\ORM\EntityRepository`. - ## Register repository Open the ConfigProvider of the module where your repository resides. diff --git a/docs/book/v5/factories/service.md b/docs/book/v5/factories/service.md index a30bbfb..c8ad182 100644 --- a/docs/book/v5/factories/service.md +++ b/docs/book/v5/factories/service.md @@ -1,6 +1,5 @@ # Inject class dependencies - ## Prepare class `dot-annotated-services` determines the dependencies by looking at the `#[Inject]` attribute, added to the constructor of a class. @@ -45,7 +44,6 @@ If your class needs the value of a specific configuration key, you can specify t } ``` - ## Register class Open the ConfigProvider of the module where your class resides. diff --git a/docs/book/v5/overview.md b/docs/book/v5/overview.md index 2e84616..06a23f1 100644 --- a/docs/book/v5/overview.md +++ b/docs/book/v5/overview.md @@ -5,5 +5,5 @@ By providing reusable factories for service and repository injection, it reduces code complexity in projects. > `dot-annotated-services` v5 has been abandoned in favor of [dot-dependency-injection](https://github.com/dotkernel/dot-dependency-injection), which uses PHP attributes instead of annotations. -> +> > Going forward, if you want to use annotations in your projects, use [dot-annotated-services v4](../v4/overview.md), else use `dot-dependency-injection`. From 72a65aad5b42e4c42193ac1f48eeb23c002b11af Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Wed, 23 Oct 2024 09:02:26 +0300 Subject: [PATCH 3/3] Target latest releases in SECURITY.md and updated site_description in mkdocs.yml Signed-off-by: alexmerlin --- SECURITY.md | 4 ++-- mkdocs.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 21831b6..aabfee3 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -5,8 +5,8 @@ | Version | Supported | PHP Version | |---------|--------------------|------------------------------------------------------------------------------------------------------------------------| -| 5.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/5.0.0) | -| 4.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.1.7) | +| 5.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/5.2.0) | +| 4.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.2.0) | | <= 3.x | :x: | | diff --git a/mkdocs.yml b/mkdocs.yml index d7ef439..d7d4297 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -28,7 +28,7 @@ nav: - "Inject class dependencies": v4/factories/service.md - "Inject entity repositories": v4/factories/repository.md site_name: dot-annotated-services -site_description: "DotKernel's dependency injection service" +site_description: "DotKernel's dependency injection service, using PHP attributes" repo_url: "https://github.com/dotkernel/dot-annotated-services" plugins: - search