-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathConfiguration.php
128 lines (113 loc) · 3.9 KB
/
Configuration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
* This file is part of the StateMachine package.
*
* (c) Alexandre Bacco
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace winzou\Bundle\StateMachineBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder(): TreeBuilder
{
if (\method_exists(TreeBuilder::class, 'getRootNode')) {
$treeBuilder = new TreeBuilder('winzou_state_machine');
$configNode = $treeBuilder->getRootNode();
} else {
$treeBuilder = new TreeBuilder();
$configNode = $treeBuilder->root('winzou_state_machine');
}
$configNode = $configNode
->useAttributeAsKey('name')
->prototype('array')
->children()
;
$configNode
->scalarNode('class')->isRequired()->end()
->scalarNode('graph')->defaultValue('default')->end()
->scalarNode('property_path')->defaultValue('state')->end()
->scalarNode('state_machine_class')->defaultValue('SM\\StateMachine\\StateMachine')->end()
;
$this->addStateSection($configNode);
$this->addTransitionSection($configNode);
$this->addCallbackSection($configNode);
$configNode->end()->end();
return $treeBuilder;
}
/**
* @param NodeBuilder $configNode
*/
protected function addStateSection(NodeBuilder $configNode)
{
$configNode
->arrayNode('states')
->useAttributeAsKey('name')
->prototype('scalar')
->end()
;
}
/**
* @param NodeBuilder $configNode
*/
protected function addTransitionSection(NodeBuilder $configNode)
{
$configNode
->arrayNode('transitions')
->useAttributeAsKey('name')
->prototype('array')
->children()
->arrayNode('from')
->prototype('scalar')->end()
->end()
->scalarNode('to')->end()
->end()
->end()
->end()
;
}
/**
* @param NodeBuilder $configNode
*/
protected function addCallbackSection(NodeBuilder $configNode)
{
$callbacks = $configNode->arrayNode('callbacks')->children();
$this->addSubCallbackSection($callbacks, 'guard');
$this->addSubCallbackSection($callbacks, 'before');
$this->addSubCallbackSection($callbacks, 'after');
$callbacks->end()->end();
}
/**
* @param NodeBuilder $callbacks
* @param string $type
*/
protected function addSubCallbackSection(NodeBuilder $callbacks, $type)
{
$callbacks
->arrayNode($type)
->useAttributeAsKey('name')
->prototype('array')
->children()
->variableNode('on')->end()
->variableNode('from')->end()
->variableNode('to')->end()
->variableNode('excluded_on')->end()
->variableNode('excluded_from')->end()
->variableNode('excluded_to')->end()
->variableNode('do')->end()
->scalarNode('disabled')->defaultValue(false)->end()
->scalarNode('priority')->defaultValue(0)->end()
->arrayNode('args')->performNoDeepMerging()->prototype('scalar')->end()
->end()
->end()
->end()
;
}
}