-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHydraPaginationEnrichmentCompilerPass.php
More file actions
49 lines (40 loc) · 2.09 KB
/
Copy pathHydraPaginationEnrichmentCompilerPass.php
File metadata and controls
49 lines (40 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Netgen\ApiPlatformExtras\DependencyInjection\CompilerPass;
use Netgen\ApiPlatformExtras\ApiPlatform\Hydra\JsonSchema\SchemaFactoryDecorator;
use Netgen\ApiPlatformExtras\ApiPlatform\Hydra\Serializer\PartialCollectionViewNormalizerDecorator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use function sprintf;
final class HydraPaginationEnrichmentCompilerPass implements CompilerPassInterface
{
private const string BASE_FEATURE_PATH = 'netgen_api_platform_extras.features.hydra_pagination_enrichment';
public function process(ContainerBuilder $container): void
{
$featureEnabledParameter = sprintf('%s.enabled', self::BASE_FEATURE_PATH);
if (
!$container->hasParameter($featureEnabledParameter)
|| $container->getParameter($featureEnabledParameter) === false
|| !$container->hasDefinition('api_platform.hydra.json_schema.schema_factory')
) {
return;
}
$container
->setDefinition('netgen.api_platform_extras.hydra.json_schema.schema_factory', new Definition(SchemaFactoryDecorator::class))
->setArguments([
new Reference('netgen.api_platform_extras.hydra.json_schema.schema_factory.inner'),
])
->setDecoratedService('api_platform.hydra.json_schema.schema_factory');
if (!$container->hasDefinition('api_platform.hydra.normalizer.partial_collection_view')) {
return;
}
$container
->setDefinition('netgen.api_platform_extras.hydra.normalizer.partial_collection_view', new Definition(PartialCollectionViewNormalizerDecorator::class))
->setArguments([
new Reference('netgen.api_platform_extras.hydra.normalizer.partial_collection_view.inner'),
])
->setDecoratedService('api_platform.hydra.normalizer.partial_collection_view');
}
}