Gehad Mohamed
Gehad Mohamed

Reputation: 151

Override translator class not working in symfony3

I need to know how to override the trans method in symfony3.

In symfony2 project we used to override the parameter for the translator class

parameters:
    translator.class: Acme\HelloBundle\Translation\Translator

We started using symfony3 and try to apply the same approach but unfortunately the parameter was removed and the class path is written directly into the service.

Upvotes: 3

Views: 348

Answers (1)

Matteo
Matteo

Reputation: 39390

You can override an existing definition (e.g. when applying the Decorator pattern). This kind of decoration is supported by the Dependency Injection Container of Symfony as described in the doc. As example:

services:
    app.mailer:
        class: AppBundle\Mailer

    # this replaces the old app.mailer definition with the new one, the
    # old definition is lost
    app.mailer:
        class: AppBundle\DecoratingMailer

and:

services:
    # ...

    app.decorating_mailer:
      class:     AppBundle\DecoratingMailer
      decorates: app.mailer
      arguments: ['@app.decorating_mailer.inner']
      public:    false

Hope this help

Upvotes: 1

Related Questions