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 Faker\Provider\Base; |
15
|
|
|
use Hautelook\AliceBundle\HautelookAliceBundle; |
16
|
|
|
use LogicException; |
17
|
|
|
use Symfony\Component\Config\FileLocator; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
20
|
|
|
use Symfony\Component\Finder\Finder; |
21
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @private |
25
|
|
|
* |
26
|
|
|
* @author Baldur Rensch <[email protected]> |
27
|
|
|
* @author Théo FIDRY <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
final class HautelookAliceExtension extends Extension |
30
|
|
|
{ |
31
|
|
|
const SERVICES_DIR = __DIR__.'/../../resources/config'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @inheritdoc |
35
|
|
|
*/ |
36
|
|
|
public function load(array $configs, ContainerBuilder $container) |
37
|
|
|
{ |
38
|
|
|
$bundles = array_flip($container->getParameter('kernel.bundles')); |
39
|
|
|
|
40
|
27 |
|
if (false === array_key_exists('Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle', $bundles)) { |
41
|
|
|
throw new LogicException( |
42
|
27 |
|
sprintf( |
43
|
27 |
|
'Cannot register "%s" without "Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle".', |
44
|
27 |
|
HautelookAliceBundle::class |
45
|
27 |
|
) |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->loadConfig($configs, $container); |
50
|
|
|
$this->loadServices($container); |
51
|
|
|
|
52
|
27 |
|
// Register autoconfiguration rules for Symfony DI 3.3+ |
53
|
|
|
if (method_exists($container, 'registerForAutoconfiguration')) { |
54
|
27 |
|
$container->registerForAutoconfiguration(Base::class) |
55
|
27 |
|
->addTag('nelmio_alice.faker.provider'); |
56
|
|
|
} |
57
|
24 |
|
} |
58
|
24 |
|
|
59
|
24 |
|
/** |
60
|
|
|
* Loads alice configuration and add the configuration values to the application parameters. |
61
|
24 |
|
* |
62
|
24 |
|
* @param array $configs |
63
|
|
|
* @param ContainerBuilder $container |
64
|
|
|
* |
65
|
|
|
* @throws \InvalidArgumentException |
66
|
24 |
|
*/ |
67
|
24 |
|
private function loadConfig(array $configs, ContainerBuilder $container) |
68
|
16 |
|
{ |
69
|
16 |
|
$configuration = new Configuration(); |
70
|
8 |
|
$processedConfiguration = $this->processConfiguration($configuration, $configs); |
71
|
8 |
|
|
72
|
|
|
foreach ($processedConfiguration as $key => $value) { |
73
|
|
|
$container->setParameter( |
74
|
24 |
|
$this->getAlias().'.'.$key, |
75
|
24 |
|
$value |
76
|
24 |
|
); |
77
|
24 |
|
} |
78
|
15 |
|
} |
79
|
|
|
|
80
|
15 |
|
/** |
81
|
15 |
|
* Loads all the services declarations. |
82
|
15 |
|
* |
83
|
15 |
|
* @param ContainerBuilder $container |
84
|
15 |
|
*/ |
85
|
|
|
private function loadServices(ContainerBuilder $container) |
86
|
15 |
|
{ |
87
|
24 |
|
$loader = new XmlFileLoader($container, new FileLocator(self::SERVICES_DIR)); |
88
|
|
|
$finder = new Finder(); |
89
|
24 |
|
|
90
|
24 |
|
$finder->files()->in(self::SERVICES_DIR); |
91
|
24 |
|
|
92
|
|
|
foreach ($finder as $file) { |
93
|
15 |
|
$loader->load( |
94
|
|
|
$file->getRelativePathname() |
95
|
|
|
); |
96
|
|
|
} |
97
|
15 |
|
} |
98
|
|
|
} |
99
|
|
|
|