Skip to content

[FrameworkBundle] Do not load property_access.xml if the component isn't installed #24605

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 2 commits into from
Closed

[FrameworkBundle] Do not load property_access.xml if the component isn't installed #24605

wants to merge 2 commits into from

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented Oct 18, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #24563 (comment)
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.

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?

@ogizanagi
Copy link
Contributor Author

Added commit for option 2.

@chalasr
Copy link
Member

chalasr commented Oct 19, 2017

My preference goes for option 2 as well.

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Oct 19, 2017
@jakzal
Copy link
Contributor

jakzal commented Oct 26, 2017

option 2

@fabpot
Copy link
Member

fabpot commented Oct 28, 2017

Thank you @ogizanagi.

@fabpot fabpot closed this Oct 28, 2017
fabpot added a commit that referenced this pull request Oct 28, 2017
…omponent 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
@ogizanagi ogizanagi deleted the fix/2.7/serializer/object_normalizer_ex branch October 28, 2017 22:14
This was referenced Oct 30, 2017
This was referenced Nov 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants