Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Controller_Action_Helper_Acl Class Reference

Provides convenient access to acl facilities from controllers. More...

List of all members.

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

Detailed Description

Provides convenient access to acl facilities from controllers.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

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.

Parameters:
P4Cms_Acl_Resource | string$resourcethe resource to verify access to.
P4Cms_Acl_Privilege | string | null$privilegethe privilege to verify access to.
P4Cms_User | null$useroptional - the user to check access for defaults to the current active user.
string | null$msgoptional - custom message for thrown P4Cms_AccessDeniedException exception.
P4Cms_Acl | null$acloptional - the acl to check access against.
Exceptions:
P4Cms_AccessDeniedExceptionif 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.

Returns:
P4Cms_Acl the acl in use by the helper.
Exceptions:
P4Cms_Acl_Exceptionif 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.

Parameters:
P4Cms_Acl_Resource | string$resourcethe resource to verify access to.
P4Cms_Acl_Privilege | string | null$privilegethe privilege to verify access to.
P4Cms_User | null$useroptional - the user to check access for defaults to the current active user.
P4Cms_Acl | null$acloptional - the acl to check access against.
Returns:
bool true if the user is allowed access; false otherwise.
    {
        $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.

Parameters:
P4Cms_Acl$aclthe acl instance to use.
    {
        $this->_acl = $acl;
    }

Member Data Documentation

P4Cms_Controller_Action_Helper_Acl::$_acl = null [protected]

The documentation for this class was generated from the following file: