php - 覆盖在 symfony3 中不起作用的翻译器类

标签 php symfony overriding

我需要知道如何覆盖 symfony3 中的 trans 方法。

在 symfony2 项目中,我们用于覆盖翻译器类的参数

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

我们开始使用 symfony3 并尝试应用相同的方法,但不幸的是 parameter was removed类路径直接写入服务。

最佳答案

您可以覆盖现有定义(例如,在应用 Decorator pattern 时)。这种修饰由 Symfony 的依赖注入(inject)容器支持,如所述 in the doc .例如:

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

和:

services:
    # ...

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

希望对你有帮助

关于php - 覆盖在 symfony3 中不起作用的翻译器类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40283193/

相关文章:

api - 如何向外部 API 发送请求

c# - 为什么需要将派生类的对象赋值给基类来调用方法?

c# - 编辑接口(interface)时叫什么?

php - if 语句和 session

php - 在 Godaddy 主机上设置 CodeIgniter 站点

symfony - 如何将数据库中的所有数据显示到twig中?

javascript - 为什么最新的值被覆盖到 JavaScript 中的对象数组中?

PHP/MySQL 安全登录和 session

php - PDO mysql 和 PHP : Undefined index and Trying to get property of non-object

php - 学说的createQuery中的子查询