|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Hautelook\AliceBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Baldur Rensch <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Hautelook\AliceBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
|
15
|
|
|
use Symfony\Component\Config\FileLocator; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
21
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The extension of this bundle. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Baldur Rensch <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
class HautelookAliceExtension extends Extension implements PrependExtensionInterface |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
private $extensions = []; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
* |
|
38
|
|
|
* Gets Doctrine extensions. |
|
39
|
|
|
*/ |
|
40
|
27 |
|
public function prepend(ContainerBuilder $container) |
|
41
|
|
|
{ |
|
42
|
27 |
|
$this->extensions[Configuration::ORM_DRIVER] = $container->getExtensionConfig('doctrine'); |
|
43
|
27 |
|
$this->extensions[Configuration::MONGODB_DRIVER] = $container->getExtensionConfig('doctrine_mongodb'); |
|
44
|
27 |
|
$this->extensions[Configuration::PHPCR_DRIVER] = $container->getExtensionConfig('doctrine_phpcr'); |
|
45
|
27 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
* |
|
50
|
|
|
* @throws InvalidConfigurationException |
|
51
|
|
|
*/ |
|
52
|
27 |
|
public function load(array $configs, ContainerBuilder $container) |
|
53
|
|
|
{ |
|
54
|
27 |
|
$configuration = new Configuration(); |
|
55
|
27 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
56
|
|
|
|
|
57
|
24 |
|
foreach ($config as $key => $value) { |
|
58
|
24 |
|
$container->setParameter($this->getAlias().'.'.$key, $value); |
|
59
|
24 |
|
} |
|
60
|
|
|
|
|
61
|
24 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
62
|
24 |
|
$loader->load('services.xml'); |
|
63
|
|
|
|
|
64
|
|
|
// Deprecated factory methods handling. |
|
65
|
|
|
// To be removed and set directly on config file when bumping Symfony requirements to >=2.6 |
|
66
|
24 |
|
$aliceFakerDefinition = $container->getDefinition('hautelook_alice.faker'); |
|
67
|
24 |
|
if (method_exists($aliceFakerDefinition, 'setFactory')) { |
|
68
|
16 |
|
$aliceFakerDefinition->setFactory(['Faker\Factory', 'create']); |
|
69
|
16 |
|
} else { |
|
70
|
8 |
|
$aliceFakerDefinition->setFactoryClass('Faker\Factory'); |
|
|
|
|
|
|
71
|
8 |
|
$aliceFakerDefinition->setFactoryMethod('create'); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
24 |
|
foreach ($config['db_drivers'] as $driver => $isEnabled) { |
|
75
|
24 |
|
if (true === $isEnabled |
|
76
|
24 |
|
|| (null === $isEnabled && true === $this->isExtensionEnabled($driver)) |
|
77
|
24 |
|
) { |
|
78
|
15 |
|
$loader->load(sprintf('%s.xml', $driver)); |
|
79
|
|
|
|
|
80
|
15 |
|
if ('orm' === $driver) { |
|
81
|
15 |
|
$this->setCommandFactory($container->getDefinition('hautelook_alice.doctrine.command.deprecated_load_command')); |
|
82
|
15 |
|
$this->setCommandFactory($container->getDefinition('hautelook_alice.doctrine.command.load_command')); |
|
83
|
15 |
|
} else { |
|
84
|
15 |
|
$this->setCommandFactory($container->getDefinition(sprintf('hautelook_alice.doctrine.%s.command.load_command', $driver))); |
|
85
|
|
|
} |
|
86
|
15 |
|
} |
|
87
|
24 |
|
} |
|
88
|
|
|
|
|
89
|
24 |
|
$container->getDefinition('hautelook_alice.alice.fixtures.loader') |
|
90
|
24 |
|
->replaceArgument(3, $container->getParameterBag()->all()); |
|
91
|
24 |
|
} |
|
92
|
|
|
|
|
93
|
15 |
|
private function setCommandFactory(Definition $commandDefinition) |
|
94
|
|
|
{ |
|
95
|
|
|
// Deprecated factory methods handling. |
|
96
|
|
|
// To be removed and set directly on config file when bumping Symfony requirements to >=2.6 |
|
97
|
15 |
|
if (method_exists($commandDefinition, 'setFactory')) { |
|
98
|
10 |
|
$commandDefinition->setFactory([new Reference('hautelook_alice.doctrine.command_factory'), 'createCommand']); |
|
99
|
10 |
|
} else { |
|
100
|
5 |
|
$commandDefinition->setFactoryService('hautelook_alice.doctrine.command_factory'); |
|
|
|
|
|
|
101
|
5 |
|
$commandDefinition->setFactoryMethod('createCommand'); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
15 |
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param string $driver |
|
107
|
|
|
* |
|
108
|
|
|
* @return bool |
|
109
|
|
|
*/ |
|
110
|
9 |
|
private function isExtensionEnabled($driver) |
|
111
|
|
|
{ |
|
112
|
9 |
|
return !empty($this->extensions[$driver]); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.