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

Skip to content

Commit 91d9d74

Browse files
committed
Added MetadataLoader to PropertyAccess configuration registration
1 parent 6f252c5 commit 91d9d74

File tree

8 files changed

+67
-2
lines changed

8 files changed

+67
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CHANGELOG
2828
name as value, using it makes the command lazy
2929
* Added `cache:pool:prune` command to allow manual stale cache item pruning of supported PSR-6 and PSR-16 cache pool
3030
implementations
31+
* Added custom property accessors support
3132
* Deprecated `Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader`, use
3233
`Symfony\Component\Translation\Reader\TranslationReader` instead
3334
* Deprecated `translation.loader` service, use `translation.reader` instead

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,16 @@ private function addPropertyAccessSection(ArrayNodeDefinition $rootNode)
790790
->children()
791791
->booleanNode('magic_call')->defaultFalse()->end()
792792
->booleanNode('throw_exception_on_invalid_index')->defaultFalse()->end()
793-
->end()
793+
->booleanNode('enable_annotations')->defaultFalse()->end()
794+
->arrayNode('mapping')
795+
->addDefaultsIfNotSet()
796+
->fixXmlConfig('path')
797+
->children()
798+
->arrayNode('paths')
799+
->prototype('scalar')->end()
800+
->end()
801+
->end()
802+
->end()
794803
->end()
795804
->end()
796805
;

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,10 +1391,36 @@ private function registerPropertyAccessConfiguration(array $config, ContainerBui
13911391

13921392
$loader->load('property_access.xml');
13931393

1394-
$container->getDefinition('property_accessor')->setPrivate(true);
1394+
$loaders = array();
1395+
$fileRecorder = function ($extension, $path) use (&$loaders) {
1396+
$definition = new Definition(in_array($extension, array('yaml', 'yml')) ? 'Symfony\Component\PropertyAccess\Mapping\Loader\YamlFileLoader' : 'Symfony\Component\PropertyAccess\Mapping\Loader\XmlFileLoader', array($path));
1397+
$definition->setPublic(false);
1398+
$loaders[] = $definition;
1399+
};
1400+
1401+
if (isset($config['enable_annotations']) && $config['enable_annotations']) {
1402+
if (!$this->annotationsConfigEnabled) {
1403+
throw new \LogicException('"enable_annotations" on property access cannot be set as Annotations support is disabled.');
1404+
}
1405+
$annotationLoader = new Definition(
1406+
'Symfony\Component\PropertyAccess\Mapping\Loader\AnnotationLoader',
1407+
array(new Reference('annotation_reader'))
1408+
);
1409+
$annotationLoader->setPublic(false);
1410+
$loaders[] = $annotationLoader;
1411+
}
1412+
1413+
$this->registerComponentMapping($container, $fileRecorder, 'property_accessor');
1414+
1415+
$this->registerMappingFilesFromConfig($container, $config, $fileRecorder);
1416+
1417+
$chainLoader = $container->getDefinition('property_access.mapping.chain_loader');
1418+
1419+
$chainLoader->replaceArgument(0, $loaders);
13951420

13961421
$container
13971422
->getDefinition('property_accessor')
1423+
->setPrivate(true)
13981424
->replaceArgument(0, $config['magic_call'])
13991425
->replaceArgument(1, $config['throw_exception_on_invalid_index'])
14001426
;

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
@@ -282,6 +282,10 @@ protected static function getBundleDefaultConfig()
282282
'property_access' => array(
283283
'magic_call' => false,
284284
'throw_exception_on_invalid_index' => false,
285+
'enable_annotations' => false,
286+
'mapping' => array(
287+
'paths' => array(),
288+
),
285289
),
286290
'property_info' => array(
287291
'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
AAC9
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