From 9a0a2de4a3fd95f8b23aa2b0a3842b47135746c3 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Mon, 1 Apr 2024 11:33:45 +0300 Subject: [PATCH 1/5] Use Github CI actions from Laminas Signed-off-by: alexmerlin --- .github/workflows/continuous-integration.yml | 11 +++++ .github/workflows/cs-tests.yml | 46 ------------------- .github/workflows/static-analysis.yml | 46 ------------------- .github/workflows/unit-test.yml | 47 -------------------- 4 files changed, 11 insertions(+), 139 deletions(-) create mode 100644 .github/workflows/continuous-integration.yml delete mode 100644 .github/workflows/cs-tests.yml delete mode 100644 .github/workflows/static-analysis.yml delete mode 100644 .github/workflows/unit-test.yml diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..26c5802 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,11 @@ +name: "Continuous Integration" + +on: + pull_request: + push: + branches: + tags: + +jobs: + ci: + uses: laminas/workflow-continuous-integration/.github/workflows/continuous-integration.yml@1.x diff --git a/.github/workflows/cs-tests.yml b/.github/workflows/cs-tests.yml deleted file mode 100644 index f9df1a0..0000000 --- a/.github/workflows/cs-tests.yml +++ /dev/null @@ -1,46 +0,0 @@ -on: - - push - -name: Run phpcs checks - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.2" - - "8.3" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - name: Install dependencies with composer - run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run phpcs checks - run: vendor/bin/phpcs diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml deleted file mode 100644 index 1c328d6..0000000 --- a/.github/workflows/static-analysis.yml +++ /dev/null @@ -1,46 +0,0 @@ -on: - - push - -name: Run static analysis - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.2" - - "8.3" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - name: Install dependencies with composer - run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run static analysis - run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4 diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml deleted file mode 100644 index e1ce1ac..0000000 --- a/.github/workflows/unit-test.yml +++ /dev/null @@ -1,47 +0,0 @@ -on: - - push - -name: Run PHPUnit tests - -jobs: - mutation: - name: PHP ${{ matrix.php }}-${{ matrix.os }} - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: - - ubuntu-latest - - php: - - "8.2" - - "8.3" - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "${{ matrix.php }}" - tools: composer:v2, cs2pr - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - - name: Install dependencies with composer - run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run PHPUnit tests - run: vendor/bin/phpunit --colors=always From b2ffb3d892251191b17de515ea4e0584ef2b7a68 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Mon, 1 Apr 2024 11:47:42 +0300 Subject: [PATCH 2/5] Code linting Signed-off-by: alexmerlin --- docs/book/v4/cache.md | 3 ++- docs/book/v4/configuration.md | 1 - docs/book/v4/factories.md | 7 +++---- docs/book/v4/usage.md | 1 + docs/book/v5/configuration.md | 1 - docs/book/v5/factories.md | 4 ++-- docs/book/v5/usage.md | 1 + 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/book/v4/cache.md b/docs/book/v4/cache.md index 9bbf51a..d8ca4b4 100644 --- a/docs/book/v4/cache.md +++ b/docs/book/v4/cache.md @@ -2,7 +2,6 @@ `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). - ## Configuration 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 ], ]; ``` + 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): + ```php Date: Mon, 1 Apr 2024 12:08:32 +0300 Subject: [PATCH 3/5] Code linting Signed-off-by: alexmerlin --- README.md | 14 ++++++++------ docs/book/v5/factories.md | 1 - 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 75f8acf..5ffb28b 100644 --- a/README.md +++ b/README.md @@ -17,19 +17,16 @@ This package can clean up your code, by getting rid of all the factories you wri [![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 - 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, - ## Usage ### Using the AttributedServiceFactory @@ -44,8 +41,8 @@ return [ ]; ``` - ### NOTE + > You can use only the fully qualified class name as the service key The next step is to add the `#[Inject]` attribute to the service constructor with the service FQCNs to inject: @@ -78,15 +75,17 @@ use Dot\AnnotatedServices\Attribute\Inject; "config.debug", )] ``` -which will inject `$container->get('config')['debug'];`. +which will inject `$container->get('config')['debug'];`. ### NOTE -> Even if using dot notation, `AttributedServiceFactory` will check first if a service name exists with that name. +> Even if using dot notation, `AttributedServiceFactory` will check first if a service name exists with that name. ### Using the AttributedRepositoryFactory + You can register doctrine repositories and inject them using the `AttributedRepositoryFactory` as below: + ```php return [ 'factories' => [ @@ -100,6 +99,7 @@ The next step is to add the `#[Entity]` attribute in the repository class. The `name` field has to be the fully qualified class name. Every repository should extend `Doctrine\ORM\EntityRepository`. + ```php use Api\App\Entity\Example; use Doctrine\ORM\EntityRepository; @@ -112,7 +112,9 @@ class ExampleRepository extends EntityRepository ``` ### NOTE + Starting from 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) - dependencies injected via the`#[Entity]`/`#[Inject]` attributes are not cached diff --git a/docs/book/v5/factories.md b/docs/book/v5/factories.md index 65a5b26..5201d32 100644 --- a/docs/book/v5/factories.md +++ b/docs/book/v5/factories.md @@ -14,7 +14,6 @@ Injects entity repositories into a class. - `Psr\Container\NotFoundExceptionInterface` if `Doctrine\ORM\EntityManagerInterface` does not exist in the service container - `Psr\Container\ContainerExceptionInterface` if service manager is unable to provide an instance of `Doctrine\ORM\EntityManagerInterface` - ## AttributedServiceFactory Injects class dependencies into classes. From 68ec12b873dcbb6ac8127c5dc60e43842fa01895 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Mon, 1 Apr 2024 12:46:18 +0300 Subject: [PATCH 4/5] Code linting Signed-off-by: alexmerlin --- README.md | 78 ++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 5ffb28b..9bf2db2 100644 --- a/README.md +++ b/README.md @@ -33,13 +33,11 @@ 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: -```php -return [ - 'factories' => [ - ServiceClass::class => AttributedServiceFactory::class, - ], -]; -``` + return [ + 'factories' => [ + ServiceClass::class => AttributedServiceFactory::class, + ], + ]; ### NOTE @@ -47,52 +45,46 @@ return [ The next step is to add the `#[Inject]` attribute to the service constructor with the service FQCNs to inject: -```php 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 -) { -} -``` + #[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. To inject an array value from the service manager, you can use dot notation as below -```php use Dot\AnnotatedServices\Attribute\Inject; -#[Inject( - "config.debug", -)] -``` + #[Inject( + "config.debug", + )] which will inject `$container->get('config')['debug'];`. -### NOTE +### NOTE > Even if using dot notation, `AttributedServiceFactory` will check first if a service name exists with that name. -### Using the AttributedRepositoryFactory +### Using the AttributedRepositoryFactory You can register doctrine repositories and inject them using the `AttributedRepositoryFactory` as below: -```php -return [ - 'factories' => [ - ExampleRepository::class => AttributedRepositoryFactory::class, - ], -]; -``` + return [ + 'factories' => [ + ExampleRepository::class => AttributedRepositoryFactory::class, + ], + ]; The next step is to add the `#[Entity]` attribute in the repository class. @@ -100,16 +92,14 @@ The `name` field has to be the fully qualified class name. Every repository should extend `Doctrine\ORM\EntityRepository`. -```php -use Api\App\Entity\Example; -use Doctrine\ORM\EntityRepository; -use Dot\AnnotatedServices\Attribute\Entity; - -#[Entity(name: Example::class)] -class ExampleRepository extends EntityRepository -{ -} -``` + use Api\App\Entity\Example; + use Doctrine\ORM\EntityRepository; + use Dot\AnnotatedServices\Attribute\Entity; + + #[Entity(name: Example::class)] + class ExampleRepository extends EntityRepository + { + } ### NOTE From 2ce6ed1988e7d76b54b7e0f70962b21175e2c98a Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Tue, 2 Apr 2024 10:44:40 +0300 Subject: [PATCH 5/5] Updated composer.json Signed-off-by: alexmerlin --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fd85127..81727e7 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ ], "require": { "php": "~8.2.0 || ~8.3.0", - "doctrine/orm": "^2.0 || ^3.0", + "doctrine/orm": "^2.9 || ^3.0", "psr/container": "^1.0 || ^2.0" }, "require-dev": {