php - Override a complicated class with multiple parameters -
i trying override class usernamepasswordformauthenticationlistener
.
parameters: security.authentication.listener.form.class: appbundle\listener\loginformlistener class loginformlistener extends usernamepasswordformauthenticationlistener { /** * {@inheritdoc} */ public function __construct(securitycontextinterface $securitycontext, authenticationmanagerinterface $authenticationmanager, sessionauthenticationstrategyinterface $sessionstrategy, httputils $httputils, $providerkey, authenticationsuccesshandlerinterface $successhandler, authenticationfailurehandlerinterface $failurehandler, array $options = array(), loggerinterface $logger = null, eventdispatcherinterface $dispatcher = null, csrfproviderinterface $csrfprovider = null) { parent::__construct($securitycontext, $authenticationmanager, $sessionstrategy, $httputils, $providerkey, $successhandler, $failurehandler, $options, $logger, $dispatcher, $csrfprovider); } protected function attemptauthentication(request $request) { if (null !== $this->csrftokenmanager) { $csrftoken = $request->get($this->options['csrf_parameter'], null, true); if (false === $this->csrftokenmanager->istokenvalid(new csrftoken($this->options['intention'], $csrftoken))) { throw new invalidcsrftokenexception('invalid csrf token.'); } } if ($this->options['post_only']) { $username = trim($request->request->get($this->options['username_parameter'], null, true)); $password = $request->request->get($this->options['password_parameter'], null, true); } else { $username = trim($request->get($this->options['username_parameter'], null, true)); $password = $request->get($this->options['password_parameter'], null, true); } $request->getsession()->set(security::last_username, $username); $apirequest = new apirequest(); $apirequest->addmethod('login', array('email' => $username, 'password' => $password)); $response = $apirequest->sendrequest(); dump($response); exit; } }
but when execute it, have error :
catchable fatal error: argument 1 passed appbundle\listener\loginformlistener::__construct() must implement interface symfony\component\security\core\securitycontextinterface, instance of symfony\component\security\core\authentication\token\storage\tokenstorage given, called in /users/dimitri/sites/rennes/app/cache/dev/appdevdebugprojectcontainer.php on line 4039 , defined
any idea how can make work ?
you can change securitycontextinterface
type hint tokenstorageinterface
in class , should work fine - class service has been changed (deprecated in 2.7) , example code might outdated.
check blog post entry more info securitycontextinterface
vs tokenstorageinterface
Comments
Post a Comment