Skip to content

Commit

Permalink
refactor: remove configuration from API Platform bundle, will try to …
Browse files Browse the repository at this point in the history
…reuse standard API Platform extra properties. (#45)
  • Loading branch information
priyadi authored Apr 9, 2024
1 parent 3d9288e commit cc8ed7a
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 77 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 0 additions & 9 deletions packages/rekapager-api-platform/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ final class RekapagerExtension implements QueryResultCollectionExtensionInterfac
public function __construct(
private readonly PagerFactory $pagerFactory,
private readonly Pagination $pagination,
private readonly bool $enabledByDefault,
) {
}

Expand All @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,16 @@
<UndefinedInterfaceMethod>
<errorLevel type="suppress">
<file name="packages/rekapager-bundle/src/DependencyInjection/Configuration.php" />
<file name="packages/rekapager-api-platform/src/DependencyInjection/Configuration.php" />
</errorLevel>
</UndefinedInterfaceMethod>
<MixedMethodCall>
<errorLevel type="suppress">
<file name="packages/rekapager-bundle/src/DependencyInjection/Configuration.php" />
<file name="packages/rekapager-api-platform/src/DependencyInjection/Configuration.php" />
</errorLevel>
</MixedMethodCall>
<PossiblyNullReference>
<errorLevel type="suppress">
<file name="packages/rekapager-bundle/src/DependencyInjection/Configuration.php" />
<file name="packages/rekapager-api-platform/src/DependencyInjection/Configuration.php" />
</errorLevel>
</PossiblyNullReference>
<InternalClass>
Expand Down
1 change: 1 addition & 0 deletions tests/config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/config/packages/rekalogika_rekapager_api_platform.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion tests/src/App/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit cc8ed7a

Please sign in to comment.