1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Openl10n\Cli\ServiceContainer\Extension; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
8
|
|
|
|
9
|
|
|
class FilesExtension implements ConfiguredExtension |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* {@inheritdoc} |
13
|
|
|
*/ |
14
|
|
|
public function initialize(ContainerBuilder $container) |
15
|
|
|
{ |
16
|
|
|
$container |
17
|
|
|
->register('file.pattern_guess.symfony', 'Openl10n\Cli\File\Guess\SymfonyGuess') |
18
|
|
|
; |
19
|
|
|
$container |
20
|
|
|
->register('file.pattern_guess.silex_kitchen_edition', 'Openl10n\Cli\File\Guess\SilexKitchenEditionGuess') |
21
|
|
|
; |
22
|
|
|
|
23
|
|
|
$container |
24
|
|
|
->register('file.pattern_guess.composable', 'Openl10n\Cli\File\Guess\ComposableGuess') |
25
|
|
|
->addArgument([ |
26
|
|
|
new Reference('file.pattern_guess.symfony'), |
27
|
|
|
new Reference('file.pattern_guess.silex_kitchen_edition'), |
28
|
|
|
]) |
29
|
|
|
; |
30
|
|
|
|
31
|
|
|
$container |
32
|
|
|
->setAlias('file.pattern_guess', 'file.pattern_guess.composable') |
33
|
|
|
; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function load(array $config, ContainerBuilder $container) |
40
|
|
|
{ |
41
|
|
|
$container |
42
|
|
|
->register('file_handler', 'Openl10n\Cli\File\FileHandler') |
43
|
|
|
->addArgument(new Reference('configuration.loader')) |
44
|
|
|
->addArgument($config) |
45
|
|
|
; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function configure(ArrayNodeDefinition $node) |
52
|
|
|
{ |
53
|
|
|
$node |
54
|
|
|
->beforeNormalization() |
55
|
|
|
// If config contains only a single string (without array) |
56
|
|
|
// then convert to an array with single string. |
57
|
|
|
->ifString() |
58
|
|
|
->then(function ($v) { return array($v); }) |
59
|
|
|
->end() |
60
|
|
|
->prototype('array') |
61
|
|
|
->beforeNormalization() |
62
|
|
|
// Item could be abbreviated with only a single string |
63
|
|
|
// which is interpreted as the pattern. |
64
|
|
|
->ifString() |
65
|
|
|
->then(function ($v) { return ['pattern' => $v]; }) |
66
|
|
|
->end() |
67
|
|
|
->children() |
68
|
|
|
->scalarNode('pattern') |
69
|
|
|
->isRequired() |
70
|
|
|
->end() |
71
|
|
|
->arrayNode('ignore') |
72
|
|
|
->beforeNormalization() |
73
|
|
|
->ifNull() |
74
|
|
|
->thenEmptyArray() |
75
|
|
|
->ifString() |
76
|
|
|
->then(function ($v) { return array($v); }) |
77
|
|
|
->end() |
78
|
|
|
->prototype('scalar')->end() |
79
|
|
|
->end() |
80
|
|
|
->arrayNode('options') |
81
|
|
|
->beforeNormalization() |
82
|
|
|
->ifNull() |
83
|
|
|
->thenEmptyArray() |
84
|
|
|
->end() |
85
|
|
|
->prototype('variable')->end() |
86
|
|
|
->end() |
87
|
|
|
->end() |
88
|
|
|
->end(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function getName() |
95
|
|
|
{ |
96
|
|
|
return 'files'; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|