8000 [Config] cleanup · symfony/symfony@fb27de0 · GitHub
[go: up one dir, main page]

Skip to content

Commit fb27de0

Browse files
committed
[Config] cleanup
1 parent 3f76d0f commit fb27de0

File tree

7 files changed

+110
-104
lines changed

7 files changed

+110
-104
lines changed

src/Symfony/Component/Config/Definition/BaseNode.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct($name, NodeInterface $parent = null)
5656
}
5757

5858
/**
59-
* Sets info message
59+
* Sets info message.
6060
*
6161
* @param string $info The info text
6262
*/
@@ -66,7 +66,7 @@ public function setInfo($info)
6666
}
6767

6868
/**
69-
* Returns info message
69+
* Returns info message.
7070
*
7171
* @return string The info text
7272
*/
@@ -78,7 +78,7 @@ public function getInfo()
7878
/**
7979
* Sets the example configuration for this node.
8080
*
81-
* @param array $example
81+
* @param string|array $example
8282
*/
8383
public function setExample($example)
8484
{
@@ -88,7 +88,7 @@ public function setExample($example)
8888
/**
8989
* Retrieves the example configuration for this node.
9090
*
91-
* @return mixed The example
91+
* @return string|array The example
9292
*/
9393
public function getExample()
9494
{

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct($name, NodeParentInterface $parent = null)
5050
}
5151

5252
/**
53-
* Set a custom children builder
53+
* Sets a custom children builder.
5454
*
5555
* @param NodeBuilder $builder A custom NodeBuilder
5656
*/
@@ -60,7 +60,7 @@ public function setBuilder(NodeBuilder $builder)
6060
}
6161

6262
/**
63-
* Returns a builder to add children nodes
63+
* Returns a builder to add children nodes.
6464
*
6565
* @return NodeBuilder
6666
*/
@@ -78,16 +78,16 @@ public function children()
7878
*/
7979
public function prototype($type)
8080
{
81-
$builder = $this->getNodeBuilder();
82-
$this->prototype = $builder->node(null, $type);
83-
$this->prototype->parent = $this;
84-
85-
return $this->prototype;
81+
return $this->prototype = $this->getNodeBuilder()->node(null, $type)->setParent($this);
8682
}
8783

8884
/**
8985
* Adds the default value if the node is not set in the configuration.
9086
*
87+
* This method is applicable to concrete nodes only (not to prototype nodes).
88+
* If this function has been called and the node is not set during the finalization
89+
* phase, it's default value will be derived from its children default values.
90+
*
9191
* @return ArrayNodeDefinition
9292
*/
9393
public function addDefaultsIfNotSet()
@@ -100,6 +100,8 @@ public function addDefaultsIfNotSet()
100100
/**
101101
* Requires the node to have at least one element.
102102
*
103+
* This method is applicable to prototype nodes only.
104+
*
103105
* @return ArrayNodeDefinition
104106
*/
105107
public function requiresAtLeastOneElement()
@@ -139,7 +141,7 @@ public function fixXmlConfig($singular, $plural = null)
139141
}
140142

141143
/**
142-
* Set the attribute which value is to be used as key.
144+
* Sets the attribute which value is to be used as key.
143145
*
144146
* This is useful when you have an indexed array that should be an
145147
* associative array. You can select an item from within the array
@@ -148,17 +150,19 @@ public function fixXmlConfig($singular, $plural = null)
148150
*
149151
* array(
150152
* array('id' => 'my_name', 'foo' => 'bar'),
151-
* )
153+
* );
152154
*
153-
* becomes
155+
* becomes
154156
*
155157
* array(
156158
* 'my_name' => array('foo' => 'bar'),
157-
* )
159+
* );
158160
*
159161
* If you'd like "'id' => 'my_name'" to still be present in the resulting
160162
* array, then you can set the second argument of this method to false.
161163
*
164+
* This method is applicable to prototype nodes only.
165+
*
162166
* @param string $name The name of the key
163167
* @param Boolean $removeKeyItem Whether or not the key item should be removed.
164168
*
@@ -216,12 +220,12 @@ public function ignoreExtraKeys()
216220
}
217221

218222
/**
219-
* Append a node definition.
223+
* Appends a node definition.
220224
*
221225
* $node = new ArrayNodeDefinition()
222226
* ->children()
223-
* ->scalarNode('foo')
224-
* ->scalarNode('baz')
227+
* ->scalarNode('foo')->end()
228+
* ->scalarNode('baz')->end()
225229
* ->end()
226230
* ->append($this->getBarNodeDefinition())
227231
* ;
@@ -254,10 +258,30 @@ protected function getNodeBuilder()
254258
*/
255259
protected function createNode()
256260
{
257-
if (null == $this->prototype) {
261+
if (null === $this->prototype) {
258262
$node = new ArrayNode($this->name, $this->parent);
263+
264+
foreach ($this->children as $child) {
265+
$child->parent = $node;
266+
$node->addChild($child->getNode());
267+
}
259268
} else {
260269
$node = new PrototypedArrayNode($this->name, $this->parent);
270+
271+
if (null !== $this->key) {
272+
$node->setKeyAttribute($this->key, $this->removeKeyItem);
273+
}
274+
275+
if (true === $this->atLeastOne) {
276+
$node->setMinNumberOfElements(1);
277+
}
278+
279+
if ($this->default) {
280+
$node->setDefaultValue($this->defaultValue);
281+
}
282+
283+
$this->prototype->parent = $node;
284+
$node->setPrototype($this->prototype->getNode());
261285
}
262286

263287
$node->setAddIfNotSet($this->addDefaults);
@@ -283,28 +307,6 @@ protected function createNode()
283307
$node->setFinalValidationClosures($this->validation->rules);
284308
}
285309

286-
if (null == $this->prototype) {
287-
foreach ($this->children as $child) {
288-
$child->parent = $node;
289-
$node->addChild($child->getNode());
290-
}
291-
} else {
292-
if (null !== $this->key) {
293-
$node->setKeyAttribute($this->key, $this->removeKeyItem);
294-
}
295-
296-
if (true === $this->atLeastOne) {
297-
$node->setMinNumberOfElements(1);
298-
}
299-
300-
if (null !== $this->defaultValue) {
301-
$node->setDefaultValue($this->defaultValue);
302-
}
303-
304-
$this->prototype->parent = $node;
305-
$node->setPrototype($this->prototype->getNode());
306-
}
307-
308310
return $node;
309311
}
310312

src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(NodeDefinition $node)
3535
}
3636

3737
/**
38-
* Mark the expression as being always used.
38+
* Marks the expression as being always used.
3939
*
4040
* @return ExprBuilder
4141
*/

src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct()
3636
}
3737

3838
/**
39-
* Set the parent node
39+
* Set the parent node.
4040
*
4141
* @param ParentNodeDefinitionInterface $parent The parent node
4242
*
@@ -50,7 +50,7 @@ public function setParent(ParentNodeDefinitionInterface $parent = null)
5050
}
5151

5252
/**
53-
* Creates a child array node
53+
* Creates a child array node.
5454
*
5555
* @param string $name The name of the node
5656
*
@@ -130,12 +130,14 @@ public function node($name, $type)
130130
}
131131

132132
/**
133-
* Append a node definition.
133+
* Appends a node definition.
134+
*
135+
* Usage:
134136
*
135137
* $node = new ArrayNodeDefinition('name')
136138
* ->children()
137-
* ->scalarNode('foo')
138-
* ->scalarNode('baz')
139+
* ->scalarNode('foo')->end()
140+
* ->scalarNode('baz')->end()
139141
* ->append($this->getBarNodeDefinition())
140142
* ->end()
141143
* ;
@@ -160,7 +162,7 @@ public function append(NodeDefinition $node)
160162
}
161163

162164
/**
163-
* Add or override a node Type
165+
* Adds or overrides a node Type.
164166
*
165167
* @param string $type The name of the type
166168
* @param string $class The fully qualified name the node definition class
@@ -175,7 +177,7 @@ public function setNodeClass($type, $class)
175177
}
176178

177179
/**
178-
* Returns the class name of the node definition
180+
* Returns the class name of the node definition.
179181
*
180182
* @param string $type The node type
181183
*

src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct($name, NodeParentInterface $parent = null)
5252
}
5353

5454
/**
55-
* Sets the parent node
55+
* Sets the parent node.
5656
*
5757
* @param NodeParentInterface $parent The parent
5858
*/
@@ -64,7 +64,7 @@ public function setParent(NodeParentInterface $parent)
6464
}
6565

6666
/**
67-
* Sets info message
67+
* Sets info message.
6868
*
6969
* @param string $info The info text
7070
*
@@ -78,9 +78,9 @@ public function setInfo($info)
7878
}
7979

8080
/**
81-
* Sets example configuration
81+
* Sets example configuration.
8282
*
83-
* @param example $example
83+
* @param string|array $example
8484
*
8585
* @return NodeDefinition
8686
*/
@@ -230,37 +230,51 @@ public function defaultFalse()
230230
}
231231

232232
/**
233-
* Gets the builder for normalization rules.
233+
* Sets an expression to run before the normalization.
234234
*
235-
* @return NormalizationBuilder
235+
* @return ExprBuilder
236236
*/
237-
protected function normalization()
237+
public function beforeNormalization()
238238
{
239-
if (null === $this->normalization) {
240-
$this->normalization = new NormalizationBuilder($this);
241-
}
239+
return $this->normalization()->before();
240+
}
242241

243-
return $this->normalization;
242+
/**
243+
* Denies the node value being empty.
244+
*
245+
* @return NodeDefinition
246+
*/
247+
public function cannotBeEmpty()
248+
{
249+
$this->allowEmptyValue = false;
250+
251+
return $this;
244252
}
245253

246254
/**
247-
* Sets an expression to run before the normalization.
255+
* Sets an expression to run for the validation.
256+
*
257+
* The expression receives the value of the node and must return it. It can
258+
* modify it.
259+
* An exception should be thrown when the node is not valid.
248260
*
249261
* @return ExprBuilder
250262
*/
251-
public function beforeNormalization()
263+
public function validate()
252264
{
253-
return $this->normalization()->before();
265+
return $this->validation()->rule();
254266
}
255267

256268
/**
257-
* Denies the node value being empty.
269+
* Sets whether the node can be overwritten.
270+
*
271+
* @param Boolean $deny Whether the overwriting is forbidden or not
258272
*
259273
* @return NodeDefinition
260274
*/
261-
public function cannotBeEmpty()
275+
public function cannotBeOverwritten($deny = true)
262276
{
263-
$this->allowEmptyValue = false;
277+
$this->merge()->denyOverwrite($deny);
264278

265279
return $this;
266280
}
@@ -279,20 +293,6 @@ protected function validation()
279293
return $this->validation;
280294
}
281295

282-
/**
283-
* Sets an expression to run for the validation.
284-
*
285-
* The expression receives the value of the node and must return it. It can
286-
* modify it.
287-
* An exception should be thrown when the node is not valid.
288-
*
289-
* @return ExprBuilder
290-
*/
291-
public function validate()
292-
{
293-
return $this->validation()->rule();
294-
}
295-
296296
/**
297297
* Gets the builder for merging rules.
298298
*
@@ -308,17 +308,17 @@ protected function merge()
308308
}
309309

310310
/**
311-
* Sets whether the node can be overwritten.
312-
*
313-
* @param Boolean $deny Whether the overwriting is forbidden or not
311+
* Gets the builder for normalization rules.
314312
*
315-
* @return NodeDefinition
313+
* @return NormalizationBuilder
316314
*/
317-
public function cannotBeOverwritten($deny = true)
315+
protected function normalization()
318316
{
319-
$this->merge()->denyOverwrite($deny);
317+
if (null === $this->normalization) {
318+
$this->normalization = new NormalizationBuilder($this);
319+
}
320320

321-
return $this;
321+
return $this->normalization;
322322
}
323323

324324
/**

0 commit comments

Comments
 (0)
0