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 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败
  • ¥150 计算DC/DC变换器平均模型中的参数mu
  • ¥25 C语言代码,大家帮帮我
  • ¥15 请问以下文字内容及对应编码是用了什么加密算法或压缩算法呢?
  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验