8000 [PropertyAccess] Allow to disable exception on invalid property path … · sroze/symfony@c336696 · GitHub
[go: up one dir, main page]

Skip to content

Commit c336696

Browse files
dimaboryRobin Chalas
authored andcommitted
[PropertyAccess] Allow to disable exception on invalid property path when using PropertyAccess::getValue()
1 parent fe7363f commit c336696

File tree

14 files changed

+98
-10
lines changed

14 files changed

+98
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CHANGELOG
3030
* Added support for boolean container parameters within routes.
3131
* Added the `messenger:setup-transports` command to setup messenger transports
3232
* Added a `InMemoryTransport` to Messenger. Use it with a DSN starting with `in-memory://`.
33+
* Added `framework.property_access.throw_exception_on_invalid_property_path` config option.
3334

3435
4.2.0
3536
-----

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ private function addPropertyAccessSection(ArrayNodeDefinition $rootNode)
903903
->children()
904904
->booleanNode('magic_call')->defaultFalse()->end()
905905
->booleanNode('throw_exception_on_invalid_index')->defaultFalse()->end()
906+
->booleanNode('throw_exception_on_invalid_property_path')->defaultTrue()->end()
906907
->end()
907908
->end()
908909
->end()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,7 @@ private function registerPropertyAccessConfiguration(array $config, ContainerBui
13611361
->getDefinition('property_accessor')
13621362
->replaceArgument(0, $config['magic_call'])
13631363
->replaceArgument(1, $config['throw_exception_on_invalid_index'])
1364+
->replaceArgument(3, $config['throw_exception_on_invalid_property_path'])
13641365
;
13651366
}
13661367

src/Symfony/Bundle/FrameworkBundle/Resources/config/property_access.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<argument /> <!-- magicCall, set by the extension -->
1212
<argument /> <!-- throwExceptionOnInvalidIndex, set by the extension -->
1313
<argument type="service" id="cache.property_access" on-invalid="ignore" />
14+
<argument /> <!-- throwExceptionOnInvalidPropertyPath, set by the extension -->
1415
</service>
1516
<service id="Symfony\Component\PropertyAccess\PropertyAccessorInterface" alias="property_accessor" />
1617
</services>

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
<xsd:complexType name="property_access">
234234
<xsd:attribute name="magic-call" type="xsd:boolean" />
235235
<xsd:attribute name="throw-exception-on-invalid-index" type="xsd:boolean" />
236+
<xsd:attribute name="throw-exception-on-invalid-property-path" type="xsd:boolean" />
236237
</xsd:complexType>
237238

238239
<xsd:complexType name="serializer">

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ protected static function getBundleDefaultConfig()
249249
'property_access' => [
250250
'magic_call' => false,
251251
'throw_exception_on_invalid_index' => false,
252+
'throw_exception_on_invalid_property_path' => true,
252253
],
253254
'property_info' => [
254255
'enabled' => !class_exists(FullStack::class),

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/property_accessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
'property_access' => [
55
'magic_call' => true,
66
'throw_exception_on_invalid_index' => true,
7+
'throw_exception_on_invalid_property_path' => false,
78
],
89
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/property_accessor.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
88

99
<framework:config>
10-
<framework:property-access magic-call="true" throw-exception-on-invalid-index="true" />
10+
<framework:property-access magic-call="true" throw-exception-on-invalid-index="true" throw-exception-on-invalid-property-path="false"/>
1111
</framework:config>
1212
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/property_accessor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ framework:
22
property_access:
33
magic_call: true
44
throw_exception_on_invalid_index: true
5+
throw_exception_on_invalid_property_path: false

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function testPropertyAccessWithDefaultValue()
8080
$def = $container->getDefinition('property_accessor');
8181
$this->assertFalse($def->getArgument(0));
8282
$this->assertFalse($def->getArgument(1));
83+
$this->assertTrue($def->getArgument(3));
8384
}
8485

8586
public function testPropertyAccessWithOverriddenValues()
@@ -88,6 +89,7 @@ public function testPropertyAccessWithOverriddenValues()
8889
$def = $container->getDefinition('property_accessor');
8990
$this->assertTrue($def->getArgument(0));
9091
$this->assertTrue($def->getArgument(1));
92+
$this->assertFalse($def->getArgument(3));
9193
}
9294

9395
public function testPropertyAccessCache()

0 commit comments

Comments
 (0)
0