[英]Symfony2: How to extend DoctrineBahaviors?
I am using DoctrineBehaviors extension in my Symfony 3.0 project. 我在Symfony 3.0项目中使用DoctrineBehaviors扩展。 Due to this change I have to override the UserCallable class.
由于此更改,我必须重写UserCallable类。 Is it possible to do this with bundle inheritance or any other way?
是否可以通过bundle继承或任何其他方式做到这一点?
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();
}
}
}
As Jason Roman said, upgrading from 1.1 to 1.3 solved the issue. 正如Jason Roman所说,从1.1升级到1.3解决了这个问题。
In case of standard extensions (eg adding publishedAt, publishedBy like in DoctrineExtensions ) - using traits should do the trick. 在标准的扩展的情况下(例如,在添加publishedAt,publishedBy像DoctrineExtensions ) - 使用特质应该做的伎俩。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.