|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Povs\ListerBundle\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @author Povilas Margaiatis <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class ListCompilerPass implements CompilerPassInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @inheritdoc |
|
19
|
|
|
*/ |
|
20
|
1 |
|
public function process(ContainerBuilder $container): void |
|
21
|
|
|
{ |
|
22
|
1 |
|
$this->buildLocator($container, 'povs_lister.list', '.povs_lister.locator.list'); |
|
23
|
1 |
|
$this->buildLocator($container, 'povs_lister.query_type', '.povs_lister.locator.query_type'); |
|
24
|
1 |
|
$this->buildLocator($container, 'povs_lister.field_type', '.povs_lister.locator.field_type'); |
|
25
|
1 |
|
$this->buildLocator($container, 'povs_lister.list_type', '.povs_lister.locator.list_type'); |
|
26
|
1 |
|
$this->buildLocator($container, 'povs_lister.filter_type', '.povs_lister.locator.filter_type'); |
|
27
|
1 |
|
$this->buildLocator($container, 'povs_lister.selector_type', '.povs_lister.locator.selector_type'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param ContainerBuilder $container |
|
32
|
|
|
* @param string $tag tag name of the services |
|
33
|
|
|
* @param string $locator fully qualified class name |
|
34
|
|
|
* |
|
35
|
|
|
* @throws InvalidArgumentException |
|
36
|
|
|
* @throws ServiceNotFoundException |
|
37
|
|
|
*/ |
|
38
|
1 |
|
private function buildLocator(ContainerBuilder $container, string $tag, string $locator): void |
|
39
|
|
|
{ |
|
40
|
1 |
|
$ref = []; |
|
41
|
|
|
|
|
42
|
1 |
|
foreach ($container->findTaggedServiceIds($tag, true) as $id => $tags) { |
|
43
|
1 |
|
$ref[$id] = new ServiceClosureArgument(new Reference($id)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
$locatorDef = $container->getDefinition($locator); |
|
47
|
1 |
|
$locatorDef->setArgument(0, $ref); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|