Symfony2 uses Dependency Injection pattern, you have to inject container that holds all services (like database connection):
$authenticate = new AuthenticationController();
$authenticate->setContainer($this->container);
$authenticate->isTokenValid($token);
Of course I assume here that your listener class is ContainerAware
[+] To make your listener ContainerAware, pass @service_container
to it (example form services.yml
)
my.listener:
class: ACMEMyBundleListenerController
arguments: [ @service_container ]
tags:
- { name: kernel.event_listener, event: kernel.controller, method: onKernelController }
kernel.event_listener:
event: kernel.controller
and then in constructor of you listener class:
public function __construct($container = null){
$this->container = $container;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…