Php 使用多个参数重写复杂的类
我正在尝试重写类Php 使用多个参数重写复杂的类,php,symfony,Php,Symfony,我正在尝试重写类UsernamePasswordFormAuthenticationListener parameters: security.authentication.listener.form.class: AppBundle\Listener\LoginFormListener class LoginFormListener extends UsernamePasswordFormAuthenticationListener { /** * {@inherit
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;
}
}
但当我执行它时,我有一个错误:
Catchable Fatal Error: Argument 1 passed to 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 and defined
你知道我该怎么做吗 您只需将类中的
SecurityContextInterface
类型提示更改为TokenStorageInterface
,所有操作都应正常工作-此类服务最近已更改(在2.7中已弃用),因此示例代码可能已过时
检查以获取有关的更多信息
securitycontenterface
vsTokenStorageInterface
根据要覆盖的类的定义,它接受TokenStorageInterface
的实例,但在您的类中,第一个参数是securitycontenterface
的实例。检查原始代码并相应地修改您的类。您是对的,我不知道我怎么会错过它?但我只是改变了它,它也犯了同样的错误。我已经清除了缓存。。。编辑:我只是忘记使用这个类,现在可以了。