Skip to content

Commit 4f57d71

Browse files
committed
use bitwise flags to configure when the property accessor should throw
1 parent 332570f commit 4f57d71

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,13 +1573,16 @@ private function registerPropertyAccessConfiguration(array $config, ContainerBui
15731573
$magicMethods |= $config['magic_get'] ? PropertyAccessor::MAGIC_GET : 0;
15741574
$magicMethods |= $config['magic_set'] ? PropertyAccessor::MAGIC_SET : 0;
15751575

1576+
$throw = PropertyAccessor::DO_NOT_THROW;
1577+
$throw |= $config['throw_exception_on_invalid_index'] ? PropertyAccessor::THROW_ON_INVALID_INDEX : 0;
1578+
$throw |= $config['throw_exception_on_invalid_property_path'] ? PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH : 0;
1579+
15761580
$container
15771581
->getDefinition('property_accessor')
15781582
->replaceArgument(0, $magicMethods)
1579-
->replaceArgument(1, $config['throw_exception_on_invalid_index'])
1580-
->replaceArgument(3, $config['throw_exception_on_invalid_property_path'])
1581-
->replaceArgument(4, new Reference(PropertyReadInfoExtractorInterface::class, ContainerInterface::NULL_ON_INVALID_REFERENCE))
1582-
->replaceArgument(5, new Reference(PropertyWriteInfoExtractorInterface::class, ContainerInterface::NULL_ON_INVALID_REFERENCE))
1583+
->replaceArgument(1, $throw)
1584+
->replaceArgument(3, new Reference(PropertyReadInfoExtractorInterface::class, ContainerInterface::NULL_ON_INVALID_REFERENCE))
1585+
->replaceArgument(4, new Reference(PropertyWriteInfoExtractorInterface::class, ContainerInterface::NULL_ON_INVALID_REFERENCE))
15831586
;
15841587
}
15851588

Resources/config/property_access.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
->set('property_accessor', PropertyAccessor::class)
2020
->args([
2121
abstract_arg('magic methods allowed, set by the extension'),
22-
abstract_arg('throwExceptionOnInvalidIndex, set by the extension'),
22+
abstract_arg('throw exceptions, set by the extension'),
2323
service('cache.property_access')->ignoreOnInvalid(),
24-
abstract_arg('throwExceptionOnInvalidPropertyPath, set by the extension'),
2524
abstract_arg('propertyReadInfoExtractor, set by the extension'),
2625
abstract_arg('propertyWriteInfoExtractor, set by the extension'),
2726
])

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,15 @@ public function testPropertyAccessWithDefaultValue()
100100

101101
$def = $container->getDefinition('property_accessor');
102102
$this->assertSame(PropertyAccessor::MAGIC_SET | PropertyAccessor::MAGIC_GET, $def->getArgument(0));
103-
$this->assertFalse($def->getArgument(1));
104-
$this->assertTrue($def->getArgument(3));
103+
$this->assertSame(PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH, $def->getArgument(1));
105104
}
106105

107106
public function testPropertyAccessWithOverriddenValues()
108107
{
109108
$container = $this->createContainerFromFile('property_accessor');
110109
$def = $container->getDefinition('property_accessor');
111110
$this->assertSame(PropertyAccessor::MAGIC_GET | PropertyAccessor::MAGIC_CALL, $def->getArgument(0));
112-
$this->assertTrue($def->getArgument(1));
113-
$this->assertFalse($def->getArgument(3));
111+
$this->assertSame(PropertyAccessor::THROW_ON_INVALID_INDEX, $def->getArgument(1));
114112
}
115113

116114
public function testPropertyAccessCache()

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"symfony/messenger": "<4.4",
8585
"symfony/mime": "<4.4",
8686
"symfony/property-info": "<4.4",
87-
"symfony/property-access": "<5.2",
87+
"symfony/property-access": "<5.3",
8888
"symfony/serializer": "<5.2",
8989
"symfony/security-csrf": "<5.3",
9090
"symfony/security-core": "<5.3",

0 commit comments

Comments
 (0)