2016-10-18 12 views
0

は、サイレックス2.0のクラスのユーザーを無効にする必要があります。サイレックス・過負荷クラスのユーザー

Symfony\Component\Security\Core\User; 

私は絶対にどのように表示されません。 私の究極の目標は、メソッドをオーバーロードすることです:

final class User implements AdvancedUserInterface 
{ 
    /** 
    * {@inheritdoc} 
    */ 
    public function getRoles() 
    { 
     return unserialize($this->roles[0]); // work (overload) 
     return $this->roles; // Not work (delete) 
    } 
} 

はあなたにこれを行うにはどのように任意のアイデアをお持ちですか?

ありがとうございました!

+0

このクラスをオーバーライドする際の問題点は何ですか? –

+0

[GitHub](https://github.com/silexphp/Silex/issues/1436)に関する同じ質問 – GromNaN

答えて

1

最終クラスUserは、InMemoryUserProviderでのみ定義されています。

シレックスからこのデータベースを読むには、自分でUserProviderconfigure itをコードする必要があります。

Userクラスを拡張する代わりに、正しい値$rolesをコンストラクタで設定できます。

あなたはドキュメントの例を取っ​​た場合は、この行置き換える必要があります。これにより

return new User($user['username'], $user['password'], explode(',', $user['roles']), true, true, true, true); 

:それ以外の場合は

return new User($user['username'], $user['password'], unserialize($user['roles']), true, true, true, true); 

を、ベストプラクティスは、独自のUserクラスを作成することです。

/** 
* User is the user implementation used by the in-memory user provider. 
* 
* This should not be used for anything else. 
*/ 
関連する問題