1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Knp\FriendlyContexts\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\Alias; |
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
9
|
|
|
|
10
|
|
|
class KernelPass implements CompilerPassInterface |
11
|
|
|
{ |
12
|
|
|
public function process(ContainerBuilder $container) |
13
|
|
|
{ |
14
|
|
|
$this->loadFileFromParameter($container, 'friendly.symfony_kernel.bootstrap'); |
15
|
|
|
$this->loadFileFromParameter($container, 'friendly.symfony_kernel.path'); |
16
|
|
|
|
17
|
|
|
if ($container->has('symfony2_extension.kernel')) { |
18
|
|
|
$alias = $container |
19
|
|
|
->setAlias('friendly.symfony.kernel', 'symfony2_extension.kernel') |
20
|
|
|
; |
21
|
|
|
if ( ! $alias instanceof Alias) { |
|
|
|
|
22
|
|
|
$alias = $container->getAlias('friendly.symfony.kernel'); |
23
|
|
|
} |
24
|
|
|
$alias->setPublic(true); |
25
|
|
|
} elseif (null !== $class = $this->getKernelClass($container)) { |
26
|
|
|
$definition = new Definition($class); |
27
|
|
|
$definition |
28
|
|
|
->addArgument($container->getParameter('friendly.symfony_kernel.env')) |
29
|
|
|
->addArgument($container->getParameter('friendly.symfony_kernel.debug')) |
30
|
|
|
; |
31
|
|
|
$container->setDefinition('friendly.symfony.kernel', $definition); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function loadFileFromParameter(ContainerBuilder $container, $parameter) |
36
|
|
|
{ |
37
|
|
|
$base = $container->getParameter('paths.base'); |
38
|
|
|
$param = $container->getParameter($parameter); |
39
|
|
|
if (file_exists($file = $base.DIRECTORY_SEPARATOR.$param)) { |
40
|
|
|
require_once($file); |
41
|
|
|
} elseif (file_exists($param)) { |
42
|
|
|
require_once($param); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function getKernelClass(ContainerBuilder $container) |
47
|
|
|
{ |
48
|
|
|
$class = $container->getParameter('friendly.symfony_kernel.class'); |
49
|
|
|
|
50
|
|
|
return class_exists($class) ? $class : null; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|