8000 [FrameworkBundle] Integrate custom property accessors into the framework by lrlopez · Pull Request #22191 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Integrate custom property accessors into the framework #22191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added MetadataLoader to PropertyAccess configuration registration
  • Loading branch information
lrlopez committed Nov 6, 2017
commit 91d9d74db37787fc7ce566b871497a4b41defbe1
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CHANGELOG
name as value, using it makes the command lazy
* Added `cache:pool:prune` command to allow manual stale cache item pruning of supported PSR-6 and PSR-16 cache pool
implementations
* Added custom property accessors support
* Deprecated `Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader`, use
`Symfony\Component\Translation\Reader\TranslationReader` instead
* Deprecated `translation.loader` service, use `translation.reader` instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,16 @@ private function addPropertyAccessSection(ArrayNodeDefinition $rootNode)
->children()
->booleanNode('magic_call')->defaultFalse()->end()
->booleanNode('throw_exception_on_invalid_index')->defaultFalse()->end()
->end()
->booleanNode('enable_annotations')->defaultFalse()->end()
->arrayNode('mapping')
->addDefaultsIfNotSet()
->fixXmlConfig('path')
->children()
->arrayNode('paths')
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->end()
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,10 +1391,36 @@ private function registerPropertyAccessConfiguration(array $config, ContainerBui

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

$container->getDefinition('property_accessor')->setPrivate(true);
$loaders = array();
$fileRecorder = function ($extension, $path) use (&$loaders) {
$definition = new Definition(in_array($extension, array('yaml', 'yml')) ? 'Symfony\Component\PropertyAccess\Mapping\Loader\YamlFileLoader' : 'Symfony\Component\PropertyAccess\Mapping\Loader\XmlFileLoader', array($path));
$definition->setPublic(false);
$loaders[] = $definition;
};

if (isset($config['enable_annotations']) && $config['enable_annotations']) {
if (!$this->annotationsConfigEnabled) {
throw new \LogicException('"enable_annotations" on property access cannot be set as Annotations support is disabled.');
}
$annotationLoader = new Definition(
'Symfony\Component\PropertyAccess\Mapping\Loader\AnnotationLoader',
array(new Reference('annotation_reader'))
);
$annotationLoader->setPublic(false);
$loaders[] = $annotationLoader;
}

$this->registerComponentMapping($container, $fileRecorder, 'property_accessor');

$this->registerMappingFilesFromConfig($container, $config, $fileRecorder);

$chainLoader = $container->getDefinition('property_access.mapping.chain_loader');

$chainLoader->replaceArgument(0, $loaders);

$container
->getDefinition('property_accessor')
->setPrivate(true)
->replaceArgument(0, $config['magic_call'])
->replaceArgument(1, $config['throw_exception_on_invalid_index'])
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@
<services>
<defaults public="false" />

<!-- Loader -->
<service id="property_access.mapping.chain_loader" class="Symfony\Component\PropertyAccess\Mapping\Loader\LoaderChain">
<argument type="collection" />
</service>

<!-- Class Metadata Factory -->
<service id="property_access.mapping.class_metadata_factory" class="Symfony\Component\PropertyAccess\Mapping\Factory\LazyLoadingMetadataFactory">
<argument type="service" id="property_access.mapping.chain_loader" />
</service>

<service id="property_accessor" class="Symfony\Component\PropertyAccess\PropertyAccessor">
<argument /> <!-- magicCall, set by the extension -->
<argument /> <!-- throwExceptionOnInvalidIndex, set by the extension -->
<argument type="service" id="cache.property_access" on-invalid="ignore" />
<argument type="service" id="property_access.mapping.class_metadata_factory" on-invalid="ignore" />
</service>
<service id="Symfony\Component\PropertyAccess\PropertyAccessorInterface" alias="property_accessor" />
</services>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ protected static function getBundleDefaultConfig()
'property_access' => array(
'magic_call' => false,
'throw_exception_on_invalid_index' => false,
'enable_annotations' => false,
'mapping' => array(
'paths' => array(),
),
),
'property_info' => array(
'enabled' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
'debug' => true,
'file_cache_dir' => '%kernel.cache_dir%/annotations',
),
'property_access' => array(
'magic_call' => false,
'throw_exception_on_invalid_index' => false,
'enable_annotations' => true,
),
'serializer' => array(
'enabled' => true,
'enable_annotations' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
'property_access' => array(
'magic_call' => true,
'throw_exception_on_invalid_index' => true,
'enable_annotations' => true,
),
));
8 changes: 8 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"homepage": "https://symfony.com/contributors"
}
],
"repositories": [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are only temporary until the PR is accepted or until PR #22190 is merged...

{
"type": "git",
"url": "https://github.com/lrlopez/property-access"
}
],
"require": {
"php": "^5.5.9|>=7.0.8",
"ext-xml": "*",
Expand All @@ -35,6 +41,7 @@
"fig/link-util": "^1.0",
"symfony/asset": "~3.3|~4.0",
"symfony/browser-kit": "~2.8|~3.0|~4.0",
"symfony/cache": "~3.4|~4.0",
"symfony/console": "~3.4|~4.0",
"symfony/css-selector": "~2.8|~3.0|~4.0",
"symfony/dom-crawler": "~2.8|~3.0|~4.0",
Expand All @@ -43,6 +50,7 @@
"symfony/form": "~3.4|~4.0",
"symfony/expression-language": "~2.8|~3.0|~4.0",
"symfony/process": "~2.8|~3.0|~4.0",
"symfony/property-access": "dev-master",
"symfony/security-core": "~3.2|~4.0",
"symfony/security-csrf": "~2.8|~3.0|~4.0",
"symfony/serializer": "~3.3|~4.0",
Expand Down
0