|
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; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Testwork\Environment\ServiceContainer\EnvironmentExtension; |
|
15
|
|
|
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; |
|
16
|
|
|
use Behat\Testwork\ServiceContainer\Extension; |
|
17
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
|
18
|
|
|
use FriendsOfBehat\ContextServiceExtension\Context\ContextRegistry; |
|
19
|
|
|
use FriendsOfBehat\ContextServiceExtension\Context\Environment\Handler\ContextServiceEnvironmentHandler; |
|
20
|
|
|
use FriendsOfBehat\ContextServiceExtension\Listener\ScenarioContainerResetter; |
|
21
|
|
|
use FriendsOfBehat\ContextServiceExtension\ServiceContainer\Scenario\ContainerFactory; |
|
22
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
23
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
24
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
25
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @internal |
|
29
|
|
|
*/ |
|
30
|
|
|
final class ContextServiceExtension implements Extension |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getConfigKey() |
|
36
|
|
|
{ |
|
37
|
|
|
return 'fob_context_service'; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function initialize(ExtensionManager $extensionManager) |
|
44
|
|
|
{ |
|
45
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function configure(ArrayNodeDefinition $builder) |
|
52
|
|
|
{ |
|
53
|
|
|
$builder |
|
54
|
|
|
->children() |
|
55
|
|
|
->arrayNode('imports') |
|
56
|
|
|
->performNoDeepMerging() |
|
57
|
|
|
->prototype('scalar') |
|
58
|
|
|
; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritdoc} |
|
63
|
|
|
*/ |
|
64
|
|
|
public function load(ContainerBuilder $container, array $config) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->loadContextRegistry($container); |
|
67
|
|
|
$this->loadScenarioServiceContainer($container, $config); |
|
68
|
|
|
$this->loadEnvironmentHandler($container); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritdoc} |
|
73
|
|
|
*/ |
|
74
|
|
|
public function process(ContainerBuilder $container) |
|
75
|
|
|
{ |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param ContainerBuilder $container |
|
81
|
|
|
*/ |
|
82
|
|
|
private function loadContextRegistry(ContainerBuilder $container) |
|
83
|
|
|
{ |
|
84
|
|
|
$container->setDefinition('fob_context_service.context_registry', (new Definition(ContextRegistry::class))->setPublic(false)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param ContainerBuilder $container |
|
89
|
|
|
* @param array $config |
|
90
|
|
|
*/ |
|
91
|
|
|
private function loadScenarioServiceContainer(ContainerBuilder $container, array $config) |
|
92
|
|
|
{ |
|
93
|
|
|
$container->set('fob_context_service.service_container.scenario', (new ContainerFactory())->createContainer( |
|
94
|
|
|
$container->getParameter('paths.base'), |
|
95
|
|
|
$container->getDefinition('fob_context_service.context_registry'), |
|
96
|
|
|
$config['imports'] |
|
97
|
|
|
)); |
|
98
|
|
|
|
|
99
|
|
|
$definition = new Definition(ScenarioContainerResetter::class, [ |
|
100
|
|
|
new Reference('fob_context_service.service_container.scenario'), |
|
101
|
|
|
]); |
|
102
|
|
|
$definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG); |
|
103
|
|
|
$container->setDefinition('fob_context_service.service_container.scenario.resetter', $definition); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param ContainerBuilder $container |
|
108
|
|
|
*/ |
|
109
|
|
|
private function loadEnvironmentHandler(ContainerBuilder $container) |
|
110
|
|
|
{ |
|
111
|
|
|
$definition = new Definition(ContextServiceEnvironmentHandler::class, [ |
|
112
|
|
|
new Reference('fob_context_service.service_container.scenario'), |
|
113
|
|
|
new Reference('fob_context_service.context_registry'), |
|
114
|
|
|
]); |
|
115
|
|
|
$definition->addTag(EnvironmentExtension::HANDLER_TAG, ['priority' => 128]); |
|
116
|
|
|
|
|
117
|
|
|
$container->setDefinition('fob_context_service.environment_handler.context_service', $definition); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|