8000 Added MetadataLoader to PropertyAccess configuration registration · symfony/symfony@7fcdcd8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fcdcd8

Browse files
committed
Added MetadataLoader to PropertyAccess configuration registration
1 parent f6dd635 commit 7fcdcd8

File tree

8 files changed

+67
-1
lines changed

8 files changed

+67
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ CHANGELOG
5959
and `YamlLintCommand` classes have been marked as final
6060
* Added `asset.request_context.base_path` and `asset.request_context.secure` parameters
6161
to provide a default request context in case the stack is empty (similar to `router.request_context.*` parameters)
62+
* Added custom property accessors support
6263

6364
3.3.0
6465
-----

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,16 @@ private function addPropertyAccessSection(ArrayNodeDefinition $rootNode)
786786
->children()
787787
->booleanNode('magic_call')->defaultFalse()->end()
788788
->booleanNode('throw_exception_on_invalid_index')->defaultFalse()->end()
789-
->end()
789+
->booleanNode('enable_annotations')->defaultFalse()->end()
790+
->arrayNode('mapping')
791+
->addDefaultsIfNotSet()
792+
->fixXmlConfig('path')
793+
->children()
794+
->arrayNode('paths')
795+
->prototype('scalar')->end()
796+
->end()
797+
->end()
798+
->end()
790799
->end()
791800
->end()
792801
;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,33 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
15011501

15021502
private function registerPropertyAccessConfiguration(array $config, ContainerBuilder $container)
15031503
{
1504+
$loaders = array();
1505+
$fileRecorder = function ($extension, $path) use (&$loaders) {
1506+
$definition = new Definition(in_array($extension, array('yaml', 'yml')) ? 'Symfony\Component\PropertyAccess\Mapping\Loader\YamlFileLoader' : 'Symfony\Component\PropertyAccess\Mapping\Loader\XmlFileLoader', array($path));
1507+
$definition->setPublic(false);
1508+
$loaders[] = $definition;
1509+
};
1510+
1511+
if (isset($config['enable_annotations']) && $config['enable_annotations']) {
1512+
if (!$this->annotationsConfigEnabled) {
1513+
throw new \LogicException('"enable_annotations" on property access cannot be set as Annotations support is disabled.');
1514+
}
1515+
$annotationLoader = new Definition(
1516+
'Symfony\Component\PropertyAccess\Mapping\Loader\AnnotationLoader',
1517+
array(new Reference('annotation_reader'))
1518+
);
1519+
$annotationLoader->setPublic(false);
1520+
$loaders[] = $annotationLoader;
1521+
}
1522+
1523+
$this->registerComponentMapping($container, $fileRecorder, 'property_accessor');
1524+
1525+
$this->registerMappingFilesFromConfig($container, $config, $fileRecorder);
1526+
1527+
$chainLoader = $container->getDefinition('property_access.mapping.chain_loader');
1528+
1529+
$chainLoader->replaceArgument(0, $loaders);
1530+
15041531
$container
15051532
->getDefinition('property_accessor')
15061533
->replaceArgument(0, $config['magic_call'])

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@
77
<services>
88
<defaults public="false" />
99

10+
<!-- Loader -->
11+
<service id="property_access.mapping.chain_loader" class="Symfony\Component\PropertyAccess\Mapping\Loader\LoaderChain">
12+
<argument type="collection" />
13+
</service>
14+
15+
<!-- Class Metadata Factory -->
16+
<service id="property_access.mapping.class_metadata_factory" class="Symfony\Component\PropertyAccess\Mapping\Factory\LazyLoadingMetadataFactory">
17+
<argument type="service" id="property_access.mapping.chain_loader" />
18+
</service>
19+
1020
<service id="property_accessor" class="Symfony\Component\PropertyAccess\PropertyAccessor">
1121
<argument /> <!-- magicCall, set by the extension -->
1222
<argument /> <!-- throwExceptionOnInvalidIndex, set by the extension -->
1323
<argument type="service" id="cache.property_access" on-invalid="ignore" />
24+
<argument type="service" id="property_access.mapping.class_metadata_factory" on-invalid="ignore" />
1425
</service>
1526
<service id="Symfony\Component\PropertyAccess\PropertyAccessorInterface" alias="property_accessor" />
1627
</services>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ protected static function getBundleDefaultConfig()
283283
'property_access' => array(
284284
'magic_call' => false,
285285
'throw_exception_on_invalid_index' => false,
286+
'enable_annotations' => false,
287+
'mapping' => array(
288+
'paths' => array(),
289+
),
286290
),
287291
'property_info' => array(
288292
'enabled' => false,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@
6464
'debug' => true,
6565
'file_cache_dir' => '%kernel.cache_dir%/annotations',
6666
),
67+
'property_access' => array(
68+
'magic_call' => false,
69+
'throw_exception_on_invalid_index' => false,
70+
'enable_annotations' => true,
71+
),
6772
'serializer' => array(
6873
'enabled' => true,
6974
'enable_annotations' => true,

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' => array(
55
'magic_call' => true,
66
'throw_exception_on_invalid_index' => true,
7+
'enable_annotations' => true,
78
),
89
));

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
"homepage": "https://symfony.com/contributors"
1616
}
1717
],
18+
"repositories": [
19+
{
20+
"type": "git",
21+
"url": "https://github.com/lrlopez/property-access"
22+
}
23+
],
1824
"require": {
1925
"php": "^5.5.9|>=7.0.8",
2026
"ext-xml": "*",
@@ -35,6 +41,7 @@
3541
"fig/link-util": "^1.0",
3642
"symfony/asset": "~3.3|~4.0",
3743
"symfony/browser-kit": "~2.8|~3.0|~4.0",
44+
"symfony/cache": "~3.4|~4.0",
3845
"symfony/console": "~3.4|~4.0",
3946
"symfony/css-selector": "~2.8|~3.0|~4.0",
4047
"symfony/dom-crawler": "~2.8|~3.0|~4.0",
@@ -43,6 +50,7 @@
4350
"symfony/form": "~3.4|~4.0",
4451
"symfony/expression-language": "~2.8|~3.0|~4.0",
4552
"symfony/process": "~2.8|~3.0|~4.0",
53+
"symfony/property-access": "dev-master",
4654
"symfony/security-core": "~3.2|~4.0",
4755
"symfony/security-csrf": "~2.8|~3.0|~4.0",
4856
"symfony/serializer": "~3.3|~4.0",

0 commit comments

Comments
 (0)
0