dsbifvcxr458755493 2016-02-01 13:07
浏览 54
已采纳

Symfony2:如何扩展DoctrineBahaviors?

I am using DoctrineBehaviors extension in my Symfony 3.0 project. Due to this change I have to override the UserCallable class. Is it possible to do this with bundle inheritance or any other way?

In more detail I want to override the original method:

class UserCallable {
    ...
    public function __invoke() {
        $token = $this->container->get('security.context')->getToken();
        if (null !== $token) {
            return $token->getUser();
        }
    }
}

probably in my custom bundle class:

class MyUserCallable extends UserCallable {
    ...
    public function __invoke() {
        $token = $this->container->get('security.token_storage')->getToken();
        if (null !== $token) {
            return $token->getUser();
        }
    }
}
  • 写回答

1条回答 默认 最新

  • dongzouh51192 2016-02-02 07:28
    关注

    As Jason Roman said, upgrading from 1.1 to 1.3 solved the issue.

    In case of standard extensions (e.g. adding publishedAt, publishedBy like in DoctrineExtensions) - using traits should do the trick.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)