From 677e82da76e039e0098553fea81113c862753cbe Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 07:32:09 +0300 Subject: [PATCH 1/5] Issue #4: Bumped PHP to 8.4 Signed-off-by: alexmerlin --- README.md | 89 +++++++++++++++++++++++++++++---------------------- composer.json | 2 +- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index b290a16..ac65c2e 100644 --- a/README.md +++ b/README.md @@ -17,18 +17,20 @@ dependency or two. [![codecov](https://codecov.io/gh/dotkernel/dot-dependency-injection/graph/badge.svg?token=DayAoD2Oj6)](https://codecov.io/gh/dotkernel/dot-dependency-injection) [![docs-build](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/docs-build.yml/badge.svg)](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/docs-build.yml) -[![SymfonyInsight](https://insight.symfony.com/projects/d434b0aa-1f35-4f98-8356-a902f312ba5c/big.svg)](https://insight.symfony.com/projects/d434b0aa-1f35-4f98-8356-a902f312ba5c) - ## Installation Install `dot-dependency-injection` by running the following command in your project directory: - composer require dotkernel/dot-dependency-injection +```shell +composer require dotkernel/dot-dependency-injection +``` After installing, register `dot-dependency-injection` in your project by adding the below line to your configuration aggregate (usually: `config/config.php`): - Dot\DependencyInjection\ConfigProvider::class, +```php +Dot\DependencyInjection\ConfigProvider::class, +``` ## Usage @@ -36,11 +38,13 @@ aggregate (usually: `config/config.php`): 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 @@ -50,17 +54,19 @@ The next step is to add the `#[Inject]` attribute to the service constructor wit use Dot\DependencyInjection\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. @@ -69,9 +75,11 @@ To inject an array value from the service manager, you can use dot notation as b use Dot\DependencyInjection\Attribute\Inject; - #[Inject( - "config.debug", - )] +```php +#[Inject( + "config.debug", +)] +``` which will inject `$container->get('config')['debug'];`. @@ -83,11 +91,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. @@ -95,16 +105,17 @@ 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\DependencyInjection\Attribute\Entity; - - #[Entity(name: Example::class)] - class ExampleRepository extends EntityRepository - { - } +```php +use Api\App\Entity\Example; +use Doctrine\ORM\EntityRepository; +use Dot\DependencyInjection\Attribute\Entity; -### NOTE +#[Entity(name: Example::class)] +class ExampleRepository extends EntityRepository +{ +} +``` + +> Dependencies injected via the`#[Entity]`/`#[Inject]` attributes are not cached -- dependencies injected via the`#[Entity]`/`#[Inject]` attributes are not cached -- injecting dependencies into property setters are not supported +> Injecting dependencies into property setters are not supported diff --git a/composer.json b/composer.json index 9a2a4fc..eab2b97 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "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" }, From 7874f06e5c822c26cae92904202bef08b1d9bac7 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 07:36:37 +0300 Subject: [PATCH 2/5] Fixed docs/book/index.md Signed-off-by: alexmerlin --- docs/book/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 120000 docs/book/index.md 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 From 02f1860b4b1e4e15e06bfa3420b118c4b8fca5ec Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 07:44:50 +0300 Subject: [PATCH 3/5] Added .laminas-ci.json Signed-off-by: alexmerlin --- .laminas-ci.json | 6 ++++++ 1 file changed, 6 insertions(+) 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 +} From fdb570b4d01ac6b900c4f6b0c895def8c3824a20 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 12:23:59 +0300 Subject: [PATCH 4/5] Modified PHP from Packagist badge in README.md Signed-off-by: alexmerlin --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ac65c2e..4118d02 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This package can clean up your code, by getting rid of all the factories you wri dependency or two. ![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-dependency-injection) -![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-dependency-injection/1.0.0) +![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-dependency-injection/1.1.0) [![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/issues) [![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/network) From a04a9ccf55b753040003995e7f898e48456d8929 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 22 Oct 2024 12:53:23 +0300 Subject: [PATCH 5/5] Bump laminas-coding-standard to 3.x Signed-off-by: alexmerlin --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index eab2b97..b7c02fc 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "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": {