1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bex\Behat\BehatRSTSpecificationLocatorExtension\ServiceContainer; |
4
|
|
|
|
5
|
|
|
use Behat\Gherkin\Cache\FileCache; |
6
|
|
|
use Behat\Gherkin\Cache\MemoryCache; |
7
|
|
|
use Behat\Testwork\ServiceContainer\Extension; |
8
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
9
|
|
|
use Bex\Behat\BehatRSTSpecificationLocatorExtension\RST\Loader\RSTFileLoader; |
10
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
11
|
|
|
use Symfony\Component\Config\FileLocator; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
13
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
14
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
15
|
|
|
|
16
|
|
|
class BehatRSTSpecificationLocatorExtension implements Extension |
17
|
|
|
{ |
18
|
|
|
private const CONFIG_KEY = 'bex_rst_specification_locator'; |
19
|
|
|
|
20
|
|
|
public function getConfigKey() |
21
|
|
|
{ |
22
|
|
|
return self::CONFIG_KEY; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function initialize(ExtensionManager $extensionManager) |
26
|
|
|
{ |
27
|
|
|
// no-op |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function configure(ArrayNodeDefinition $builder) |
31
|
|
|
{ |
32
|
|
|
$builder |
33
|
|
|
->addDefaultsIfNotSet() |
34
|
|
|
->children() |
35
|
|
|
->scalarNode('cache') |
36
|
|
|
->info('Sets the rst gherkin parser cache folder') |
37
|
|
|
->defaultValue( |
38
|
|
|
is_writable(sys_get_temp_dir()) |
39
|
|
|
? sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat_rst_gherkin_cache' |
40
|
|
|
: null |
41
|
|
|
) |
42
|
|
|
->end() |
43
|
|
|
->end() |
|
|
|
|
44
|
|
|
; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function load(ContainerBuilder $container, array $config) |
48
|
|
|
{ |
49
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config')); |
50
|
|
|
$loader->load('services.yml'); |
51
|
|
|
$container->getDefinition(Config::class)->addArgument($config); |
52
|
|
|
|
53
|
|
|
if (!empty($config['cache'])) { |
54
|
|
|
$cacheDefinition = new Definition(FileCache::class, array($config['cache'])); |
55
|
|
|
} else { |
56
|
|
|
$cacheDefinition = new Definition(MemoryCache::class); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$container->getDefinition(RSTFileLoader::class)->setArgument('$cache', $cacheDefinition); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function process(ContainerBuilder $container) |
63
|
|
|
{ |
64
|
|
|
// no-op |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|