Skip to content

[DependencyInjection] Add documentation for service locator changes #10397

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 2 commits into from
Sep 23, 2019

Conversation

codedmonkey
Copy link
Contributor

Adds documentation for PR symfony/symfony#28571

@javiereguiluz javiereguiluz added the Waiting Code Merge Docs for features pending to be merged label Sep 25, 2018
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull request Oct 3, 2018
…rvice matching (codedmonkey)

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

Discussion
----------

[DependencyInjection] Improve ServiceLocatorTagPass service matching

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

Allows omitting of keys for service locator arguments (it will automatically take over the original definition alias).

Commits
-------

1c1210a3e8 [DependencyInjection] Improve ServiceLocatorTagPass service matching
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Oct 3, 2018
…rvice matching (codedmonkey)

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

Discussion
----------

[DependencyInjection] Improve ServiceLocatorTagPass service matching

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

Allows omitting of keys for service locator arguments (it will automatically take over the original definition alias).

Commits
-------

1c1210a [DependencyInjection] Improve ServiceLocatorTagPass service matching
@codedmonkey
Copy link
Contributor Author

Code has been merged :)

@javiereguiluz javiereguiluz removed the Waiting Code Merge Docs for features pending to be merged label Oct 8, 2018
@javiereguiluz
Copy link
Member

@codedmonkey for this kind of features, we always add some comments and examples in the code samples, to make it easier to understand. Could you please my reword to do that? Thanks!

@javiereguiluz
Copy link
Member

@codedmonkey the current YAML example that I added is wrong:

# config/services.yaml
services:
    app.command_handler_locator:
        class: Symfony\Component\DependencyInjection\ServiceLocator
        arguments:
           -
               App\FooCommand: '@app.command_handler.foo'
               App\BarCommand: '@app.command_handler.bar'
               # if the element has no key, the ID of the original service is used
               '@app.command_handler.baz'

It says:

(<unknown>): could not find expected ':' while scanning a simple key
at line 10 column 16

What's the correct syntax for YAML? Or maybe this feature is not supported in YAML? Thanks!

@javiereguiluz
Copy link
Member

Anyone knows if this feature works with YAML config? @xabbuh? @nicolas-grekas? If it works, which is the syntax? Thanks!

@codedmonkey
Copy link
Contributor Author

My apologies for the late response.

It looks like combining collections aand arrays in YAML is indeed a no-go, symfony/symfony#23664. It's possible to do either

        arguments:
           -
               - '@app.command_handler.foo'
               - '@app.command_handler.bar'
               - '@app.command_handler.baz'

or

        arguments:
           -
               App\FooCommand: '@app.command_handler.foo'
               App\BarCommand: '@app.command_handler.bar'
               App\BazCommand: '@app.command_handler.baz'

but not a combination of the two. Trying to add the feature would just increase complexity. Any ideas how best to address this in the docs?

@xabbuh
Copy link
Member

xabbuh commented Nov 6, 2018

That's correct, a collection in YAML is either a sequence or a mapping. I would just add a second example like this:

# config/services.yaml
services:
    app.command_handler_locator:
        class: Symfony\Component\DependencyInjection\ServiceLocator
        arguments:
           -
               App\FooCommand: '@app.command_handler.foo'
               App\BarCommand: '@app.command_handler.bar'

    # or if the element has no key, the ID of the original service is used
    app.another_command_handler_locator:
        class: Symfony\Component\DependencyInjection\ServiceLocator
        arguments:
           -
               - '@app.command_handler.baz'

@@ -314,6 +321,10 @@ include as many services as needed in it.
previous Symfony versions you always needed to add the
``container.service_locator`` tag explicitly.

.. versionadded:: 4.2
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a blank line after the directive

@javiereguiluz javiereguiluz changed the base branch from master to 4.3 September 23, 2019 15:32
javiereguiluz added a commit that referenced this pull request Sep 23, 2019
…tor changes (codedmonkey, javiereguiluz)

This PR was submitted for the master branch but it was merged into the 4.3 branch instead (closes #10397).

Discussion
----------

[DependencyInjection] Add documentation for service locator changes

Adds documentation for PR symfony/symfony#28571

Commits
-------

8d8c65e Reword
bc5ef85 [DependencyInjection] Add documentation for service locator changes
@javiereguiluz javiereguiluz merged commit 8d8c65e into symfony:4.3 Sep 23, 2019
@javiereguiluz
Copy link
Member

It took us forever ... but this is finally merged. Thank you all for your help and contributions.

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