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

Skip to content

[DI] Autowire arguments that are container parameters #21699

Closed
@javiereguiluz

Description

@javiereguiluz
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 3.3

These days we're updating the Symfony Demo app to use the new service configuration proposed for Symfony 3.3. See https://github.com/symfony/symfony-demo/pull/483/files

One of the things I like the least is this config:

services:
    AppBundle\Twig\AppExtension:
        $locales: '%app_locales%'

    AppBundle\EventListener\RedirectToPreferredLocaleSubscriber:
        $locales: '%app_locales%'

    AppBundle\EventListener\CommentNotificationSubscriber:
        $sender: '%app.notifications.email_sender%'

Having to create that boring config just to pass some container parameters destroys the purpose of this new config being RAD, etc.

Proposal

Would it make any sense to "autowire the parameters"?

Before

class AppExtension extends \Twig_Extension
{
    // ...

    public function __construct(Markdown $parser, $locales)
    {
        // ...
    }

    // ...
}
services:
    AppBundle\Twig\AppExtension:
        $locales: '%app_locales%'

After

class AppExtension extends \Twig_Extension
{
    // ...

    public function __construct(Markdown $parser, $locales = '%app_locales%')
    {
        // ...
    }

    // ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DependencyInjectionFeatureRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions