1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Roave\BehatPsrContainer; |
5
|
|
|
|
6
|
|
|
use Behat\Testwork\ServiceContainer\Extension; |
7
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
8
|
|
|
use Psr\Container\ContainerInterface; |
9
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
12
|
|
|
|
13
|
|
|
final class PsrContainerExtension implements Extension |
14
|
|
|
{ |
15
|
|
|
public function process(ContainerBuilder $container) : void |
16
|
|
|
{ |
17
|
|
|
} |
18
|
|
|
|
19
|
1 |
|
public function getConfigKey() : string |
20
|
|
|
{ |
21
|
1 |
|
return __NAMESPACE__; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function initialize(ExtensionManager $extensionManager) : void |
25
|
|
|
{ |
26
|
|
|
} |
27
|
|
|
|
28
|
1 |
|
public function configure(ArrayNodeDefinition $builder) : void |
29
|
|
|
{ |
30
|
|
|
/** @noinspection NullPointerExceptionInspection */ |
31
|
|
|
$builder |
32
|
1 |
|
->children() |
33
|
1 |
|
->scalarNode('container')->defaultValue('config/container.php')->end() |
34
|
1 |
|
->scalarNode('name')->defaultValue('psr_container')->end() |
35
|
1 |
|
->end() |
36
|
1 |
|
->end(); |
37
|
1 |
|
} |
38
|
|
|
|
39
|
1 |
|
public function load(ContainerBuilder $container, array $config) : void |
40
|
|
|
{ |
41
|
1 |
|
$container->setParameter('roave.behat.psr.container.included.file', $config['container']); |
42
|
1 |
|
$container->setDefinition($config['name'], $this->createContainerDefinition()); |
43
|
1 |
|
} |
44
|
|
|
|
45
|
1 |
|
private function createContainerDefinition() : Definition |
46
|
|
|
{ |
47
|
1 |
|
$definition = new Definition(ContainerInterface::class, ['%roave.behat.psr.container.included.file%']); |
48
|
1 |
|
$definition->setFactory([ContainerFactory::class, 'createContainerFromIncludedFile']); |
49
|
1 |
|
$definition->addTag('helper_container.container'); |
50
|
1 |
|
$definition->setPublic(true); |
51
|
|
|
|
52
|
1 |
|
$this->setContainerScope($definition); |
53
|
|
|
|
54
|
1 |
|
return $definition; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* The way to set service scope was improved across Symfony versions: |
59
|
|
|
* - setShared was introduced in 2.8 |
60
|
|
|
* - setScope (and the constant) were removed in 3.0 |
61
|
|
|
* |
62
|
|
|
* @param Definition $definition |
63
|
|
|
*/ |
64
|
1 |
|
private function setContainerScope(Definition $definition) : void |
65
|
|
|
{ |
66
|
1 |
|
if (method_exists($definition, 'setShared')) { |
67
|
1 |
|
$definition->setShared(false); |
68
|
|
|
} else { |
69
|
|
|
$definition->setScope(ContainerBuilder::SCOPE_PROTOTYPE); |
|
|
|
|
70
|
|
|
} |
71
|
1 |
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.