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
파일 보기 프로젝트 열기: dereuromark/cakephp-tinyauth

공개 메소드들

메소드 설명
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