-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
LocatorRegistrationPass.php
61 lines (54 loc) · 2.13 KB
/
LocatorRegistrationPass.php
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
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
* Symfony DataTables Bundle
* (c) Omines Internetbureau B.V. - https://omines.nl/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Omines\DataTablesBundle\DependencyInjection\Compiler;
use Omines\DataTablesBundle\Adapter\AdapterInterface;
use Omines\DataTablesBundle\Column\AbstractColumn;
use Omines\DataTablesBundle\DataTableTypeInterface;
use Omines\DataTablesBundle\DependencyInjection\Instantiator;
use Omines\DataTablesBundle\Exporter\DataTableExporterInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ServiceLocator;
/**
* LocatorRegistrationPass.
*
* @author Niels Keurentjes <niels.keurentjes@omines.com>
*/
class LocatorRegistrationPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$container->getDefinition(Instantiator::class)
->setArguments([[
AdapterInterface::class => $this->registerLocator($container, 'adapter'),
AbstractColumn::class => $this->registerLocator($container, 'column'),
DataTableTypeInterface::class => $this->registerLocator($container, 'type'),
DataTableExporterInterface::class => $this->registerLocator($container, 'exporter'),
]]);
}
private function registerLocator(ContainerBuilder $container, string $baseTag): Definition
{
$types = [];
foreach ($container->findTaggedServiceIds("datatables.{$baseTag}") as $serviceId => $tag) {
$types[$serviceId] = new Reference($serviceId);
}
return $container
->register("datatables.{$baseTag}_locator", ServiceLocator::class)
->addTag('container.service_locator')
->setPublic(false)
->setArguments([$types])
;
}
}