|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Velikonja\LabbyBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
6
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
7
|
|
|
use SyncFS\Configuration\Configuration as SyncFSConfiguration; |
|
8
|
|
|
use Velikonja\LabbyBundle\Events; |
|
9
|
|
|
|
|
10
|
|
|
class Configuration implements ConfigurationInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* {@inheritDoc} |
|
14
|
|
|
*/ |
|
15
|
5 |
|
public function getConfigTreeBuilder() |
|
16
|
|
|
{ |
|
17
|
5 |
|
$treeBuilder = new TreeBuilder(); |
|
18
|
5 |
|
$rootNode = $treeBuilder->root('velikonja_labby'); |
|
19
|
|
|
|
|
20
|
|
|
$rootNode |
|
21
|
5 |
|
->children() |
|
22
|
5 |
|
->scalarNode('process_timeout')->defaultValue(5 * 60)->end() |
|
23
|
5 |
|
->arrayNode('roles') |
|
24
|
5 |
|
->treatNullLike(array()) |
|
25
|
5 |
|
->prototype('scalar')->end() |
|
26
|
5 |
|
->defaultValue(array('remote')) |
|
27
|
5 |
|
->end() |
|
28
|
5 |
|
->arrayNode('remote') |
|
29
|
5 |
|
->isRequired() |
|
30
|
5 |
|
->children() |
|
31
|
5 |
|
->scalarNode('hostname')->isRequired()->end() |
|
32
|
5 |
|
->scalarNode('path')->isRequired()->end() |
|
33
|
5 |
|
->scalarNode('env')->defaultValue('prod')->end() |
|
34
|
5 |
|
->end() |
|
35
|
5 |
|
->end() |
|
36
|
5 |
|
->append( |
|
37
|
5 |
|
$this->addSyncFsNode() |
|
38
|
|
|
) |
|
39
|
5 |
|
->arrayNode('db') |
|
40
|
5 |
|
->children() |
|
41
|
5 |
|
->booleanNode('recreate')->defaultValue(true)->end() |
|
42
|
|
|
// copy from doctrine dbal config |
|
43
|
5 |
|
->scalarNode('driver')->end() |
|
44
|
5 |
|
->scalarNode('dbname')->end() |
|
45
|
5 |
|
->scalarNode('host')->defaultValue('localhost')->end() |
|
46
|
5 |
|
->scalarNode('port')->defaultNull()->end() |
|
47
|
5 |
|
->scalarNode('user')->defaultValue('root')->end() |
|
48
|
5 |
|
->scalarNode('password')->defaultNull()->end() |
|
49
|
5 |
|
->scalarNode('charset')->end() |
|
50
|
5 |
|
->end() |
|
51
|
5 |
|
->end() |
|
52
|
5 |
|
->arrayNode('event_executors') |
|
53
|
5 |
|
->useAttributeAsKey('event_name') |
|
54
|
5 |
|
->beforeNormalization() |
|
55
|
5 |
|
->always() |
|
56
|
|
|
// prefix all events with bundle name |
|
57
|
|
|
->then(function ($events) { |
|
58
|
4 |
|
$normalized = array(); |
|
59
|
4 |
|
foreach ($events as $name => $value) { |
|
60
|
4 |
|
$normalized['velikonja_labby.' . $name] = $value; |
|
61
|
|
|
} |
|
62
|
4 |
|
return $normalized; |
|
63
|
5 |
|
}) |
|
64
|
5 |
|
->end() |
|
65
|
5 |
|
->validate() |
|
66
|
5 |
|
->ifTrue(function ($events) { |
|
67
|
4 |
|
$allEvents = Events::all(); |
|
68
|
4 |
|
foreach ($events as $name => $value) { |
|
69
|
4 |
|
if (! in_array($name, $allEvents)) { |
|
70
|
4 |
|
return true; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
3 |
|
return false; |
|
75
|
5 |
|
}) |
|
76
|
5 |
|
->thenInvalid("Event does not exists. \n%s") |
|
77
|
5 |
|
->end() |
|
78
|
5 |
|
->prototype('array') |
|
79
|
5 |
|
->prototype('array') |
|
80
|
5 |
|
->useAttributeAsKey('type') |
|
81
|
5 |
|
->requiresAtLeastOneElement() |
|
82
|
5 |
|
->prototype('scalar')->end() |
|
83
|
5 |
|
->end() |
|
84
|
5 |
|
->end() |
|
85
|
5 |
|
->end() |
|
86
|
5 |
|
->end(); |
|
87
|
|
|
|
|
88
|
5 |
|
return $treeBuilder; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Returns configuration node of Velikonja/SyncFS library. |
|
93
|
|
|
* |
|
94
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition |
|
95
|
|
|
*/ |
|
96
|
5 |
|
private function addSyncFsNode() |
|
97
|
|
|
{ |
|
98
|
5 |
|
$config = new SyncFSConfiguration(); |
|
99
|
5 |
|
$builder = new TreeBuilder(); |
|
100
|
5 |
|
$node = $builder->root('fs'); |
|
101
|
|
|
|
|
102
|
5 |
|
return $config->getConfigNode($node); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|