Skip to content

Commit 792c4b5

Browse files
committed
[FrameworkBundle] Expose configuration of PropertyAccess
1 parent 2221268 commit 792c4b5

File tree

10 files changed

+85
-2
lines changed

10 files changed

+85
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* Added `Controller::isCsrfTokenValid` helper
8+
* Added configuration for the PropertyAccess component
89

910
2.5.0
1011
-----

DependencyInjection/Configuration.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function getConfigTreeBuilder()
9292
$this->addValidationSection($rootNode);
9393
$this->addAnnotationsSection($rootNode);
9494
$this->addSerializerSection($rootNode);
95+
$this->addPropertyAccessSection($rootNode);
9596

9697
return $treeBuilder;
9798
}
@@ -524,4 +525,20 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode)
524525
->end()
525526
;
526527
}
528+
529+
private function addPropertyAccessSection(ArrayNodeDefinition $rootNode)
530+
{
531+
$rootNode
532+
->children()
533+
->arrayNode('property_access')
534+
->addDefaultsIfNotSet()
535+
->info('Property access configuration')
536+
->children()
537+
->booleanNode('magic_call')->defaultFalse()->end()
538+
->booleanNode('throw_exception_on_invalid_index')->defaultFalse()->end()
539+
->end()
540+
->end()
541+
->end()
542+
;
543+
}
527544
}

DependencyInjection/FrameworkExtension.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public function load(array $configs, ContainerBuilder $container)
133133

134134
$this->registerAnnotationsConfiguration($config['annotations'], $container, $loader);
135135

136+
$this->registerPropertyAccessConfiguration($config['property_access'], $container);
137+
136138
if (isset($config['serializer']) && $config['serializer']['enabled']) {
137139
$loader->load('serializer.xml');
138140
}
@@ -818,6 +820,15 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
818820
}
819821
}
820822

823+
private function registerPropertyAccessConfiguration(array $config, ContainerBuilder $container)
824+
{
825+
$container
826+
->getDefinition('property_accessor')
827+
->replaceArgument(0, $config['magic_call'])
828+
->replaceArgument(1, $config['throw_exception_on_invalid_index'])
829+
;
830+
}
831+
821832
/**
822833
* Loads the security configuration.
823834
*

Resources/config/property_access.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</parameters>
1010

1111
<services>
12-
<service id="property_accessor" class="%property_accessor.class%" />
12+
<service id="property_accessor" class="%property_accessor.class%" >
13+
<argument /> <!-- magicCall, set by the extension -->
14+
<argument /> <!-- throwExceptionOnInvalidIndex, set by the extension -->
15+
</service>
1316
</services>
1417
</container>

Resources/config/schema/symfony-1.0.xsd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<xsd:element name="translator" type="translator" minOccurs="0" maxOccurs="1" />
3131
<xsd:element name="validation" type="validation" minOccurs="0" maxOccurs="1" />
3232
<xsd:element name="annotations" type="annotations" minOccurs="0" maxOccurs="1" />
33+
<xsd:element name="property-access" type="property_access" minOccurs="0" maxOccurs="1" />
3334
</xsd:all>
3435

3536
<xsd:attribute name="http-method-override" type="xsd:boolean" />
@@ -177,4 +178,9 @@
177178
<xsd:attribute name="debug" type="xsd:string" />
178179
<xsd:attribute name="file-cache-dir" type="xsd:string" />
179180
</xsd:complexType>
181+
182+
<xsd:complexType name="property_access">
183+
<xsd:attribute name="magic-call" type="xsd:boolean" />
184+
<xsd:attribute name="throw-exception-on-invalid-index" type="xsd:boolean" />
185+
</xsd:complexType>
180186
</xsd:schema>

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ protected static function getBundleDefaultConfig()
139139
),
140140
'serializer' => array(
141141
'enabled' => false
142-
)
142+
),
143+
'property_access' => array(
144+
'magic_call' => false,
145+
'throw_exception_on_invalid_index' => false,
146+
),
143147
);
144148
}
145149
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'property_access' => array(
5+
'magic_call' => true,
6+
'throw_exception_on_invalid_index' => true,
7+
),
8+
));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:property-access magic-call="true" throw-exception-on-invalid-index="true" />
11+
</framework:config>
12+
</container>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
property_access:
3+
magic_call: true
4+
throw_exception_on_invalid_index: true

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ public function testCsrfProtection()
3434
$this->assertEquals('%form.type_extension.csrf.field_name%', $def->getArgument(2));
3535
}
3636

37+
public function testPropertyAccessWithDefaultValue()
38+
{
39+
$container = $this->createContainerFromFile('full');
40+
41+
$def = $container->getDefinition('property_accessor');
42+
$this->assertEquals(false, $def->getArgument(0));
43+
$this->assertEquals(false, $def->getArgument(1));
44+
}
45+
46+
public function testPropertyAccessWithOverriddenValues()
47+
{
48+
$container = $this->createContainerFromFile('property_accessor');
49+
$def = $container->getDefinition('property_accessor');
50+
$this->assertEquals(true, $def->getArgument(0));
51+
$this->assertEquals(true, $def->getArgument(1));
52+
}
53+
3754
/**
3855
* @expectedException \LogicException
3956
* @expectedExceptionMessage CSRF protection needs sessions to be enabled.

0 commit comments

Comments
 (0)