Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d7e859e

Browse filesBrowse files
committed
bug #24605 [FrameworkBundle] Do not load property_access.xml if the component isn't installed (ogizanagi)
This PR was squashed before being merged into the 2.7 branch (closes #24605). Discussion ---------- [FrameworkBundle] Do not load property_access.xml if the component isn't installed | Q | A | ------------- | --- | Branch? | 2.7 <!-- see comment below --> | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #24563 (comment) <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A This PR actually aims to fix #24563 (comment) as the exception introduced in the PR can't be reached anyway when using the FrameworkBundle without the property access component as you'll get: > Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "PropertyAccessor" from namespace "Symfony\Component\PropertyAccess". With this fix, you properly get: > The ObjectNormalizer class requires the "PropertyAccess" component. Install "symfony/property-access" to use it. Not sure this change really belongs to a patch release, but the original PR was accepted in the 2.7 branch. Also, I'd rather remove the ObjectNormalizer definition if the component isn't available, as suggested by @xabbuh (#24563 (comment)). But in 2.7, this is the only normalizer registered by default and the [`SerializerPass` throws an exception if no normalizer is registered.](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/SerializerPass.php#L46) To sum up, either: 1. we completly prevent using the FrameworkBundle and the serializer without the property access component, even if you don't really care about the ObjectNormalizer because you only use your owns specific ones. (and you'll get the exception hinting to install the property access component) 2. we allow using the FrameworkBundle and the serializer without the property access component, so we remove the ObjectNormalizer definition, but the user'll get a `You must tag at least one service as "serializer.normalizer" to use the Serializer service` exception until he configures a normalizer (and we don't get the hint about installing the property access component to enable the ObjectNormalizer. We already have a suggest entry in the composer.json file, though). To me option 2 looks better. WDYT? Commits ------- d297e27 [FrameworkBundle] Do not load property_access.xml if the component isn't installed
2 parents 711bdc9 + d297e27 commit d7e859e
Copy full SHA for d7e859e

File tree

1 file changed

+13
-5
lines changed
Filter options

1 file changed

+13
-5
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ public function load(array $configs, ContainerBuilder $container)
6060
// will be used and everything will still work as expected.
6161
$loader->load('translation.xml');
6262

63-
// Property access is used by both the Form and the Validator component
64-
$loader->load('property_access.xml');
65-
6663
$configuration = $this->getConfiguration($configs, $container);
6764
$config = $this->processConfiguration($configuration, $configs);
6865

@@ -126,7 +123,7 @@ public function load(array $configs, ContainerBuilder $container)
126123
}
127124

128125
$this->registerAnnotationsConfiguration($config['annotations'], $container, $loader);
129-
$this->registerPropertyAccessConfiguration($config['property_access'], $container);
126+
$this->registerPropertyAccessConfiguration($config['property_access'], $container, $loader);
130127

131128
if (isset($config['serializer'])) {
132129
$this->registerSerializerConfiguration($config['serializer'], $container, $loader);
@@ -761,8 +758,14 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
761758
}
762759
}
763760

764-
private function registerPropertyAccessConfiguration(array $config, ContainerBuilder $container)
761+
private function registerPropertyAccessConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
765762
{
763+
if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccessor')) {
764+
return;
765+
}
766+
767+
$loader->load('property_access.xml');
768+
766769
$container
767770
->getDefinition('property_accessor')
768771
->replaceArgument(0, $config['magic_call'])
@@ -793,6 +796,11 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
793796
$loader->load('serializer.xml');
794797
$chainLoader = $container->getDefinition('serializer.mapping.chain_loader');
795798

799+
if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccessor')) {
800+
$container->removeAlias('serializer.property_accessor');
801+
$container->removeDefinition('serializer.normalizer.object');
802+
}
803+
796804
$serializerLoaders = array();
797805
if (isset($config['enable_annotations']) && $config['enable_annotations']) {
798806
$annotationLoader = new Definition(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.