Skip to content

[FrameworkBundle] Support autowiring for TranslationInterface #17703

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
wants to merge 2 commits into from

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Feb 5, 2016

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

@soullivaneuh
Copy link
Contributor

This seems to not working:

Unable to autowire argument of type "Symfony\Component\Translation\TranslatorInterface" for the service "twig.ssl_certificate_extension".

My service definition:

    twig.ssl_certificate_extension:
        class: AppBundle\Twig\SslCertificateExtension
        autowire: true
        tags:
            - { name: twig.extension }

My service class:

class SslCertificateExtension extends \Twig_Extension
{
    /**
     * @var TranslatorInterface
     */
    private $translator;

    /**
     * @param TranslatorInterface $translator
     */
    public function __construct(TranslatorInterface $translator)
    {
        $this->translator = $translator;
    }
// [...]

@stof
Copy link
Member

stof commented Feb 5, 2016

This may be because this service is replaced by another one when enabling the translator

@soullivaneuh
Copy link
Contributor

@stof indeed:

$ ./docker-console app/console container:debug | grep translator
  translator                                                                       Symfony\Component\Translation\DataCollectorTranslator                                           
  translator.default                                                               Symfony\Bundle\FrameworkBundle\Translation\Translator                                           
  translator_listener                                                              Symfony\Component\HttpKernel\EventListener\TranslatorListener                                   

@soullivaneuh
Copy link
Contributor

Works like a charm now! 💚

@fabpot
Copy link
Member

fabpot commented Feb 9, 2016

Thank you @dunglas.

fabpot added a commit that referenced this pull request Feb 9, 2016
…ace (dunglas)

This PR was squashed before being merged into the 2.8 branch (closes #17703).

Discussion
----------

[FrameworkBundle] Support autowiring for TranslationInterface

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

2419725 [FrameworkBundle] Support autowiring for TranslationInterface
@fabpot fabpot closed this Feb 9, 2016
This was referenced Feb 28, 2016
@dunglas dunglas deleted the translator_autowiring branch March 10, 2016 11:41
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