このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 次のリビジョン 両方とも次のリビジョン | ||
apricot:ext:user-auth [2020/05/25 09:32] y2sunlight [AuthUserクラス] |
apricot:ext:user-auth [2020/06/08 11:25] tanaka [Authenticatableインターフェース] |
||
---|---|---|---|
行 50: | 行 50: | ||
以下に、Authenticatableインターフェースのコードを示します。 | 以下に、Authenticatableインターフェースのコードを示します。 | ||
- | {{fa> | + | {{fa> |
<code php Authenticatable.php> | <code php Authenticatable.php> | ||
<?php | <?php | ||
行 506: | 行 506: | ||
' | ' | ||
], | ], | ||
- | ] | + | ], |
], | ], | ||
]; | ]; | ||
行 607: | 行 607: | ||
protected static function createInstance() | protected static function createInstance() | ||
{ | { | ||
- | | + | return new Authentication(new User()); |
- | | + | |
} | } | ||
} | } | ||
</ | </ | ||
+ | |||
+ | * createInstance() では、ユーザモデル( User )を使って、Authenticationクラスのシングルトンを生成しています。 | ||
+ | |||
+ | === マルチ認証 === | ||
+ | |||
+ | 同様の方法で別のモデルを使用したAuthenticationクラスのシングルトンも同時に作る事ができます。例えば、Userとは別に、AdminUserクラスやApiUserクラスも認証したいなどの例には実際によく遭遇するかもしれません。このように、Apricotでは潜在的にマルチ認証を想定した実装に仕上げていますが、これはApricotの範囲を超えているので、これ以上は触れないことにします。 | ||
\\ | \\ |