rendered paste body<?php
class Pvac_Controller_Action_Helper_Acl extends Zend_Controller_Action_Helper_Abstract
{
protected $_action;
protected $_auth;
protected $_acl;
protected $_controllerName;
public function __construct(Zend_View_Interface $view = null,array $options = array())
{
$this->_auth = Zend_Auth::getInstance();
$this->_acl = $options['acl'];
}
/**
* Hook into action controller initialization
* @return void
*/
public function init()
{
$this->_action = $this->getActionController();
// add resource for this controller
$controller = $this->_action->getRequest()->getControllerName();
if(!$this->_acl->has($controller)) {
$this->_acl->add(new Zend_Acl_Resource($controller));
}
}
/**
* Proxy to the underlying Zend_Acl's allow() function.
*
* We use the controller's name as the resource and the
* action name(s) as the privilege(s)
*
* @param Zend_Acl_Role_Interface|string|array $roles
* @param string|array $actions
* @uses Zend_Acl::setRule()
* @return Places_Controller_Action_Helper_Acl Provides a fluent interface
*/
public function allow($roles = null, $actions = null)
{
$resource = $this->_controllerName;
$this->_acl->allow($roles, $resource, $actions);
return $this;
}
/**
* Proxy to the underlying Zend_Acl's deny() function.
*
* We use the controller's name as the resource and the
* action name(s) as the privilege(s)
*
* @param Zend_Acl_Role_Interface|string|array $roles
* @param string|array $actions
* @uses Zend_Acl::setRule()
* @return Places_Controller_Action_Helper_Acl Provides a fluent interface
*/
public function deny($roles = null, $actions = null)
{
$resource = $this->_controllerName;
$this->_acl->allow($roles, $resource, $actions);
return $this;
}
}