|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PommProject\PommBundle\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class BuilderPass. |
|
12
|
|
|
* |
|
13
|
|
|
* @author Manuel Raynaud <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class BuilderPass implements CompilerPassInterface |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* You can modify the container here before it is dumped to PHP code. |
|
20
|
|
|
* |
|
21
|
|
|
* @param ContainerBuilder $container |
|
22
|
|
|
*/ |
|
23
|
|
|
public function process(ContainerBuilder $container) |
|
24
|
|
|
{ |
|
25
|
|
|
$config = $container->getParameter('pomm.configuration'); |
|
26
|
|
|
|
|
27
|
|
|
$definition = $container->getDefinition('pomm'); |
|
28
|
|
|
|
|
29
|
|
|
foreach ($config as $name => $pommConfig) { |
|
30
|
|
|
if (isset($pommConfig['session_builder'])) { |
|
31
|
|
|
$service = $container->getDefinition($pommConfig['session_builder']); |
|
32
|
|
|
$service->setArguments([$pommConfig]); |
|
33
|
|
|
|
|
34
|
|
|
$definition->addMethodCall('addBuilder', [$name, new Reference($pommConfig['session_builder'])]); |
|
35
|
|
|
} else { |
|
36
|
|
|
$service = uniqid($pommConfig['class:session_builder'], true); |
|
37
|
|
|
$cbDefinition = $container->register($service, ltrim($pommConfig['class:session_builder'], '\\')); |
|
38
|
|
|
$cbDefinition->setShared(false); |
|
39
|
|
|
$cbDefinition->setArguments([$pommConfig]); |
|
40
|
|
|
|
|
41
|
|
|
$definition->addMethodCall('addBuilder', [$name, new Reference($service)]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (isset($pommConfig['pomm:default']) && $pommConfig['pomm:default']) { |
|
45
|
|
|
$definition->addMethodCall('setDefaultBuilder', [$name]); |
|
46
|
|
|
|
|
47
|
|
|
$container->setAlias('pomm.default_session', sprintf('pomm.session.%s', $name)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
//register all session's into the container |
|
51
|
|
|
$session = new Definition('PommProject\Foundation\Session\Session'); |
|
52
|
|
|
$session->setFactory([new Reference('pomm'), 'getSession']) |
|
53
|
|
|
->addArgument($name) |
|
54
|
|
|
; |
|
55
|
|
|
$container->addDefinitions([sprintf('pomm.session.%s', $name) => $session]); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|