|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ContextServiceExtension package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) FriendsOfBehat |
|
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 FriendsOfBehat\ContextServiceExtension\ServiceContainer\Scenario; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
|
15
|
|
|
use Symfony\Component\Config\Loader\DelegatingLoader; |
|
16
|
|
|
use Symfony\Component\Config\Loader\LoaderResolver; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @internal |
|
24
|
|
|
*/ |
|
25
|
|
|
final class ContainerFactory |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $basePath |
|
29
|
|
|
* @param Definition $contextRegistryDefinition |
|
30
|
|
|
* @param array $importedFiles |
|
31
|
|
|
* |
|
32
|
|
|
* @return ContainerInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
public function createContainer($basePath, Definition $contextRegistryDefinition, array $importedFiles = []) |
|
35
|
|
|
{ |
|
36
|
|
|
$container = new ContainerBuilder(); |
|
37
|
|
|
|
|
38
|
|
|
$loader = $this->createLoader($container, $basePath); |
|
39
|
|
|
foreach ($importedFiles as $file) { |
|
40
|
|
|
$loader->load($file); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$container->addCompilerPass(new ContextRegistryPass($contextRegistryDefinition)); |
|
44
|
|
|
$container->compile(); |
|
45
|
|
|
|
|
46
|
|
|
return $container; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param ContainerBuilder $container |
|
51
|
|
|
* @param string $basePath |
|
52
|
|
|
* |
|
53
|
|
|
* @return DelegatingLoader |
|
54
|
|
|
*/ |
|
55
|
|
|
private function createLoader(ContainerBuilder $container, $basePath) |
|
56
|
|
|
{ |
|
57
|
|
|
$fileLocator = new FileLocator($basePath); |
|
58
|
|
|
$loader = new DelegatingLoader(new LoaderResolver([ |
|
59
|
|
|
new Loader\XmlFileLoader($container, $fileLocator), |
|
60
|
|
|
new Loader\YamlFileLoader($container, $fileLocator), |
|
61
|
|
|
new Loader\PhpFileLoader($container, $fileLocator), |
|
62
|
|
|
])); |
|
63
|
|
|
|
|
64
|
|
|
return $loader; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|