|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the QueryResourcesLoaderBundle, an RunOpenCode project. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) 2017 RunOpenCode. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace RunOpenCode\Bundle\QueryResourcesLoader\DependencyInjection\CompilerPass; |
|
11
|
|
|
|
|
12
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class TwigEnvironmentCompilerPass |
|
18
|
|
|
* |
|
19
|
|
|
* Builds Twig environment, registers its extensions. |
|
20
|
|
|
* |
|
21
|
|
|
* @package RunOpenCode\Bundle\QueryResourcesLoader\DependencyInjection\CompilerPass |
|
22
|
|
|
*/ |
|
23
|
|
|
class TwigEnvironmentCompilerPass implements CompilerPassInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
2 |
|
public function process(ContainerBuilder $container) |
|
29
|
|
|
{ |
|
30
|
2 |
|
if (false === $container->hasDefinition('run_open_code.query_resources_loader.twig')) { |
|
31
|
1 |
|
return; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
$definition = $container->getDefinition('run_open_code.query_resources_loader.twig'); |
|
35
|
|
|
|
|
36
|
|
|
// Extensions must always be registered before everything else. |
|
37
|
|
|
// For instance, global variable definitions must be registered |
|
38
|
|
|
// afterward. If not, the globals from the extensions will never |
|
39
|
|
|
// be registered. |
|
40
|
1 |
|
$calls = $definition->getMethodCalls(); |
|
41
|
|
|
|
|
42
|
1 |
|
$definition->setMethodCalls(array()); |
|
43
|
|
|
|
|
44
|
1 |
|
foreach ($container->findTaggedServiceIds('run_open_code.query_resources_loader.twig.extension') as $id => $attributes) { |
|
45
|
1 |
|
$definition->addMethodCall('addExtension', array(new Reference($id))); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
$definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls)); |
|
49
|
1 |
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|