2012-01-04 111 views
1

這個問題涉及到自定義AuthenticationHandler沒有正確實現接口 - 爲什麼?

How to disable redirection after login_check in Symfony 2

我已經實現了該鏈接正好給出的解決方案,但我收到一條錯誤我通常理解,但這次沒有。我的課完全實現了界面(我認爲)。

致命錯誤:Foo \ AppBundle \ Handler \ AuthenticationHandler :: onAuthenticationSuccess()聲明必須與/ Users/Me/Sites中的Symfony \ Component \ Security \ Http \ Authentication \ AuthenticationSuccessHandlerInterface :: onAuthenticationSuccess()兼容/github/Foo/Symfony/src/Foo/AppBundle/Handler/AuthenticationHandler.php第6行

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(); 
    } 
} 

建議表示讚賞!

回答

5

PHP認爲Request,TokenInterface來自當前命名空間,但接口聲明要求它們來自Symfony\*命名空間。 嘗試添加使用語句或使用這些類的FQN:

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\Security\Core\Exception\AuthenticationException; 
+0

哇。我怎麼錯過:)非常感謝 – PorridgeBear 2012-01-04 21:23:11

+0

非常感謝你:) – 2016-12-20 17:40:30