1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Kévin Dunglas <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This source file is subject to the MIT license that is bundled |
7
|
|
|
* with this source code in the file LICENSE. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Dunglas\ActionBundle\DependencyInjection; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
13
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
14
|
|
|
use Symfony\Component\Console\Command\Command; |
15
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
* |
20
|
|
|
* @author Kévin Dunglas <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Configuration implements ConfigurationInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function getConfigTreeBuilder() |
28
|
|
|
{ |
29
|
|
|
$treeBuilder = new TreeBuilder(); |
30
|
|
|
$treeBuilder->root('dunglas_action') |
31
|
|
|
->fixXmlConfig('directory', 'directories') |
32
|
|
|
->children() |
33
|
|
|
->arrayNode('methods') |
34
|
|
|
->info('The list of methods to autowire.') |
35
|
|
|
->prototype('scalar')->end() |
36
|
|
|
->defaultValue(['__construct', 'get*', 'set*']) |
37
|
|
|
->end() |
38
|
|
|
->arrayNode('directories') |
39
|
|
|
->info('List of directories relative to the kernel root directory containing classes.') |
40
|
|
|
->prototype('scalar')->end() |
41
|
|
|
->defaultValue(['../src/*Bundle/{Action,Command,Controller,EventSubscriber,Twig}']) |
42
|
|
|
->end() |
43
|
|
|
->arrayNode('tags') |
44
|
|
|
->info('List of tags to add when implementing the corresponding class.') |
45
|
|
|
->useAttributeAsKey('class') |
46
|
|
|
->prototype('array') |
47
|
|
|
// Converts 'console.command' to ['console.command'] |
48
|
|
|
->beforeNormalization()->ifString()->then(function ($v) { |
49
|
|
|
return [$v]; |
50
|
|
|
})->end() |
51
|
|
|
->prototype('array') |
52
|
|
|
// Converts 'console.command' to ['console.command', []] |
53
|
|
|
->beforeNormalization()->ifString()->then(function ($v) { |
54
|
|
|
return [$v, []]; |
55
|
|
|
})->end() |
56
|
|
|
->validate() |
57
|
|
|
->ifTrue(function ($v) { |
58
|
|
|
return count($v) !== 2 || !is_string($v[0]) || !is_array($v[1]); |
59
|
|
|
}) |
60
|
|
|
->thenInvalid('Invalid tag format. They must be as following: [\'my_tag.name\', [\'attribute\' => \'value\']]') |
61
|
|
|
->end() |
62
|
|
|
->prototype('variable')->end() |
63
|
|
|
->end() |
64
|
|
|
->end() |
65
|
|
|
->defaultValue([ |
66
|
|
|
Command::class => [['console.command', []]], |
67
|
|
|
EventSubscriberInterface::class => [['kernel.event_subscriber', []]], |
68
|
|
|
\Twig_ExtensionInterface::class => [['twig.extension', []]], |
69
|
|
|
]) |
70
|
|
|
->end() |
71
|
|
|
->end() |
72
|
|
|
->end(); |
73
|
|
|
|
74
|
|
|
return $treeBuilder; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|