Passed
Pull Request — master (#6)
by
unknown
02:45
created

PaginatorCompilerPass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 27
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPaginationConfigs() 0 6 1
A process() 0 12 2
1
<?php
2
3
namespace ElevenLabs\ApiServiceBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
10
/**
11
 * Class PaginatorCompilerPass.
12
 */
13
class PaginatorCompilerPass implements CompilerPassInterface
14
{
15
    /**
16
     * @param ContainerBuilder $container
17
     *
18
     * @throws \Exception
19
     */
20
    public function process(ContainerBuilder $container)
21
    {
22
        $providers = [];
23
        $configsProviders = $this->getPaginationConfigs($container);
24
        foreach ($container->findTaggedServiceIds('api_service.pagination_provider') as $id => $configs) {
25
            $provider = $container->getDefinition($id);
26
            $provider->replaceArgument(0, $configsProviders[$configs[0]['provider']] ?? []);
27
            $providers[] = $provider;
28
        }
29
30
        $pagination = $container->getDefinition('api_service.pagination_provider.chain');
31
        $pagination->replaceArgument(0, $providers);
32
    }
33
34
    private function getPaginationConfigs(ContainerBuilder $container)
35
    {
36
        $configs = $container->getExtensionConfig('api_service');
37
        $config = reset($configs);
38
39
        return $config['pagination'] ?? [];
40
    }
41
}
42