自定义AuthenticationHandler没有正确实现接口 - 为什么?

Por*_*ear 1 symfony

这个问题涉及到

如何在Symfony 2中的login_check之后禁用重定向

我已经完全实现了在该链接上给出的解决方案,但是我收到了一个我通常理解的错误但是在这种情况下没有.我的课程绝对完美地实现了界面(我认为).

致命错误:Foo\AppBundle\Handler\AuthenticationHandler :: onAuthenticationSuccess()的声明必须与/ Users/Me/Sites/github/Foo中Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface :: onAuthenticationSuccess()的声明兼容第6行/Symfony/src/Foo/AppBundle/Handler/AuthenticationHandler.php

class AuthenticationHandler implements
\Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface,
\Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface
{
    function onAuthenticationSuccess(Request $request, TokenInterface $token) {
        return new Response();
    }

    function onAuthenticationFailure(Request $request, AuthenticationException $exception) {
        return new Response();
    }
}
Run Code Online (Sandbox Code Playgroud)

建议赞赏!

mez*_*eze 5

PHP认为Request,TokenInterface来自当前的命名空间,但接口的声明要求它们来自Symfony\*命名空间.尝试添加using语句或对这些类使用FQN:

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
Run Code Online (Sandbox Code Playgroud)