2017-06-15 37 views
0

我嘗試按照Silex official website上的教程進行操作,但在Authenticator註冊爲服務時出現錯誤。Silex自定義身份驗證帶防護

Catchable fatal error: Argument 1 passed to App\Security\TokenAuthenticator::__construct() must be an instance of App\Security\EncoderFactoryInterface, instance of Symfony\Component\Security\Core\Encoder\EncoderFactory given, called in C:\wamp\www\api\src\app.php on line 41 and defined in C:\wamp\www\api\src\App\Security\TokenAuthenticator.php on line 17

這裏是我的app.php

$app = new Silex\Application(['debug' => true]); 

$app['security.firewalls'] = array(
    'main' => array(
     'guard' => array(
      'authenticators' => array(
       'app.token_authenticator' 
      ), 

      // Using more than 1 authenticator, you must specify 
      // which one is used as entry point. 
      // 'entry_point' => 'app.token_authenticator', 
     ), 
     // configure where your users come from. Hardcode them, or load them from somewhere 
     // http://silex.sensiolabs.org/doc/providers/security.html#defining-a-custom-user-provider 
     'users' => array(
     //raw password = foo 
      'test' => array('ROLE_USER', '$2y$10$3i9/lVd8UOFIJ6PAMFt8gu3/r5g0qeCJvoSlLCsvMTythye19F77a'), 
     ), 
     // 'anonymous' => true 
    ), 
); 

$app['app.token_authenticator'] = function ($app) { 
    return new App\Security\TokenAuthenticator($app['security.encoder_factory']); 
}; 

$app->register(new Silex\Provider\SecurityServiceProvider()); 

return $app; 

TokenAuthenticator相同的例子。我如何使用實現App\Security\EncoderFactoryInterface的參數來配置此服務?你能幫我嗎 ?

+0

只是一個快速的出手,你可以嘗試添加了'''使用的Symfony \分量\安全\核心\編碼器\ EncoderFactoryInterface'''你TokenAuthenticator的開始.php文件?看來這個接口的命名空間丟失了 – mTorres

回答

0

使用語句丟失:

use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;