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])
파일 보기 프로젝트 열기: xpressengine/xpressengine 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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