|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Pfilsx\DataGrid\DependencyInjection\Compiler; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
11
|
|
|
|
|
12
|
|
|
class GridPass implements CompilerPassInterface |
|
13
|
|
|
{ |
|
14
|
|
|
private $gridExtensionService; |
|
15
|
|
|
private $gridTypeTag; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct(string $gridExtensionService = 'data_grid.extension', string $gridTypeTag = 'data_grid.type') |
|
18
|
|
|
{ |
|
19
|
|
|
$this->gridExtensionService = $gridExtensionService; |
|
20
|
|
|
$this->gridTypeTag = $gridTypeTag; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function process(ContainerBuilder $container) |
|
24
|
|
|
{ |
|
25
|
|
|
if (!$container->hasDefinition($this->gridExtensionService)) { |
|
26
|
|
|
return; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$definition = $container->getDefinition($this->gridExtensionService); |
|
30
|
|
|
$definition->replaceArgument(0, $this->processGridTypes($container)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
private function processGridTypes(ContainerBuilder $container) |
|
34
|
|
|
{ |
|
35
|
|
|
// Get service locator argument |
|
36
|
|
|
$servicesMap = []; |
|
37
|
|
|
$namespaces = []; |
|
38
|
|
|
|
|
39
|
|
|
// Builds an array with fully-qualified type class names as keys and service IDs as values |
|
40
|
|
|
foreach ($container->findTaggedServiceIds($this->gridTypeTag, true) as $serviceId => $tag) { |
|
41
|
|
|
// Add form type service to the service locator |
|
42
|
|
|
$serviceDefinition = $container->getDefinition($serviceId); |
|
43
|
|
|
$servicesMap[$formType = $serviceDefinition->getClass()] = new Reference($serviceId); |
|
44
|
|
|
$namespaces[substr($formType, 0, strrpos($formType, '\\'))] = true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return ServiceLocatorTagPass::register($container, $servicesMap); |
|
48
|
|
|
} |
|
49
|
|
|
} |