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.
Автор: Mark Scherer
Показать файл Открыть проект

Открытые методы

Метод Описание
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.
public hasRole ( mixed $expectedRole, mixed | null $providedRoles = null ) : boolean
$expectedRole mixed
$providedRoles mixed | null
Результат boolean Success

hasRoles() публичный Метод

You can either require one of the roles (default), or you can require all roles to match.
public hasRoles ( mixed $expectedRoles, boolean $oneRoleIsEnough = true, mixed | null $providedRoles = null ) : boolean
$expectedRoles mixed
$oneRoleIsEnough boolean (if all $roles have to match instead of just one)
$providedRoles mixed | null
Результат boolean Success

id() публичный Метод

This can be used anywhere to check if a user is logged in.
public id ( ) : mixed
Результат mixed User id if existent, null otherwise.

isMe() публичный Метод

This check can be used to tell if a record that belongs to some user is the current logged in user
public isMe ( string | integer $userId ) : boolean
$userId string | integer
Результат boolean

roles() публичный Метод

It will return the single role for single role setup, and a flat list of roles for multi role setup.
public roles ( ) : array
Результат array Array of roles

user() публичный Метод

Get the user data of the current session.
public user ( string | null $key = null ) : mixed
$key string | null Key in dot syntax.
Результат mixed Data