简体   繁体   中英

Symfony2: How to extend 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();
        }
    }
}

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM