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

Skip to content

Update docs about class named services #8403

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

Closed
ro0NL opened this issue Sep 17, 2017 · 4 comments
Closed

Update docs about class named services #8403

ro0NL opened this issue Sep 17, 2017 · 4 comments
Labels
actionable Clear and specific issues ready for anyone to take them. bug DependencyInjection Status: Needs Review Waiting feedback
Milestone

Comments

@ro0NL
Copy link
Contributor

ro0NL commented Sep 17, 2017

E.g. https://symfony.com/doc/current/service_container/tags.html

Talks about

    Swift_SmtpTransport:
        arguments: ['%mailer_host%']
        tags:
            - { name: app.mail_transport, alias: smtp }

# ...
    Swift_SendmailTransport:
        class: \Swift_SendmailTransport
        tags: [app.mail_transport]

The first-like variants wont work, and i also think we should avoid leading \ in class attr. This might break any normalization check. Standard is no leading slash.

See also symfony/symfony#24145

basically using poor-man namespacing by example makes your life hard.

@xabbuh xabbuh added actionable Clear and specific issues ready for anyone to take them. bug DependencyInjection labels Sep 18, 2017
xabbuh added a commit that referenced this issue Oct 13, 2017
…javiereguiluz)

This PR was merged into the 3.4 branch.

Discussion
----------

Docs for referencing tagged services in config

See symfony/symfony#22200

Curious how it looks :) also a bit related to #8403

Commits
-------

ed70659 Update tags.rst
2e5c87f Update tags.rst
564b5ea Update tags.rst
a2fd23f Update tags.rst
000b801 Minor reword and fixes
0aaf48b Update tags.rst
71158f8 Update tags.rst
61c74da Update tags.rst
da034d2 Docs for referencing tagged services in config
@javiereguiluz javiereguiluz added this to the 4.0 milestone Jul 19, 2018
@javiereguiluz
Copy link
Member

@ro0NL thanks for reporting this issue but I'm afraid I don't understand you. What should we do about this?

  • Remove this example because it doesn't work in Symfony 4?
  • Add or remove something in the current example? If yes, please show me the new config so I can update it.

Thanks!

@ro0NL
Copy link
Contributor Author

ro0NL commented Jul 19, 2018

Let me do a quick test this weekend, and i'll propose a PR for this page.

If i recall correctly the first example should be:

swift.smpt_transport: # the ID
   class: Swift_SmtpTransport # the Class

Only for namespaced classes using the class as ID value works:

Ns\Some: ~

Using the leading \ in the ID value has no effect, it would still need a class: value.

Using the leading \ in the class value probably works but is inconsistent. I think the issue was it wont work with any check a la $def->getClass() === Some::class (as in PHP we dont get the leading \). But that's a per case issue most likely, in general avoiding the leading \ seems like a good practice, and perhaps should even be normalized somewhere in Symfony.

@ro0NL
Copy link
Contributor Author

ro0NL commented Jul 19, 2018

@javiereguiluz

About the class attribute

# always works
class: MyClass
class: My\Class

# works as of v2.7.32, v2.8.25, v3.2.12, v3.3.5
class: \MyClass
class: \My\Class

So in terms of consistency and providing working example code, even prior to the versions mentioned above, i think we should leave out the leading \ in the class attribute across all docs.

About the service ID

# always works
MyClass: { class: 'MyClass' }
My\Class: ~

# doesnt work / unsupported
MyClass: ~
\MyClass: ~
\My\Class: ~

In this case we should actually provide working example code across all docs. Thus only use variants without leading /, adding the class attribute if necessary or using namespaced classes by default.

Hope this clarifies. Im not aware how many examples are affected actually :)

@javiereguiluz
Copy link
Member

Thanks for the explanation. As discussed in symfony/symfony#28006, let's not "pollute" the docs with these internal details ... and let's improve the error message shown by Symfony. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable Clear and specific issues ready for anyone to take them. bug DependencyInjection Status: Needs Review Waiting feedback
Projects
None yet
Development

No branches or pull requests

4 participants