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