8000 #20921 [Config] Provide shorthand methods for ArrayNodeDefinition::pr… · skafandri/symfony@c7d0fea · GitHub
[go: up one dir, main page]

Skip to content

Commit c7d0fea

Browse files
committed
symfony#20921 [Config] Provide shorthand methods for ArrayNodeDefinition::prototype()
1 parent e98c068 commit c7d0fea

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,69 @@ public function prototype($type)
7979
return $this->prototype = $this->getNodeBuilder()->node(null, $type)->setParent($this);
8080
}
8181

82+
/**
83+
* Shorthand for prototype('variable')
84+
* @return VariableNodeDefinition
85+
*/
86+
public function prototypeVariable()
87+
{
88+
return $this->prototype('variable');
89+
}
90+
91+
/**
92+
* Shorthand for prototype('scalar')
93+
* @return ScalarNodeDefinition
94+
*/
95+
public function prototypeScalar()
96+
{
97+
return $this->prototype('scalar');
98+
}
99+
100+
/**
101+
* Shorthand for prototype('boolean')
102+
* @return BooleanNodeDefinition
103+
*/
104+
public function prototypeBoolean()
105+
{
106+
return $this->prototype('boolean');
107+
}
108+
109+
/**
110+
* Shorthand for prototype('integer')
111+
* @return IntegerNodeDefinition
112+
*/
113+
public function prototypeInteger()
114+
{
115+
return $this->prototype('integer');
116+
}
117+
118+
/**
119+
* Shorthand for prototype('float')
120+
* @return FloatNodeDefinition
121+
*/
122+
public function prototypeFloat()
123+
{
124+
return $this->prototype('float');
125+
}
126+
127+
/**
128+
* Shorthand for prototype('array')
129+
* @return ArrayNodeDefinition
130+
*/
131+
public function prototypeArray()
132+
{
133+
return $this->prototype('array');
134+
}
135+
136+
/**
137+
* Shorthand for prototype('enum')
138+
* @return EnumNodeDefinition
139+
*/
140+
public function prototypeEnum()
141+
{
142+
return $this->prototype('enum');
143+
}
144+
82145
/**
83146
* Adds the default value if the node is not set in the configuration.
84147
*

src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,48 @@ public function testNormalizeKeys()
227227
$this->assertFalse($this->getField($node, 'normalizeKeys'));
228228
}
229229

230+
public function testPrototypeVariable()
231+
{
232+
$node = new ArrayNodeDefinition('root');
233+
$this->assertEquals($node->prototype('variable'), $node->prototypeVariable());
234+
}
235+
236+
public function testPrototypeScalar()
237+
{
238+
$node = new ArrayNodeDefinition('root');
239+
$this->assertEquals($node->prototype('scalar'), $node->prototypeScalar());
240+
}
241+
242+
public function testPrototypeBoolean()
243+
{
244+
$node = new ArrayNodeDefinition('root');
245+
$this->assertEquals($node->prototype('boolean'), $node->prototypeBoolean());
246+
}
247+
248+
public function testPrototypeInteger()
249+
{
250+
$node = new ArrayNodeDefinition('root');
251+
$this->assertEquals($node->prototype('integer'), $node->prototypeInteger());
252+
}
253+
254+
public function testPrototypeFloat()
255+
{
256+
$node = new ArrayNodeDefinition('root');
257+
$this->assertEquals($node->prototype('float'), $node->prototypeFloat());
258+
}
259+
260+
public function testPrototypeArray()
261+
{
262+
$node = new ArrayNodeDefinition('root');
263+
$this->assertEquals($node->prototype('array'), $node->prototypeArray());
264+
}
265+
266+
public function testPrototypeEnum()
267+
{
268+
$node = new ArrayNodeDefinition('root');
269+
$this->assertEquals($node->prototype('enum'), $node->prototypeEnum());
270+
}
271+
230272
public function getEnableableNodeFixtures()
231273
{
232274
return array(

0 commit comments

Comments
 (0)
0