From 8cd0ebc69e56756650d5bb5cb93e5e5f7f83cb18 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Tue, 29 Oct 2024 21:28:50 +0700 Subject: [PATCH] feat: API Platform 4 compatibility --- CHANGELOG.md | 4 ++++ composer.json | 4 +++- packages/rekapager-api-platform/composer.json | 2 +- tests/config/packages/api_platform.yaml | 2 -- tests/src/App/Kernel.php | 17 +++++++++++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 275ff4f..eb66c72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# 0.19.0 + +* feat: API Platform 4 compatibility + # 0.18.1 * chore: add missing types diff --git a/composer.json b/composer.json index d2ec36a..f594760 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "type": "library", "require": { "php": "^8.2", - "api-platform/core": "^3.2", + "api-platform/core": "^3.2 || ^4.0", "doctrine/collections": "^2.2", "doctrine/dbal": "^3.8 || ^4.0", "doctrine/orm": "^2.19 || ^3.0 <3.3", @@ -31,7 +31,9 @@ "twig/twig": "^3.8" }, "require-dev": { + "composer-runtime-api": "^2.2", "bnf/phpstan-psr-container": "^1.0", + "composer/semver": "^3.4", "doctrine/doctrine-bundle": "^2.11.3", "doctrine/doctrine-fixtures-bundle": "^3.5", "doctrine/persistence": "^3.1", diff --git a/packages/rekapager-api-platform/composer.json b/packages/rekapager-api-platform/composer.json index 835b4d4..a8a9464 100644 --- a/packages/rekapager-api-platform/composer.json +++ b/packages/rekapager-api-platform/composer.json @@ -29,7 +29,7 @@ }, "require": { "php": "^8.2", - "api-platform/core": "^3.2", + "api-platform/core": "^3.2 || ^4.0", "rekalogika/rekapager-contracts": "^0.18.1", "rekalogika/rekapager-core": "^0.18.1", "rekalogika/rekapager-doctrine-orm-adapter": "^0.18.1", diff --git a/tests/config/packages/api_platform.yaml b/tests/config/packages/api_platform.yaml index 7c2a927..dabf12b 100644 --- a/tests/config/packages/api_platform.yaml +++ b/tests/config/packages/api_platform.yaml @@ -22,8 +22,6 @@ api_platform: rekapager_orm_enabled: true normalization_context: skip_null_values: false - event_listeners_backward_compatibility_layer: false - keep_legacy_inflector: false mapping: paths: - '%kernel.project_dir%/src/App/Entity' diff --git a/tests/src/App/Kernel.php b/tests/src/App/Kernel.php index b7b6cd2..96da415 100644 --- a/tests/src/App/Kernel.php +++ b/tests/src/App/Kernel.php @@ -14,6 +14,8 @@ namespace Rekalogika\Rekapager\Tests\App; use ApiPlatform\Symfony\Bundle\ApiPlatformBundle; +use Composer\InstalledVersions; +use Composer\Semver\VersionParser; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle; use Rekalogika\Rekapager\ApiPlatform\RekalogikaRekapagerApiPlatformBundle; @@ -86,5 +88,20 @@ public function getConfigDir(): string public function registerContainerConfiguration(LoaderInterface $loader): void { $this->baseRegisterContainerConfiguration($loader); + + $loader->load(function (ContainerBuilder $container): void { + if (InstalledVersions::satisfies(new VersionParser(), 'api-platform/core', '3.*')) { + $container->loadFromExtension('api_platform', [ + 'event_listeners_backward_compatibility_layer' => false, + 'keep_legacy_inflector' => false, + ]); + } elseif (InstalledVersions::satisfies(new VersionParser(), 'api-platform/core', '4.*')) { + $container->loadFromExtension('api_platform', [ + 'serializer' => [ + 'hydra_prefix' => true, + ], + ]); + } + }); } }