From cc8ed7aeb3ec66a1afe355c3f70b4a2224076294 Mon Sep 17 00:00:00 2001
From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com>
Date: Tue, 9 Apr 2024 04:20:54 +0000
Subject: [PATCH] refactor: remove configuration from API Platform bundle, will
try to reuse standard API Platform extra properties. (#45)
---
CHANGELOG.md | 5 +++
.../config/services.php | 9 -----
.../src/DependencyInjection/Configuration.php | 39 -------------------
...ekalogikaRekapagerApiPlatformExtension.php | 16 --------
.../src/Implementation/RekapagerExtension.php | 9 +----
psalm.xml | 3 --
tests/config/packages/api_platform.yaml | 1 +
.../rekalogika_rekapager_api_platform.yaml | 2 -
tests/src/App/Entity/Post.php | 2 +-
9 files changed, 9 insertions(+), 77 deletions(-)
delete mode 100644 packages/rekapager-api-platform/src/DependencyInjection/Configuration.php
delete mode 100644 tests/config/packages/rekalogika_rekapager_api_platform.yaml
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e374391..7b61bfa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# Changelog
+# 0.8.2
+
+* refactor: remove configuration from API Platform bundle, will try to reuse
+ standard API Platform extra properties.
+
# 0.8.1
* feat: add `PagerFactoryInterface` for API Platform
diff --git a/packages/rekapager-api-platform/config/services.php b/packages/rekapager-api-platform/config/services.php
index 6703210..3e69730 100644
--- a/packages/rekapager-api-platform/config/services.php
+++ b/packages/rekapager-api-platform/config/services.php
@@ -22,14 +22,6 @@
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
return static function (ContainerConfigurator $containerConfigurator): void {
- $parameters = $containerConfigurator->parameters();
-
- $parameters
- ->set(
- 'rekalogika.rekapager.api_platform.enable_orm_support_by_default',
- false
- );
-
$services = $containerConfigurator->services();
$services
@@ -65,7 +57,6 @@
->args([
'$pagerFactory' => service(PagerFactoryInterface::class),
'$pagination' => service('api_platform.pagination'),
- '$enabledByDefault' => '%rekalogika.rekapager.api_platform.enable_orm_support_by_default%',
])
->tag('api_platform.doctrine.orm.query_extension.collection', [
'priority' => -48,
diff --git a/packages/rekapager-api-platform/src/DependencyInjection/Configuration.php b/packages/rekapager-api-platform/src/DependencyInjection/Configuration.php
deleted file mode 100644
index 570a27b..0000000
--- a/packages/rekapager-api-platform/src/DependencyInjection/Configuration.php
+++ /dev/null
@@ -1,39 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE file
- * that was distributed with this source code.
- */
-
-namespace Rekalogika\Rekapager\ApiPlatform\DependencyInjection;
-
-use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
-use Symfony\Component\Config\Definition\Builder\TreeBuilder;
-use Symfony\Component\Config\Definition\ConfigurationInterface;
-
-class Configuration implements ConfigurationInterface
-{
- public function getConfigTreeBuilder(): TreeBuilder
- {
- $treeBuilder = new TreeBuilder('rekalogika_rekapager_api_platform');
-
- /** @var ArrayNodeDefinition $rootNode */
- $rootNode = $treeBuilder->getRootNode();
-
- $rootNode
- ->children()
- ->booleanNode('enable_orm_support_by_default')
- ->defaultValue(false)
- ->end()
- ->end()
- ;
-
- return $treeBuilder;
- }
-}
diff --git a/packages/rekapager-api-platform/src/DependencyInjection/RekalogikaRekapagerApiPlatformExtension.php b/packages/rekapager-api-platform/src/DependencyInjection/RekalogikaRekapagerApiPlatformExtension.php
index d05450a..15101c9 100644
--- a/packages/rekapager-api-platform/src/DependencyInjection/RekalogikaRekapagerApiPlatformExtension.php
+++ b/packages/rekapager-api-platform/src/DependencyInjection/RekalogikaRekapagerApiPlatformExtension.php
@@ -23,11 +23,6 @@ class RekalogikaRekapagerApiPlatformExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
- // load configuration
-
- $configuration = new Configuration();
- $config = $this->processConfiguration($configuration, $configs);
-
// load our services
$loader = new PhpFileLoader(
@@ -47,16 +42,5 @@ public function load(array $configs, ContainerBuilder $container)
// load services from symfony-bridge package
RekapagerSymfonyBridge::loadServices($container);
-
- // process config
- $enableOrmSupportByDefault = $config['enable_orm_support_by_default'] ?? false;
- if (!\is_bool($enableOrmSupportByDefault)) {
- throw new \InvalidArgumentException('The "enable_orm_support_by_default" option must be a boolean.');
- }
-
- $container->setParameter(
- 'rekalogika.rekapager.api_platform.enable_orm_support_by_default',
- $enableOrmSupportByDefault
- );
}
}
diff --git a/packages/rekapager-api-platform/src/Implementation/RekapagerExtension.php b/packages/rekapager-api-platform/src/Implementation/RekapagerExtension.php
index 061d74a..1087d32 100644
--- a/packages/rekapager-api-platform/src/Implementation/RekapagerExtension.php
+++ b/packages/rekapager-api-platform/src/Implementation/RekapagerExtension.php
@@ -41,7 +41,6 @@ final class RekapagerExtension implements QueryResultCollectionExtensionInterfac
public function __construct(
private readonly PagerFactory $pagerFactory,
private readonly Pagination $pagination,
- private readonly bool $enabledByDefault,
) {
}
@@ -67,12 +66,8 @@ public function supportsResult(
): bool {
/** @psalm-suppress InternalMethod */
$extraProperties = $operation?->getExtraProperties() ?? [];
- /** @var bool|null */
- $isEnabled = $extraProperties['rekapager_orm_enabled'] ?? null;
-
- if (!\is_bool($isEnabled) && $isEnabled === null) {
- $isEnabled = $this->enabledByDefault;
- }
+ /** @var bool */
+ $isEnabled = $extraProperties['rekapager_orm_enabled'] ?? false;
if ($isEnabled === false) {
return false;
diff --git a/psalm.xml b/psalm.xml
index 14b4463..3321776 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -54,19 +54,16 @@
-
-
-
diff --git a/tests/config/packages/api_platform.yaml b/tests/config/packages/api_platform.yaml
index fcd693a..da33ad4 100644
--- a/tests/config/packages/api_platform.yaml
+++ b/tests/config/packages/api_platform.yaml
@@ -18,6 +18,7 @@ api_platform:
extra_properties:
standard_put: true
rfc_7807_compliant_errors: true
+ rekapager_orm_enabled: true
normalization_context:
skip_null_values: false
event_listeners_backward_compatibility_layer: false
diff --git a/tests/config/packages/rekalogika_rekapager_api_platform.yaml b/tests/config/packages/rekalogika_rekapager_api_platform.yaml
deleted file mode 100644
index ce5622b..0000000
--- a/tests/config/packages/rekalogika_rekapager_api_platform.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
-rekalogika_rekapager_api_platform:
- enable_orm_support_by_default: false
\ No newline at end of file
diff --git a/tests/src/App/Entity/Post.php b/tests/src/App/Entity/Post.php
index eeb64a9..0326d9e 100644
--- a/tests/src/App/Entity/Post.php
+++ b/tests/src/App/Entity/Post.php
@@ -26,7 +26,7 @@
#[ORM\Index(fields: ['date'])]
#[ORM\Index(fields: ['title'])]
#[ORM\Index(fields: ['setName'])]
-#[ApiResource(extraProperties: ['rekapager_orm_enabled' => true])]
+#[ApiResource]
#[ApiResource(
operations: [
new GetCollection(