1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Finite\Bundle\FiniteBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* This is the class that loads and manages your bundle configuration. |
13
|
|
|
* |
14
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
15
|
|
|
*/ |
16
|
|
|
class FiniteFiniteExtension extends Extension |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
5 |
|
public function load(array $configs, ContainerBuilder $container) |
22
|
|
|
{ |
23
|
5 |
|
$configuration = new Configuration(); |
24
|
5 |
|
$config = $this->processConfiguration($configuration, $configs); |
25
|
|
|
|
26
|
5 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
27
|
5 |
|
$loader->load('services.xml'); |
28
|
5 |
|
$factoryDefinition = $container->getDefinition('finite.factory'); |
29
|
|
|
|
30
|
5 |
|
$smDefinition = $container->getDefinition('finite.state_machine'); |
31
|
5 |
|
if (method_exists($smDefinition, 'setShared')) { |
32
|
5 |
|
$smDefinition->setShared(false); |
33
|
3 |
|
} else { |
34
|
|
|
$smDefinition->setScope('prototype'); |
35
|
|
|
} |
36
|
|
|
|
37
|
5 |
|
foreach ($config as $key => $stateMachineConfig) { |
38
|
5 |
|
$stateMachineConfig = $this->removeDisabledCallbacks($stateMachineConfig); |
39
|
|
|
|
40
|
5 |
|
$definition = clone $container->getDefinition('finite.array_loader'); |
41
|
5 |
|
$definition->replaceArgument(0, $stateMachineConfig); |
42
|
5 |
|
$definition->addTag('finite.loader'); |
43
|
|
|
|
44
|
|
|
// setLazy method wasn't available before 2.3, FiniteBundle requirement is ~2.1 |
45
|
5 |
|
if (method_exists($definition, 'setLazy')) { |
46
|
5 |
|
$definition->setLazy(true); |
47
|
3 |
|
} |
48
|
|
|
|
49
|
5 |
|
$serviceId = 'finite.loader.'.$key; |
50
|
5 |
|
$container->setDefinition($serviceId, $definition); |
51
|
|
|
|
52
|
5 |
|
$factoryDefinition->addMethodCall('addLoader', array(new Reference($serviceId))); |
53
|
3 |
|
} |
54
|
|
|
|
55
|
5 |
|
$container->removeDefinition('finite.array_loader'); |
56
|
5 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Remove callback entries where index 'disabled' is set to true. |
60
|
|
|
* |
61
|
|
|
* @param array $config |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
5 |
|
protected function removeDisabledCallbacks(array $config) |
66
|
|
|
{ |
67
|
5 |
|
if (!isset($config['callbacks'])) { |
68
|
|
|
return $config; |
69
|
|
|
} |
70
|
|
|
|
71
|
5 |
|
foreach (array('before', 'after') as $position) { |
72
|
5 |
|
foreach ($config['callbacks'][$position] as $i => $callback) { |
73
|
5 |
|
if ($callback['disabled']) { |
74
|
5 |
|
unset($config['callbacks'][$position][$i]); |
75
|
3 |
|
} |
76
|
5 |
|
unset($config['callbacks'][$position][$i]['disabled']); |
77
|
3 |
|
} |
78
|
3 |
|
} |
79
|
|
|
|
80
|
5 |
|
return $config; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|