|
Perforce Chronicle 2012.2/486814
API Documentation
|
Provides convenient access to acl facilities from controllers. More...
Public Member Functions | |
| check ($resource, $privilege=null, P4Cms_User $user=null, $msg=null, P4Cms_Acl $acl=null) | |
| Verify that the user is allowed access to the given resource/privilege, throws an exception if not allowed. | |
| getAcl () | |
| Get the ACL instance in use by this helper. | |
| isAllowed ($resource, $privilege=null, P4Cms_User $user=null, P4Cms_Acl $acl=null) | |
| Determine if the user is allowed access to the given resource/privilege. | |
| preDispatch () | |
| Provide easy access to the helper from the controller. | |
| setAcl (P4Cms_Acl $acl) | |
| Set the ACL instance to use. | |
Protected Attributes | |
| $_acl = null | |
Provides convenient access to acl facilities from controllers.
| P4Cms_Controller_Action_Helper_Acl::check | ( | $ | resource, |
| $ | privilege = null, |
||
| P4Cms_User $ | user = null, |
||
| $ | msg = null, |
||
| P4Cms_Acl $ | acl = null |
||
| ) |
Verify that the user is allowed access to the given resource/privilege, throws an exception if not allowed.
| P4Cms_Acl_Resource | string | $resource | the resource to verify access to. |
| P4Cms_Acl_Privilege | string | null | $privilege | the privilege to verify access to. |
| P4Cms_User | null | $user | optional - the user to check access for defaults to the current active user. |
| string | null | $msg | optional - custom message for thrown P4Cms_AccessDeniedException exception. |
| P4Cms_Acl | null | $acl | optional - the acl to check access against. |
| P4Cms_AccessDeniedException | if user is not allowed access to the resource. |
{
if (!$this->isAllowed($resource, $privilege, $user, $acl)) {
throw new P4Cms_AccessDeniedException(
$msg ?: "You do not have permission to: $privilege/$resource."
);
}
}
| P4Cms_Controller_Action_Helper_Acl::getAcl | ( | ) |
Get the ACL instance in use by this helper.
| P4Cms_Acl_Exception | if no acl has been set. |
{
if (!$this->_acl instanceof P4Cms_Acl) {
throw new P4Cms_Acl_Exception(
"Cannot get acl. No acl has been set."
);
}
return $this->_acl;
}
| P4Cms_Controller_Action_Helper_Acl::isAllowed | ( | $ | resource, |
| $ | privilege = null, |
||
| P4Cms_User $ | user = null, |
||
| P4Cms_Acl $ | acl = null |
||
| ) |
Determine if the user is allowed access to the given resource/privilege.
| P4Cms_Acl_Resource | string | $resource | the resource to verify access to. |
| P4Cms_Acl_Privilege | string | null | $privilege | the privilege to verify access to. |
| P4Cms_User | null | $user | optional - the user to check access for defaults to the current active user. |
| P4Cms_Acl | null | $acl | optional - the acl to check access against. |
{
$acl = $acl ?: $this->getAcl();
$user = $user ?: P4Cms_User::fetchActive();
return $user->isAllowed($resource, $privilege, $acl);
}
| P4Cms_Controller_Action_Helper_Acl::preDispatch | ( | ) |
Provide easy access to the helper from the controller.
{
$this->getActionController()->acl = $this;
}
| P4Cms_Controller_Action_Helper_Acl::setAcl | ( | P4Cms_Acl $ | acl | ) |
Set the ACL instance to use.
| P4Cms_Acl | $acl | the acl instance to use. |
{
$this->_acl = $acl;
}
P4Cms_Controller_Action_Helper_Acl::$_acl = null [protected] |