Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 446ced9

Browse filesBrowse files
committed
[Config] Deprecate ArrayNodeDefinition::ignoreExtraKeys in favor of setIgnoreExtraKeys and setRemoveExtraKeys
1 parent c1311c1 commit 446ced9
Copy full SHA for 446ced9

File tree

5 files changed

+66
-5
lines changed
Filter options

5 files changed

+66
-5
lines changed

‎UPGRADE-6.2.md

Copy file name to clipboardExpand all lines: UPGRADE-6.2.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Config
55
------
66

77
* Deprecate calling `NodeBuilder::setParent()` without any arguments
8+
* Deprecate `ArrayNodeDefinition::ignoreExtraKeys()`, use `ArrayNodeDefinition::setIgnoreExtraKeys(true)` and `ArrayNodeDefinition::setRemoveExtraKeys()` instead
89

910
Console
1011
-------

‎src/Symfony/Component/Config/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Deprecate calling `NodeBuilder::setParent()` without any arguments
88
* Add a more accurate typehint in generated PHP config
9+
* Deprecate `ArrayNodeDefinition::ignoreExtraKeys()`, use `ArrayNodeDefinition::setIgnoreExtraKeys(true)` and `ArrayNodeDefinition::setRemoveExtraKeys()` instead
910

1011
6.1
1112
---

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php
+26-2Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,35 @@ public function performNoDeepMerging(): static
305305
* @param bool $remove Whether to remove the extra keys
306306
*
307307
* @return $this
308+
*
309+
* @deprecated since Symfony 6.2, use setIgnoreExtraKeys(true) and setIgnoreExtraKeys() instead
308310
*/
309311
public function ignoreExtraKeys(bool $remove = true): static
310312
{
311-
$this->ignoreExtraKeys = true;
312-
$this->removeExtraKeys = $remove;
313+
trigger_deprecation('symfony/config', '6.2', 'The "%s()" method is deprecated, use "setIgnoreExtraKeys(true)" and "setIgnoreExtraKeys()" instead.', __METHOD__);
314+
315+
$this->setIgnoreExtraKeys(true);
316+
$this->setRemoveExtraKeys($remove);
317+
318+
return $this;
319+
}
320+
321+
/**
322+
* @return $this
323+
*/
324+
public function setIgnoreExtraKeys(bool $ignoreExtraKeys): static
325+
{
326+
$this->ignoreExtraKeys = $ignoreExtraKeys;
327+
328+
return $this;
329+
}
330+
331+
/**
332+
* @return $this
333+
*/
334+
public function setRemoveExtraKeys(bool $removeExtraKeys): static
335+
{
336+
$this->removeExtraKeys = $removeExtraKeys;
313337

314338
return $this;
315339
}

‎src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.php
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,26 @@ public function getConfigTreeBuilder(): TreeBuilder
2323
$rootNode
2424
->children()
2525
->arrayNode('foo')
26-
->ignoreExtraKeys(false)
26+
->setIgnoreExtraKeys(true)
27+
->setRemoveExtraKeys(false)
2728
->children()
2829
->scalarNode('baz')->end()
2930
->scalarNode('qux')->end()
3031
->end()
3132
->end()
3233
->arrayNode('bar')
3334
->prototype('array')
34-
->ignoreExtraKeys(false)
35+
->setIgnoreExtraKeys(true)
36+
->setRemoveExtraKeys(false)
3537
->children()
3638
->scalarNode('corge')->end()
3739
->scalarNode('grault')->end()
3840
->end()
3941
->end()
4042
->end()
4143
->arrayNode('baz')
42-
->ignoreExtraKeys(false)
44+
->setIgnoreExtraKeys(true)
45+
->setRemoveExtraKeys(false)
4346
->end()
4447
;
4548

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Tests\Definition\Builder;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1617
use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition;
1718
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
@@ -23,6 +24,8 @@
2324

2425
class ArrayNodeDefinitionTest extends TestCase
2526
{
27+
use ExpectDeprecationTrait;
28+
2629
public function testAppendingSomeNode()
2730
{
2831
$parent = new ArrayNodeDefinition('root');
@@ -208,18 +211,47 @@ public function testCanBeDisabled()
208211
$this->assertTrue($this->getField($enabledNode, 'defaultValue'));
209212
}
210213

214+
/**
215+
* @group legacy
216+
*/
211217
public function testIgnoreExtraKeys()
212218
{
213219
$node = new ArrayNodeDefinition('root');
214220

215221
$this->assertFalse($this->getField($node, 'ignoreExtraKeys'));
216222

223+
$this->expectDeprecation('Since symfony/config 6.2: The "Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition::ignoreExtraKeys()" method is deprecated, use "setIgnoreExtraKeys(true)" and "setIgnoreExtraKeys()" instead.');
224+
217225
$result = $node->ignoreExtraKeys();
218226

219227
$this->assertEquals($node, $result);
220228
$this->assertTrue($this->getField($node, 'ignoreExtraKeys'));
221229
}
222230

231+
public function testSetIgnoreExtraKeys()
232+
{
233+
$node = new ArrayNodeDefinition('root');
234+
235+
$this->assertFalse($this->getField($node, 'ignoreExtraKeys'));
236+
237+
$result = $node->setIgnoreExtraKeys(true);
238+
239+
$this->assertEquals($node, $result);
240+
$this->assertTrue($this->getField($node, 'ignoreExtraKeys'));
241+
}
242+
243+
public function testSetRemoveExtraKeys()
244+
{
245+
$node = new ArrayNodeDefinition('root');
246+
247+
$this->assertTrue($this->getField($node, 'removeExtraKeys'));
248+
249+
$result = $node->setRemoveExtraKeys(false);
250+
251+
$this->assertEquals($node, $result);
252+
$this->assertFalse($this->getField($node, 'removeExtraKeys'));
253+
}
254+
223255
public function testNormalizeKeys()
224256
{
225257
$node = new ArrayNodeDefinition('root');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.