|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the sauls/object-registry-bundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Saulius Vaičeliūnas <[email protected]> |
|
6
|
|
|
* @link http://saulius.vaiceliunas.lt |
|
7
|
|
|
* @copyright 2018 |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Sauls\Bundle\ObjectRegistryBundle\DependencyInjection\Compiler; |
|
14
|
|
|
|
|
15
|
|
|
use Sauls\Bundle\ObjectRegistryBundle\Collection\BatchOperationCollection; |
|
16
|
|
|
use Sauls\Bundle\ObjectRegistryBundle\Collection\ObjectManagerCollection; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
20
|
|
|
|
|
21
|
|
|
class RegisterTaggedServicesPass implements CompilerPassInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* You can modify the container here before it is dumped to PHP code. |
|
25
|
|
|
*/ |
|
26
|
2 |
|
public function process(ContainerBuilder $container) |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
2 |
|
$this->processTaggedServices( |
|
30
|
2 |
|
$container, ObjectManagerCollection::class, 'sauls.object_registry.manager' |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
2 |
|
$this->processTaggedServices( |
|
34
|
2 |
|
$container, BatchOperationCollection::class,'sauls.object_registry.batch_operation' |
|
35
|
|
|
); |
|
36
|
2 |
|
} |
|
37
|
|
|
|
|
38
|
2 |
|
private function processTaggedServices(ContainerBuilder $container, string $definitionClass, string $tag) |
|
39
|
|
|
{ |
|
40
|
2 |
|
if (false === $container->has($definitionClass)) { |
|
41
|
1 |
|
return; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
$definition = $container->findDefinition($definitionClass); |
|
45
|
1 |
|
$taggedServices = $container->findTaggedServiceIds($tag); |
|
46
|
|
|
|
|
47
|
1 |
|
foreach ($taggedServices as $id => $tags) { |
|
48
|
1 |
|
$definition->addMethodCall('set', ['', new Reference($id)]); |
|
49
|
|
|
} |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|