8000 bug #24025 Use new configuration depreciation method (sanpii, chalasr) · symfony/symfony@c9bee84 · GitHub
[go: up one dir, main page]

Skip to content

Commit c9bee84

Browse files
bug #24025 Use new configuration depreciation method (sanpii, chalasr)
This PR was merged into the 3.4 branch. Discussion ---------- Use new configuration depreciation method | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | N/A | License | MIT | Doc PR | N/A In keeping with #22382 Commits ------- 4a62cc6 Do not trigger deprecation if node has not been explicitly filled 012e381 Use new configuration node depreciation method
2 parents 86c3a50 + 4a62cc6 commit c9bee84

File tree

7 files changed

+65
-25
lines changed

7 files changed

+65
-25
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ public function getConfigTreeBuilder()
6666
->defaultTrue()
6767
->end()
6868
->arrayNode('trusted_proxies')
69+
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.')
6970
->beforeNormalization()
7071
->ifTrue(function ($v) {
71-
@trigger_error('The "framework.trusted_proxies" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.', E_USER_DEPRECATED);
72-
7372
return !is_array($v) && null !== $v;
7473
})
7574
->then(function ($v) { return is_bool($v) ? array() : preg_split('/\s*,\s*/', $v); })
@@ -663,8 +662,9 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
663662
->{!class_exists(FullStack::class) && class_exists(Validation::class) ? 'canBeDisabled' : 'canBeEnabled'}()
664663
->children()
665664
->scalarNode('cache')
665+
// Can be removed in 4.0, when validator.mapping.cache.doctrine.apc is removed
666+
->setDeprecated('The "%path%.%node%" option is deprecated since Symfony 3.2 and will be removed in 4.0. Configure the "cache.validator" service under "framework.cache.pools" instead.')
666667
->beforeNormalization()
667-
// Can be removed in 4.0, when validator.mapping.cache.doctrine.apc is removed
668668
->ifString()->then(function ($v) {
669669
if ('validator.mapping.cache.doctrine.apc' === $v && !class_exists('Doctrine\Common\Cache\ApcCache')) {
670670
throw new LogicException('Doctrine APC cache for the validator cannot be enabled as the Doctrine Cache package is not installed.');
@@ -727,7 +727,9 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode)
727727
->{!class_exists(FullStack::class) && class_exists(Serializer::class) ? 'canBeDisabled' : 'canBeEnabled'}()
728728
->children()
729729
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) && class_exists(Annotation::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
730-
->scalarNode('cache')->end()
730+
->scalarNode('cache')
731+
->setDeprecated('The "%path%.%node%" option is deprecated since Symfony 3.1 and will be removed in 4.0. Configure the "cache.serializer" service under "framework.cache.pools" instead.')
732+
->end()
731733
->scalarNode('name_converter')->end()
732734
->scalarNode('circular_reference_handler')->end()
733735
->arrayNode('mapping')

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,6 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
11981198
}
11991199

12001200
if (isset($config['cache']) && $config['cache']) {
1201-
@trigger_error('The "framework.validation.cache" option is deprecated since Symfony 3.2 and will be removed in 4.0. Configure the "cache.validator" service under "framework.cache.pools" instead.', E_USER_DEPRECATED);
1202-
12031201
$container->setParameter(
12041202
'validator.mapping.cache.prefix',
12051203
'validator_'.$this->getKernelRootHash($container)
@@ -1454,8 +1452,6 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
14541452
$container->getDefinition('serializer.mapping.cache_warmer')->replaceArgument(0, $serializerLoaders);
14551453

14561454
if (isset($config['cache']) && $config['cache']) {
1457-
@trigger_error('The "framework.serializer.cache" option is deprecated since Symfony 3.1 and will be removed in 4.0. Configure the "cache.serializer" service under "framework.cache.pools" instead.', E_USER_DEPRECATED);
1458-
14591455
$container->setParameter(
14601456
'serializer.mapping.cache.prefix',
14611457
'serializer_'.$this->getKernelRootHash($container)

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"symfony/cache": "~3.4|~4.0",
2222
"symfony/class-loader": "~3.2",
2323
"symfony/dependency-injection": "~3.4|~4.0",
24-
"symfony/config": "~3.3|~4.0",
24+
"symfony/config": "~3.4|~4.0",
2525
"symfony/event-dispatcher": "^3.3.1|~4.0",
2626
"symfony/http-foundation": "~3.3|~4.0",
2727
"symfony/http-kernel": "~3.4|~4.0",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,6 @@ protected function finalizeValue($value)
234234
}
235235

236236
foreach ($this->children as $name => $child) {
237-
if ($child->isDeprecated()) {
238-
@trigger_error($child->getDeprecationMessage($name, $this->getPath()), E_USER_DEPRECATED);
239-
}
240-
241237
if (!array_key_exists($name, $value)) {
242238
if ($child->isRequired()) {
243239
$msg = sprintf('The child node "%s" at path "%s" must be configured.', $name, $this->getPath());
@@ -254,6 +250,10 @@ protected function finalizeValue($value)
254250
continue;
255251
}
256252

253+
if ($child->isDeprecated()) {
254+
@trigger_error($child->getDeprecationMessage($name, $this->getPath()), E_USER_DEPRECATED);
255+
}
256+
257257
try {
258258
$value[$name] = $child->finalize($value[$name]);
259259
} catch (UnsetKeyException $e) {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ protected function validateType($value)
8484
*/
8585
protected function finalizeValue($value)
8686
{
87-
if ($this->deprecationMessage) {
88-
@trigger_error($this->getDeprecationMessage($this->getName(), $this->getPath()), E_USER_DEPRECATED);
89-
}
90-
9187
if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {
9288
$ex = new InvalidConfigurationException(sprintf(
9389
'The path "%s" cannot contain an empty value, but got %s.',

src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,33 @@ public function testGetDefaultValueWithoutDefaultValue()
219219

220220
public function testSetDeprecated()
221221
{
222-
$node = new ArrayNode('foo');
223-
$node->setDeprecated('"%node%" is deprecated');
222+
$childNode = new ArrayNode('foo');
223+
$childNode->setDeprecated('"%node%" is deprecated');
224+
225+
$this->assertTrue($childNode->isDeprecated());
226+
$this->assertSame('"foo" is deprecated', $childNode->getDeprecationMessage($childNode->getName(), $childNode->getPath()));
227+
228+
$node = new ArrayNode('root');
229+
$node->addChild($childNode);
230+
231+
$deprecationTriggered = false;
232+
$deprecationHandler = function ($level, $message, $file, $line) use (&$prevErrorHandler, &$deprecationTriggered) {
233+
if (E_USER_DEPRECATED === $level) {
234+
return $deprecationTriggered = true;
235+
}
236+
237+
return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
238+
};
239+
240+
$prevErrorHandler = set_error_handler($deprecationHandler);
241+
$node->finalize(array());
242+
restore_error_handler();
243+
244+
$this->assertFalse($deprecationTriggered, '->finalize() should not trigger if the deprecated node is not set');
224245

225-
$this->assertTrue($node->isDeprecated());
226-
$this->assertSame('"foo" is deprecated', $node->getDeprecationMessage($node->getName(), $node->getPath()));
246+
$prevErrorHandler = set_error_handler($deprecationHandler);
247+
$node->finalize(array('foo' => array()));
248+
restore_error_handler();
249+
$this->assertTrue($deprecationTriggered, '->finalize() should trigger if the deprecated node is set');
227250
}
228251
}

src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Tests\Definition;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Config\Definition\ArrayNode;
1516
use Symfony\Component\Config\Definition\ScalarNode;
1617

1718
class ScalarNodeTest extends TestCase
@@ -42,11 +43,33 @@ public function getValidValues()
4243

4344
public function testSetDeprecated()
4445
{
45-
$node = new ScalarNode('foo');
46-
$node->setDeprecated('"%node%" is deprecated');
46+
$childNode = new ScalarNode('foo');
47+
$childNode->setDeprecated('"%node%" is deprecated');
4748

48-
$this->assertTrue($node->isDeprecated());
49-
$this->assertSame('"foo" is deprecated', $node->getDeprecationMessage($node->getName(), $node->getPath()));
49+
$this->assertTrue($childNode->isDeprecated());
50+
$this->assertSame('"foo" is deprecated', $childNode->getDeprecationMessage($childNode->getName(), $childNode->getPath()));
51+
52+
$node = new ArrayNode('root');
53+
$node->addChild($childNode);
54+
55+
$deprecationTriggered = 0;
56+
$deprecationHandler = function ($level, $message, $file, $line) use (&$prevErrorHandler, &$deprecationTriggered) {
57+
if (E_USER_DEPRECATED === $level) {
58+
return ++$deprecationTriggered;
59+
}
60+
61+
return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
62+
};
63+
64+
$prevErrorHandler = set_error_handler($deprecationHandler);
65+
$node->finalize(array());
66+
restore_error_handler();
67+
$this->assertSame(0, $deprecationTriggered, '->finalize() should not trigger if the deprecated node is not set');
68+
69+
$prevErrorHandler = set_error_handler($deprecationHandler);
70+
$node->finalize(array('foo' => ''));
71+
restore_error_handler();
72+
$this->assertSame(1, $deprecationTriggered, '->finalize() should trigger if the deprecated node is set');
5073
}
5174

5275
/**

0 commit comments

Comments
 (0)
0