Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Make YamlFileLoader raise a deprecation notice if a service definition contains unsupported keywords. #17133

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

Conversation

hhamon
Copy link
Contributor

@hhamon hhamon commented Dec 24, 2015

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets ~
License MIT
Doc PR ~

Merry Christmas Symfony!!!

@hhamon
Copy link
Contributor Author

hhamon commented Dec 24, 2015

To me this PR should be opened against the 2.3, 2.7,  2.8 and  3.0 branches as this behavior is already supported by the XmlFileLoader thanks to the provided XML definition file.

Should we consider it a new feature and keep the PR opened against the master branch or should I reopen it against the older branches?

@nicolas-grekas @stof @fabpot any ideas please?

@hhamon hhamon force-pushed the feat-raise-exception-invalid-yaml-definition branch from 97d979b to 505089b Compare December 24, 2015 15:22
@hhamon hhamon changed the title [DependencyInjection] The YamlFileLoader raises an InvalidArgumentException is a service definition contains unsupported keywords. [DependencyInjection] Make YamlFileLoader raise an InvalidArgumentException if a service definition contains unsupported keywords. Dec 25, 2015
private static function checkDefinition($id, array $definition)
{
foreach ($definition as $key => $value) {
if (!in_array($key, static::$keywords)) {
Copy link
Member

Choose a reason for hiding this comment

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

You can make supported properties keys of static::$keywords and use isset, it will reduce the complexity from O(n) to O(1).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@hhamon hhamon force-pushed the feat-raise-exception-invalid-yaml-definition branch from 505089b to 188ab3b Compare December 27, 2015 12:40
if (!isset(static::$keywords[$key])) {
throw new InvalidArgumentException(sprintf(
'The "%s" key in "%s" service definition is not valid. It must be one of "%s".',
(string) $key,
Copy link
Member

Choose a reason for hiding this comment

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

no need to cast here, and usually, we prefer putting exceptions on one single (long) line

@stof
Copy link
Member

stof commented Dec 28, 2015

The problem is when you have a generic bundle that supports "symfony/symfony": "^2.3|^3.0", a solution to support the new api is to have the new and the deprecated keywords in its configuration files.
This PR would force people to update their package in a minor version and it is against the symfony BC policy. IMO this exception should be added in symfony 4.0 and unsupported keywords deprecated in symfony 3.1.

I agree with @Ener-Getick here. Throwing an exception on unsupported keys in the service definition is indeed a BC break as it might break existing working config files.

@hhamon hhamon changed the title [DependencyInjection] Make YamlFileLoader raise an InvalidArgumentException if a service definition contains unsupported keywords. [DependencyInjection] Make YamlFileLoader raise a deprecation notice if a service definition contains unsupported keywords. Dec 28, 2015
@hhamon
Copy link
Contributor Author

hhamon commented Dec 28, 2015

I've changed the PR to raise a deprecation notice instead. Shall we also introduce an UPGRADE-4.0.md to start indexing the future changes in 4.x?

@hhamon hhamon force-pushed the feat-raise-exception-invalid-yaml-definition branch 2 times, most recently from 898e9b8 to 4a3ab07 Compare December 28, 2015 16:26
@GuilhemN
Copy link
Contributor

I think that we should have an upgrade file for 3.1 which would advise to don't use unsupported keys anymore.

@hhamon hhamon force-pushed the feat-raise-exception-invalid-yaml-definition branch 4 times, most recently from 31a98fc to 6f398da Compare December 28, 2015 16:45
@hhamon
Copy link
Contributor Author

hhamon commented Dec 28, 2015

I guess this time, it's ok for another round of review.

@@ -32,6 +32,30 @@
*/
class YamlFileLoader extends FileLoader
{
private static $keywords = array(
'alias' => 'alias',
'parent' => 'parent',
Copy link
Contributor

Choose a reason for hiding this comment

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

What about removing this array values as the code only uses its keys?
Ping @dunglas

Copy link
Member

Choose a reason for hiding this comment

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

values are used when constructing the message (see implode)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops didn't see that ☺️

@hhamon hhamon force-pushed the feat-raise-exception-invalid-yaml-definition branch 3 times, most recently from 54ea34c to 4a67241 Compare December 29, 2015 09:35
…if a service definition contains unsupported keywords.
@hhamon hhamon force-pushed the feat-raise-exception-invalid-yaml-definition branch from 4a67241 to bb5f118 Compare December 29, 2015 09:37
@nicolas-grekas
Copy link
Member

👍

@xabbuh
Copy link
Member

xabbuh commented Dec 29, 2015

We should add a way to add additional custom keys. For example, the FOSRestBundle adds additional keys for defining REST related routes. With the current implementation we would have overridde the complete checkDefinition() method.

@hhamon
Copy link
Contributor Author

hhamon commented Dec 29, 2015

@xabbuh it's for service definitions routing. Does FOSRestBundle have extra parameters for services definitions?

@xabbuh
Copy link
Member

xabbuh commented Dec 29, 2015

@hhamon Sorry, forget about my comment.

@hhamon
Copy link
Contributor Author

hhamon commented Jan 5, 2016

Any news on this? @xabbuh @stof @nicolas-grekas @dunglas @weaverryan @webmozart

// @deprecated Uncomment the following statement in Symfony 4.0
// and also update the corresponding unit test to make it expect
// an InvalidArgumentException exception.
//throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for service definition "%s" in "%s". Allowed configuration keys are "%s".', $key, $id, $file, implode('", "', static::$keywords)));
Copy link
Member

Choose a reason for hiding this comment

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

What about creating the 4.0 branch now to avoid having to make such updates later?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 would avoid to forget some deprecations/updates of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm 100% for creating for 4.0 branch already if @fabpot agrees.

Copy link
Member

Choose a reason for hiding this comment

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

As one of the happy few doing the merges from 2.3 up to master, I'm 👎. This is tedious enough to not add one more branch. I hope you understand...

Copy link
Contributor

Choose a reason for hiding this comment

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

@nicolas-grekas this branch would not need to have merges as often as the others and should also not receive as much commits

Copy link
Member

Choose a reason for hiding this comment

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

The drawback would be that we would have to maintain it already, and people would start using it in their composer projects. So I'm -1 on it.

When we start the 4.0 development, we will look at any existing @trigger_error to convert them to the new code (either removing code, or doing other actions).

I would even remove the commented exception and just put a comment saying it should be converted to an exception in 4.0. This way, the exception message will be written at the 4.0 time, not now, and so using the uptodate deprecation message.

Copy link
Member

Choose a reason for hiding this comment

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

Thus, merges into newer major versions are the worse branch merges, as they often trigger merge conflicts (due to the removal of BC layers), so it is better to avoid doing them during the whole 3.x lifetime.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, and creating 4.0 would require creating 3.1, 3.2, 3.3 and 3.4 also, because that's how we merge things. 👎 👎 👎

@dunglas
Copy link
Member

dunglas commented Jan 5, 2016

👍, very useful when using autowiring (I often use the key types instead and autowiring_types and currently it silently fail).

@xabbuh
Copy link
Member

xabbuh commented Jan 5, 2016

👍

@fabpot
Copy link
Member

fabpot commented Jan 7, 2016

Thank you @hhamon.

@fabpot fabpot merged commit bb5f118 into symfony:master Jan 7, 2016
fabpot added a commit that referenced this pull request Jan 7, 2016
…ecation notice if a service definition contains unsupported keywords. (hhamon)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[DependencyInjection] Make YamlFileLoader raise a deprecation notice if a service definition contains unsupported keywords.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Merry Christmas Symfony!!!

Commits
-------

bb5f118 [DependencyInjection] make YamlFileLoader raise a deprecation notice if a service definition contains unsupported keywords.
fabpot added a commit that referenced this pull request Jan 16, 2016
…/elements for alias (Ener-Getick)

This PR was squashed before being merged into the 3.1-dev branch (closes #17323).

Discussion
----------

[DependencyInjection] Deprecate unsupported attributes/elements for alias

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #17256
| License       | MIT

Following #17133, this PR deprecates using unsupported keywords on alias definition.

For example the following examples will trigger deprecations:
```xml
<?xml version="1.0" encoding="utf-8"?>
<container>
  <services>
    <service id="bar" alias="foo" class="Foo">
        <tag name="foo.bar" />
    </service>
  </services>
</container>
```
```yml
services:
    bar:
        alias: foo
        parent: quz
```

Commits
-------

49eb65c [DependencyInjection] Deprecate unsupported attributes/elements for alias
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull request Jan 16, 2016
…/elements for alias (Ener-Getick)

This PR was squashed before being merged into the 3.1-dev branch (closes #17323).

Discussion
----------

[DependencyInjection] Deprecate unsupported attributes/elements for alias

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #17256
| License       | MIT

Following symfony/symfony#17133, this PR deprecates using unsupported keywords on alias definition.

For example the following examples will trigger deprecations:
```xml
<?xml version="1.0" encoding="utf-8"?>
<container>
  <services>
    <service id="bar" alias="foo" class="Foo">
        <tag name="foo.bar" />
    </service>
  </services>
</container>
```
```yml
services:
    bar:
        alias: foo
        parent: quz
```

Commits
-------

49eb65c [DependencyInjection] Deprecate unsupported attributes/elements for alias
@fabpot fabpot mentioned this pull request May 13, 2016
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.

8 participants