Skip to content

Validate the extended type for lazy-loaded type extensions #15743

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

Merged
merged 1 commit into from
Sep 15, 2015

Conversation

stof
Copy link
Member

@stof stof commented Sep 9, 2015

Q A
Bug fix? no
New feature? not really
BC breaks? yes, but only for broken setups
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Symfony 2.1 introduced such validation for form types because a mismatch would actually break the logic (the name is accessed again later).
This was not added for type extensions because in such case, getExtendedType would actually never be used for extensions loaded by the DI extension (this method is only used inside extensions, and the DI extension relies on the service configuration instead). However, having mismatching values there would make debugging much harder, and can hide mistakes (see #15740 for such a mistake being fixed in the core). It also means that it might be hard to fix usage of deprecated APIs as the code might not contain the same extended type than the one used in the fullstack usage.

@@ -9,6 +9,7 @@ CHANGELOG
* deprecated the "cascade_validation" option in favor of setting "constraints"
with the Valid constraint
* moved data trimming logic of TrimListener into StringUtil
* [BC BREAK] When registering a type extension through the DI extension, the tag alias has to match the actual extended type.
Copy link
Contributor

Choose a reason for hiding this comment

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

tag alias or the service id (if we don't intend to fallback to the service id, it should be deprecated)

Copy link
Contributor

Choose a reason for hiding this comment

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

the service id makes no sense as there could only be one extension for a type (as the service ids need to be unique). So IMO this fallback really needs to be deprecated, making the "alias" required in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, this really does not make sense for extensions

@stof
Copy link
Member Author

stof commented Sep 15, 2015

@symfony/deciders anything else needed here ?

@stof stof added the Ready label Sep 15, 2015
@stof stof force-pushed the validate_type_extensions branch from 169e965 to 8db6880 Compare September 15, 2015 09:06
@stof
Copy link
Member Author

stof commented Sep 15, 2015

I fixed the component tests by adding the necessary dev dependency to be able to test the DI extension.

@aitboudad
Copy link
Contributor

👍

// validate result of getExtendedType() to ensure it is consistent with the service definition
if ($extension->getExtendedType() !== $name) {
throw new InvalidArgumentException(
sprintf('The extended type specified for the service "%s" does not match the actual extended type. Expected "%s", given "%s"',
Copy link
Member

Choose a reason for hiding this comment

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

Missing dot at the end of the sentence.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@fabpot
Copy link
Member

fabpot commented Sep 15, 2015

👍

@stof stof force-pushed the validate_type_extensions branch from 8db6880 to 8826d39 Compare September 15, 2015 10:07
@fabpot
Copy link
Member

fabpot commented Sep 15, 2015

Thank you @stof.

@fabpot fabpot merged commit 8826d39 into symfony:2.8 Sep 15, 2015
fabpot added a commit that referenced this pull request Sep 15, 2015
…ions (stof)

This PR was merged into the 2.8 branch.

Discussion
----------

Validate the extended type for lazy-loaded type extensions

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | not really
| BC breaks?    | yes, but only for broken setups
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Symfony 2.1 introduced such validation for form types because a mismatch would actually break the logic (the name is accessed again later).
This was not added for type extensions because in such case, ``getExtendedType`` would actually never be used for extensions loaded by the DI extension (this method is only used inside extensions, and the DI extension relies on the service configuration instead). However, having mismatching values there would make debugging much harder, and can hide mistakes (see #15740 for such a mistake being fixed in the core). It also means that it might be hard to fix usage of deprecated APIs as the code might not contain the same extended type than the one used in the fullstack usage.

Commits
-------

8826d39 Validate the extended type for lazy-loaded type extensions
@stof stof deleted the validate_type_extensions branch September 20, 2015 21:01
@fabpot fabpot mentioned this pull request Nov 16, 2015
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.

5 participants