Skip to content

[DI] Deprecate underscore-services in YamlFileLoader #21484

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
Feb 16, 2017

Conversation

nicolas-grekas
Copy link
Member

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

As discussed when introducing _defaults

@@ -239,6 +239,9 @@ private function parseDefaults(array &$content, $file)
*/
private function parseDefinition($id, $service, $file, array $defaults)
{
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
@trigger_error(sprintf('Service names that start with an underscore are deprecated since Symfony 3.3 and will be reserved in 4.0. Rename the "%s" service or define it in XML instead.', $id), E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's a good idea that the allowed service ids depend on the config format. In the past, we've worked hard to make all formats work the same in spite of their differences (for example, by adding PHP constants support for Yaml files). If we want to deprecate something, we could deprecate just the _defaults string as service id (whatever the config format used).

Copy link
Member Author

@nicolas-grekas nicolas-grekas Feb 1, 2017

Choose a reason for hiding this comment

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

There is little comparison between supporting a feature in all formats (eg constants), and excluding a very specific narrow case for one specific loader which misses a few oops of expressiveness (eg underscore-services, which are not a "feature").
We also stated previously that we don't want parity with all loader formats - quite the contrary in fact: we want to embrace the full expressiveness of each format. Here, it's exactly a matter of expressiveness. Thus falls into this policy to me - thus only the yaml loader should be affected.

@jvasseur
Copy link
Contributor

jvasseur commented Feb 1, 2017

Maybe we could use a yaml tag for default values (or other non-service keys) instead and keep allowing anything for service names.

@nicolas-grekas
Copy link
Member Author

We wondered about tags for eg _defaults in #21194, but that didn't look good. What would it look like to you?

@jvasseur
Copy link
Contributor

jvasseur commented Feb 1, 2017

Probably something like this

services:
  defaults: !default
    public: false
  Foo\Bar: [@foo]

Any service tagged with default would be used as default instead of a service. And the key would be ignored.

@nicolas-grekas
Copy link
Member Author

That's what I meant by:

that didn't look good

I keep this opinion :)

@jvasseur
Copy link
Contributor

jvasseur commented Feb 1, 2017

Yeah I don't like it that much, but using underscore-names to convey special meanings looks to much like a hack to me to like it.

@javiereguiluz
Copy link
Member

Is it too late to create a new config option called services_defaults ? It could convey its meaning better and it'd remove the need for hacks and for the YAML/XML unparity:

services_defaults:
    public: false

services:
    Foo\Bar: [@foo]

@nicolas-grekas
Copy link
Member Author

@javiereguiluz this discussion already happened, see #21071 :)

@stof
Copy link
Member

stof commented Feb 1, 2017

@javiereguiluz this is also a BC break, as it makes this key forbidden for DI extensions (and it is much harder to write a BC layer, as we would be unable to detect this case as the DI extension could expose a config similar to our defaults)

@fabpot
Copy link
Member

fabpot commented Feb 16, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 7781082 into symfony:master Feb 16, 2017
fabpot added a commit that referenced this pull request Feb 16, 2017
…nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Deprecate underscore-services in YamlFileLoader

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

As discussed when introducing `_defaults`

Commits
-------

7781082 [DI] Deprecate underscore-services in YamlFileLoader
@nicolas-grekas nicolas-grekas deleted the di-deprec_ branch February 16, 2017 12:54
@fabpot fabpot mentioned this pull request May 1, 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