PHP Трейт TinyAuth\Auth\AuthUserTrait
Simply add it at the class file:
trait AuthUserTrait;
But needs
protected function _getUser() }
to be implemented in the using class.
Expects the Role session infos to be either
-
Auth.User.role_id (single) or
-
Auth.User.Role (multi - flat array of roles, or array role data)
and can be adjusted via constants and defined().
Same goes for Right data.
If roles are defined in configuration file (non-db roles setup) the constant
USER_ROLE_KEY has to be defined in
bootstrap.php.
if role key in User model is role_id
define('USER_ROLE_KEY', 'role_id');
Note: This uses AuthComponent internally to work with both stateful and stateless auth.
Показать файл
Открыть проект
Открытые методы
Метод |
Описание |
|
hasRole ( mixed $expectedRole, mixed | null $providedRoles = null ) : boolean |
Check if the current session has this role. |
|
hasRoles ( mixed $expectedRoles, boolean $oneRoleIsEnough = true, mixed | null $providedRoles = null ) : boolean |
Check if the current session has one of these roles. |
|
id ( ) : mixed |
Get the user id of the current session. |
|
isMe ( string | integer $userId ) : boolean |
This check can be used to tell if a record that belongs to some user is the
current logged in user |
|
roles ( ) : array |
Get the role(s) of the current session. |
|
user ( string | null $key = null ) : mixed |
Get the user data of the current session. |
|
Описание методов
hasRole()
публичный Метод
Check if the current session has this role.
hasRoles()
публичный Метод
You can either require one of the roles (default), or you can require all
roles to match.
This can be used anywhere to check if a user is logged in.
public id ( ) : mixed |
Результат |
mixed |
User id if existent, null otherwise. |
This check can be used to tell if a record that belongs to some user is the
current logged in user
It will return the single role for single role setup, and a flat
list of roles for multi role setup.
Get the user data of the current session.