PHP Класс Xpressengine\Permission\PermissionHandler

요청에 맞는 적절한 타입의 permission 객체를 제공해주는 패키지 메인 클래스. ### app binding : xe.permission 으로 바인딩 되어 있음 ### Usage #### register * 권한 등록 php $grant = new Xpressengine\Permission\Grant(); $grant->set('access', 'guest'); $grant->set('create', 'member'); $grant->set('read', 'guest'); $grant->set('update', 'group', ['group_id_1', 'group_id_2']); $grant->add('update', 'user', ['user_id_1', 'user_id_2']); $grant->set('delete', [ 'rating' => 'super', 'group' => ['group_id_1', 'group_id_2'], 'user' => ['user_id_1', 'user_id_2'], ]); 저장소에 등록 app('xe.permission')->register('menu.menu1', $grant); * 제외 php except 메서드를 사용해 특정 사용자의 권한을 제외시킬 수 있다. except 는 사용자 아이디만 등록 되어진다. $grant->except('access', ['user_id_1', 'user_id_2']); #### define permission 은 Illuminate\Auth\Access\Gate 를 통해 사용되어 진다. 권한 검사를 하고자 하는 대상에 맞는 policy class 를 생성하여 등록시켜주어야 한다 php Gate::policy(Menu::class, MenuPolicy::class); policy class 는 Xpressengine\Permission\Policy 를 상속받아 구현한다. 이때 각 action 에 대한 메서드를 작성해야 하며 register 시 등록했던 permission 이름으로 등록된 정보를 가져와야 한다. php Class MenuItemPolicy extend Policy { public function access($user, $menu) { return $this->check($user, $this->get($menu->getNameForPermission()), 'access'); } } #### check 권한에 대한 검사는 policy 에 정의된 메서드명과 같게 action 을 지정하여 그 결과를 반환 받는다. php if (Gate::denies('access', $menu)) { throw new AccessDeniesException(); } else { ... } #### non object check 특정한 객체 없이 permission 이름만으로 권한 검사를 하고자 하는 경우 패키지내에 존재하는 InstancePolicy 를 사용하여 해결할 수 있다. php if (Gate::allows('create', new Instance('instance.name'))) { ... } * Gate 사용에 대한 더 많은 정보를 원한다면 laravel 메뉴얼 을 참고 한다.
Автор: XE Developers ([email protected])
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$repo Xpressengine\Permission\PermissionRepository Repository instance

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

Метод Описание
__construct ( Xpressengine\Permission\PermissionRepository $repo ) PermissionHandler constructor.
destroy ( string $name, string $siteKey = 'default' ) : void Remove from repository
find ( string $name, string $siteKey = 'default' ) : Permission | null Get a permission from repository
findOrNew ( string $name, string $siteKey = 'default' ) : Permission | null Get a permission from repository or generate when not exists
get ( string $name, string $siteKey = 'default' ) : Permission | null Get a permission from repository
getOrNew ( string $name, string $siteKey = 'default' ) : Permission | null Get a permission from repository or generate when not exists
loadBranch ( string $name, string $siteKey = 'default' ) : void 특정 대상이 포함된 하위 권한 정보를 가져와 캐싱 함
move ( Permission $permission, string | null $to = null ) : void Move entity hierarchy to new parent or root
newItem ( ) : Permission Returns new permission instance
register ( string $name, Grant $grant, string $siteKey = 'default' ) : Permission Register permission information

Защищенные методы

Метод Описание
setAncestor ( Permission $permission ) : void Set permission's ancestor to permission

Описание методов

__construct() публичный метод

PermissionHandler constructor.
public __construct ( Xpressengine\Permission\PermissionRepository $repo )
$repo Xpressengine\Permission\PermissionRepository repository instance

destroy() публичный метод

Remove from repository
public destroy ( string $name, string $siteKey = 'default' ) : void
$name string permission name
$siteKey string site key name
Результат void

find() публичный метод

Get a permission from repository
Устаревший: since 3.0.0-beta.2
public find ( string $name, string $siteKey = 'default' ) : Permission | null
$name string permission name
$siteKey string site key name
Результат Permission | null

findOrNew() публичный метод

Get a permission from repository or generate when not exists
Устаревший: since 3.0.0-beta.2
public findOrNew ( string $name, string $siteKey = 'default' ) : Permission | null
$name string permission name
$siteKey string site key name
Результат Permission | null

get() публичный метод

Get a permission from repository
public get ( string $name, string $siteKey = 'default' ) : Permission | null
$name string permission name
$siteKey string site key name
Результат Permission | null

getOrNew() публичный метод

Get a permission from repository or generate when not exists
public getOrNew ( string $name, string $siteKey = 'default' ) : Permission | null
$name string permission name
$siteKey string site key name
Результат Permission | null

loadBranch() публичный метод

특정 대상이 포함된 하위 권한 정보를 가져와 캐싱 함
Устаревший: since 3.0.0-beta.2
public loadBranch ( string $name, string $siteKey = 'default' ) : void
$name string permission name
$siteKey string site key name
Результат void

move() публичный метод

Move entity hierarchy to new parent or root
public move ( Permission $permission, string | null $to = null ) : void
$permission Permission permission instance
$to string | null to prefix
Результат void

newItem() публичный метод

Returns new permission instance
public newItem ( ) : Permission
Результат Permission

register() публичный метод

Register permission information
public register ( string $name, Grant $grant, string $siteKey = 'default' ) : Permission
$name string permission name
$grant Grant grant instance
$siteKey string site key name
Результат Permission

setAncestor() защищенный метод

Set permission's ancestor to permission
protected setAncestor ( Permission $permission ) : void
$permission Permission permission instance
Результат void

Описание свойств

$repo защищенное свойство

Repository instance
protected PermissionRepository,Xpressengine\Permission $repo
Результат Xpressengine\Permission\PermissionRepository