Skip to content

[DependencyInjection] [Service Container] Fix Service parameters typo in services.yml #14682

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

Yondz
Copy link

@Yondz Yondz commented Dec 9, 2020

Hi there,

I noticed a strange yml in the service_container doc, affecting >= 4.3 , there was a misplaced parameter under an example service definition.

I thought it would be nice to keep the actual information about escaping using @ so I just removed the wrong mailer_password: '@@securepassword' thing.

I used 4.4 as target, maybe this could be merged to 4.3 as well, I'll let you check this point !

=)

@carsonbot carsonbot added this to the 4.4 milestone Dec 9, 2020
@wouterj
Copy link
Member

wouterj commented Dec 9, 2020

Thank you @Yondz. This indeed looks quite weird.

What do you think about modifying the example a little bit, like this:

.. code-block:: yaml

    # config/services.yaml
    services:
        App\Service\MessageGenerator:
            arguments:
                # this is not a string, but a reference to a service called 'logger'
                - '@logger'

                # if the value of a string parameter starts with '@', you need to escape
                # it by adding another '@' so Symfony doesn't consider it a service
                # (this will be parsed as the string '@securepassword')
                - '@@securepassword'

If you agree, please update your PR (by pushing to fix_service_container_service_parameters), otherwise I would like to learn your ideas :)

@Yondz
Copy link
Author

Yondz commented Dec 9, 2020

Hi @wouterj ,

That's okay and better :) I might have to update the MessageGenerator / XML / PHP configurations as well to keep consistent then (that's why I wasn't sure at first sight),

I'll update this :)
Thanks

@Yondz Yondz changed the title [Service Container] Fix Service parameters typo in services.yml [WIP][Service Container] Fix Service parameters typo in services.yml Dec 9, 2020
@wouterj
Copy link
Member

wouterj commented Dec 9, 2020

Oh ah, yeah it's a bit confusing in XML/PHP, as the @ doesn't need to be escaped there. I think it's best to keep these as they are now.

@Yondz
Copy link
Author

Yondz commented Dec 9, 2020

And furthermore, when you scroll down a bit, there's even a redundancy with this example :

# config/services.yaml
services:
    # ... same code as before

    # explicitly configure the service
    App\Service\MessageGenerator:
        arguments:
            # the '@' symbol is important: that's what tells the container
            # you want to pass the *service* whose id is 'monolog.logger.request',
            # and not just the *string* 'monolog.logger.request'
            $logger: '@monolog.logger.request'

Maybe this would be a good tradeoff :

        services:
            App\Service\MessageGenerator:
                arguments:
                    # this is not a string, but a reference to a service called 'logger'
                    - '@logger'

                    # if the value of a string argument starts with '@', you need to escape
                    # it by adding another '@' so Symfony doesn't consider it a service
                    # the following example would be parsed as the string '@securepassword' : 
                    # - '@@securepassword'

WDYT ?

@Yondz Yondz force-pushed the fix_service_container_service_parameters branch 2 times, most recently from 4d90253 to e5e2122 Compare December 10, 2020 09:47
@Yondz Yondz force-pushed the fix_service_container_service_parameters branch from e5e2122 to a741c9c Compare December 10, 2020 09:48
@Yondz Yondz changed the title [WIP][Service Container] Fix Service parameters typo in services.yml [Service Container] Fix Service parameters typo in services.yml Dec 10, 2020
@carsonbot carsonbot changed the title [Service Container] Fix Service parameters typo in services.yml [DependencyInjection] [Service Container] Fix Service parameters typo in services.yml Jan 8, 2021
@javiereguiluz
Copy link
Member

Greg, it took us some time, but this is finally merged. Thanks!

@javiereguiluz javiereguiluz merged commit 9357aba into symfony:4.4 Jan 8, 2021
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.

4 participants