1 | <?php |
||
13 | final class Configuration implements ConfigurationInterface |
||
14 | { |
||
15 | /** {@inheritdoc} */ |
||
16 | 30 | public function getConfigTreeBuilder() |
|
49 | |||
50 | 30 | private function configureEntityProto(ArrayNodeDefinition $parent) |
|
51 | { |
||
52 | 30 | $parent->canBeDisabled(); |
|
53 | |||
54 | $parent |
||
55 | 30 | ->children() |
|
56 | 30 | ->scalarNode('class') |
|
57 | 30 | ->isRequired() |
|
58 | 30 | ->info('Doctrine class') |
|
59 | 30 | ->example('MyBundle:MyEntity'); |
|
60 | |||
61 | $parent |
||
62 | 30 | ->children() |
|
63 | 30 | ->scalarNode('prefix') |
|
64 | 30 | ->defaultNull() |
|
65 | 30 | ->info('Route prefix. Defaults to entity key if not set') |
|
66 | 30 | ->example('/my-entity'); |
|
67 | |||
68 | $parent |
||
69 | 30 | ->children() |
|
70 | 30 | ->scalarNode('mount') |
|
71 | 30 | ->defaultValue('api') |
|
72 | 30 | ->cannotBeEmpty() |
|
73 | 30 | ->info( |
|
74 | 'Route mount. You can create different entries '. |
||
75 | 30 | 'with different mounts. You can use this value when loading routes' |
|
76 | ) |
||
77 | 30 | ->example('my-mount-name'); |
|
78 | |||
79 | $parent |
||
80 | 30 | ->children() |
|
81 | 30 | ->scalarNode('repository') |
|
82 | 30 | ->defaultNull() |
|
83 | 30 | ->info( |
|
84 | 30 | 'Object repository. service reference,'.PHP_EOL. |
|
85 | 30 | 'default to factory-acquired doctrine repository for class' |
|
86 | ) |
||
87 | 30 | ->example('@my_entity.repository'); |
|
88 | |||
89 | $parent |
||
90 | 30 | ->children() |
|
91 | 30 | ->scalarNode('manager') |
|
92 | 30 | ->defaultNull() |
|
93 | 30 | ->info( |
|
94 | 30 | 'Object manager. service reference,'.PHP_EOL. |
|
95 | 30 | 'default to factory-acquired doctrine manager for class' |
|
96 | ) |
||
97 | 30 | ->example('@my_entity.repository'); |
|
98 | |||
99 | |||
100 | $actions = $parent |
||
101 | 30 | ->children() |
|
102 | 30 | ->arrayNode('actions'); |
|
103 | |||
104 | $actions |
||
105 | 30 | ->beforeNormalization() |
|
106 | 30 | ->ifArray() |
|
107 | 30 | ->then( |
|
108 | 30 | function (array $v) { |
|
109 | 30 | if (array_keys($v) !== range(0, count($v) - 1)) { |
|
110 | 15 | return $v; |
|
111 | } |
||
112 | |||
113 | 30 | $result = []; |
|
114 | 30 | foreach ($v as $key) { |
|
115 | 30 | $result[$key] = ['enabled' => true]; |
|
116 | } |
||
117 | |||
118 | 30 | return $result; |
|
119 | 30 | } |
|
120 | ) |
||
121 | 30 | ->end() |
|
122 | 30 | ->info('Action configuration'); |
|
123 | |||
124 | 30 | $this->configureCreateAction($actions); |
|
125 | 30 | $this->configureReadAction($actions); |
|
126 | 30 | $this->configureUpdateAction($actions); |
|
127 | 30 | $this->configureDeleteAction($actions); |
|
128 | 30 | $this->configureSearchAction($actions); |
|
129 | 30 | } |
|
130 | |||
131 | 30 | private function configureCreateAction(ArrayNodeDefinition $parent) |
|
132 | { |
||
133 | $create = $parent |
||
134 | 30 | ->children() |
|
135 | 30 | ->arrayNode('create'); |
|
136 | |||
137 | $create |
||
138 | 30 | ->children() |
|
139 | 30 | ->variableNode('factory') |
|
140 | 30 | ->defaultNull() |
|
141 | 30 | ->example('@my_entity.factory') |
|
142 | 30 | ->info( |
|
143 | 30 | 'Service ID implementing '.PHP_EOL. |
|
144 | 30 | EntityFactoryInterface::class.PHP_EOL. |
|
145 | 30 | 'Defaults to '.ReflectionConstructorFactory::class |
|
146 | ); |
||
147 | |||
148 | $create |
||
149 | 30 | ->children() |
|
150 | 30 | ->variableNode('processor') |
|
151 | 30 | ->defaultNull() |
|
152 | 30 | ->example('@my_entity.factory') |
|
153 | 30 | ->info( |
|
154 | 30 | 'Service ID implementing '.PHP_EOL. |
|
155 | 30 | EntityFactoryInterface::class.PHP_EOL. |
|
156 | 30 | 'Defaults to '.ReflectionConstructorFactory::class |
|
157 | ); |
||
158 | |||
159 | 30 | $this->configureActionNode($create, 'create'); |
|
160 | 30 | } |
|
161 | |||
162 | 30 | private function configureSearchAction(ArrayNodeDefinition $parent) |
|
184 | |||
185 | 30 | private function configureReadAction(ArrayNodeDefinition $parent) |
|
192 | |||
193 | 30 | private function configureUpdateAction(ArrayNodeDefinition $parent) |
|
194 | { |
||
195 | $update = $parent |
||
196 | 30 | ->children() |
|
197 | 30 | ->arrayNode('update'); |
|
198 | |||
199 | $update |
||
200 | 30 | ->children() |
|
201 | 30 | ->variableNode('processor') |
|
202 | 30 | ->defaultNull() |
|
203 | 30 | ->example('@my_entity.processor') |
|
204 | 30 | ->info( |
|
205 | 30 | 'Service ID implementing '.PHP_EOL. |
|
206 | 30 | EntityProcessorInterface::class.PHP_EOL. |
|
207 | 30 | 'Defaults to '.PropertyAccessProcessor::class |
|
208 | ); |
||
209 | |||
210 | 30 | $this->configureActionNode($update, 'update'); |
|
211 | 30 | } |
|
212 | |||
213 | 30 | private function configureDeleteAction(ArrayNodeDefinition $parent) |
|
220 | |||
221 | 30 | private function configureActionNode(ArrayNodeDefinition $parent, $action) |
|
231 | } |
||
232 |