Skip to content

Commit a4d278d

Browse files
committed
[Config] Use callable instead of closure in naming
Replace references to closures in function, property and parameter names in preparation of future callable support.
1 parent 862bdf1 commit a4d278d

File tree

5 files changed

+66
-17
lines changed

5 files changed

+66
-17
lines changed

UPGRADE-2.8.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
UPGRADE FROM 2.7 to 2.8
2+
=======================
3+
4+
Config
5+
------
6+
7+
* The methods `setNormalizationClosures()` and `setFinalValidationClosures()` in
8+
`BaseNode` were deprecated, `setNormalizationCallbacks()` and
9+
`setFinalValidationCallbacks()` should be used instead.
10+
11+
* The protected properties `normalizationClosures` and `finalValidationClosures` in
12+
`BaseNode` were renamed to `normalizationCallbacks` and `finalValidationCallbacks`.

src/Symfony/Component/Config/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
CHANGELOG
22
=========
33

4+
2.8.0
5+
-----
6+
7+
* [BC BREAK] The protected properties `normalizationClosures` and `finalValidationClosures` in
8+
`BaseNode` were renamed to `normalizationCallbacks` and `finalValidationCallbacks`.
9+
* [DEPRECATION] The methods `setNormalizationClosures()` and `setFinalValidationClosures()` in
10+
`BaseNode` were deprecated, `setNormalizationCallbacks()` and `setFinalValidationCallbacks()`
11+
should be used instead.
12+
413
2.7.0
514
-----
615

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

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ abstract class BaseNode implements NodeInterface
2525
{
2626
protected $name;
2727
protected $parent;
28-
protected $normalizationClosures = array();
29-
protected $finalValidationClosures = array();
28+
protected $normalizationCallbacks = array();
29+
protected $finalValidationCallbacks = array();
3030
protected $allowOverwrite = true;
3131
protected $required = false;
3232
protected $equivalentValues = array();
@@ -151,24 +151,52 @@ public function setAllowOverwrite($allow)
151151
$this->allowOverwrite = (bool) $allow;
152152
}
153153

154+
/**
155+
* Sets the callbacks used for normalization.
156+
*
157+
* @param callable[] $callbacks An array of callbacks used for normalization
158+
*/
159+
public function setNormalizationCallbacks(array $callbacks)
160+
{
161+
$this->normalizationCallbacks = $callbacks;
162+
}
163+
154164
/**
155165
* Sets the closures used for normalization.
156166
*
157167
* @param \Closure[] $closures An array of Closures used for normalization
168+
*
169+
* @deprecated since version 2.8, to be removed in 3.0. Use setNormalizationCallbacks() instead
158170
*/
159171
public function setNormalizationClosures(array $closures)
160172
{
161-
$this->normalizationClosures = $closures;
173+
trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the setNormalizationCallbacks() method instead.', E_USER_DEPRECATED);
174+
175+
$this->normalizationCallbacks = $closures;
176+
}
177+
178+
/**
179+
* Sets the callbacks used for final validation.
180+
*
181+
* @param callable[] $callbacks An array of callbacks used for final validation
182+
*/
183+
public function setFinalValidationCallbacks(array $callbacks)
184+
{
185+
$this->finalValidationCallbacks = $callbacks;
162186
}
163187

164188
/**
165189
* Sets the closures used for final validation.
166190
*
167191
* @param \Closure[] $closures An array of Closures used for final validation
192+
*
193+
* @deprecated since version 2.8, to be removed in 3.0. Use setFinalValidationCallbacks() instead
168194
*/
169195
public function setFinalValidationClosures(array $closures)
170196
{
171-
$this->finalValidationClosures = $closures;
197+
trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the setFinalValidationCallbacks() method instead.', E_USER_DEPRECATED);
198+
199+
$this->finalValidationCallbacks = $closures;
172200
}
173201

174202
/**
@@ -235,7 +263,7 @@ final public function merge($leftSide, $rightSide)
235263
}
236264

237265
/**
238-
* Normalizes a value, applying all normalization closures.
266+
* Normalizes a value, applying all normalization callbacks.
239267
*
240268
* @param mixed $value Value to normalize.
241269
*
@@ -245,9 +273,9 @@ final public function normalize($value)
245273
{
246274
$value = $this->preNormalize($value);
247275

248-
// run custom normalization closures
249-
foreach ($this->normalizationClosures as $closure) {
250-
$value = $closure($value);
276+
// run custom normalization callbacks
277+
foreach ($this->normalizationCallbacks as $callback) {
278+
$value = call_user_func($callback, $value);
251279
}
252280

253281
// replace value with their equivalent
@@ -287,7 +315,7 @@ public function getParent()
287315
}
288316

289317
/**
290-
* Finalizes a value, applying all finalization closures.
318+
* Finalizes a value, applying all finalization callbacks.
291319
*
292320
* @param mixed $value The value to finalize
293321
*
@@ -302,11 +330,11 @@ final public function finalize($value)
302330

303331
$value = $this->finalizeValue($value);
304332

305-
// Perform validation on the final value if a closure has been set.
306-
// The closure is also allowed to return another value.
307-
foreach ($this->finalValidationClosures as $closure) {
333+
// Perform validation on the final value if a callback has been set.
334+
// The callback is also allowed to return another value.
335+
foreach ($this->finalValidationCallbacks as $callback) {
308336
try {
309-
$value = $closure($value);
337+
$value = call_user_func($callback, $value);
310338
} catch (Exception $correctEx) {
311339
throw $correctEx;
312340
} catch (\Exception $invalid) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ protected function createNode()
397397
$node->setNormalizeKeys($this->normalizeKeys);
398398

399399
if (null !== $this->normalization) {
400-
$node->setNormalizationClosures($this->normalization->before);
400+
$node->setNormalizationCallbacks($this->normalization->before);
401401
$node->setXmlRemappings($this->normalization->remappings);
402402
}
403403

@@ -407,7 +407,7 @@ protected function createNode()
407407
}
408408

409409
if (null !== $this->validation) {
410-
$node->setFinalValidationClosures($this->validation->rules);
410+
$node->setFinalValidationCallbacks($this->validation->rules);
411411
}
412412

413413
return $node;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function createNode()
3838
$node = $this->instantiateNode();
3939

4040
if (null !== $this->normalization) {
41-
$node->setNormalizationClosures($this->normalization->before);
41+
$node->setNormalizationCallbacks($this->normalization->before);
4242
}
4343

4444
if (null !== $this->merge) {
@@ -56,7 +56,7 @@ protected function createNode()
5656
$node->setRequired($this->required);
5757

5858
if (null !== $this->validation) {
59-
$node->setFinalValidationClosures($this->validation->rules);
59+
$node->setFinalValidationCallbacks($this->validation->rules);
6060
}
6161

6262
return $node;

0 commit comments

Comments
 (0)