本文整理匯總了PHP中Nette\Application\UI\PresenterComponentReflection::getAnnotation方法的典型用法代碼示例。如果您正苦於以下問題:PHP PresenterComponentReflection::getAnnotation方法的具體用法?PHP PresenterComponentReflection::getAnnotation怎麽用?PHP PresenterComponentReflection::getAnnotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\Application\UI\PresenterComponentReflection
的用法示例。
在下文中一共展示了PresenterComponentReflection::getAnnotation方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isPresenterAllowed
/**
* @param \Nette\Application\UI\PresenterComponentReflection $element
* @return bool
*/
protected function isPresenterAllowed(\Nette\Application\UI\PresenterComponentReflection $element)
{
$ref = ClassType::from($element->name);
// is not secured
if (!$ref->hasAnnotation('secured')) {
return TRUE;
}
// resource & privilege
$secured = $ref->getAnnotation('secured');
$resource = isset($secured['resource']) ? $secured['resource'] : $ref->getNamespaceName();
$privilege = isset($secured['privilege']) ? $secured['privilege'] : NULL;
if (!parent::isAllowed($resource, $privilege)) {
return FALSE;
}
// roles
if (isset($secured['roles'])) {
$userRoles = $this->getRoles();
$roles = explode(',', $secured['roles']);
array_walk($roles, function (&$val) {
$val = trim($val);
});
if (count(array_intersect($userRoles, $roles)) == 0) {
return FALSE;
}
}
// users
if (isset($secured['users'])) {
$users = explode(',', $secured['users']);
array_walk($users, function (&$val) {
$val = trim($val);
});
$users = (array) $element->getAnnotation('User');
if (in_array($this->getId(), $users)) {
return FALSE;
}
}
return TRUE;
}