Skip to content

[DependencyInjection] Usability: decorates syntax feels inconsistent by not requiring leading @ #17666

@k0pernikus

Description

@k0pernikus

I just got bit that when using the decorates syntax for a service definiton, that the decorates requires the service name without leading @.

As pointed out on the docs, this is correct:

bar:
  public: false
  class: stdClass
  decorates: foo
  arguments: ["@bar.inner"]

Yet I have written this code and thought it to be correct:

bar:
  public: false
  class: stdClass
  decorates: @foo
  arguments: ["@bar.inner"]

This then crashed by throwing a:

InvalidArgumentException in ContainerBuilder.php line 815:
The service definition "@foo" does not exist.

and it took me a bit and a xdebug session to figure out my typo.

Why isn't the @ here required for the service name? Is the current syntax inconsistent or do I lack an understanding of what the syntax refers to here? E.g. is the @ only used when a service is passed, and here it is only referencing a service name?

Maybe one can also improve the handling of Symfony\Component\DependencyInjection\ContainerBuilder::getDefinition($id) to either strip an incomming @ from the beginning of the $id or throw a message like

The service definition "@foo" does not exist. Did you maybe mean "foo" instead?`

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)DependencyInjection

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy