Skip to content

Instantly share code, notes, and snippets.

@kaiohken1982
Created November 11, 2013 19:55
Show Gist options
  • Select an option

  • Save kaiohken1982/7419301 to your computer and use it in GitHub Desktop.

Select an option

Save kaiohken1982/7419301 to your computer and use it in GitHub Desktop.
Zend Framework 1 Acl implementation #1
<?php
class My_Acl extends Zend_Acl
{
protected static $_instance = null;
const ROLE_GUEST = 'guest';
const ROLE_MEMBER_STANDARD = 'member-standard';
const ROLE_MEMBER_PREMIUM = 'member-premium';
const ROLE_ADMIN = 'admin';
protected $_roles = array(
self::ROLE_GUEST,
self::ROLE_MEMBER_STANDARD,
self::ROLE_MEMBER_STANDARD => self::ROLE_MEMBER_PREMIUM,
self::ROLE_ADMIN
);
/**
* Returns an instance of My_Acl
*
* Singleton pattern implementation
*
* @return Zend_Auth Provides a fluent interface
*/
public static function getInstance()
{
if (null === self::$_instance) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Singleton pattern implementation makes "clone" unavailable
*
* @return void
*/
protected function __clone()
{}
/**
* Singleton pattern implementation makes "new" unavailable
*
* @return void
*/
protected function __construct()
{
$this->_addRole();
$this->_addResources();
$this->_allow();
}
protected function _addRole()
{
/*$this->addRole(new Zend_Acl_Role('guest'));
$this->addRole(new Zend_Acl_Role('member-standard'));
$this->addRole(new Zend_Acl_Role('member-premium'),'member-standard');
$this->addRole(new Zend_Acl_Role('admin'));*/
foreach($this->_roles as $parent => $role) {
$parent = is_string($parent) ? $parent : null;
$this->addRole(new Zend_Acl_Role($role),$parent);
}
}
protected function _addResources()
{
$this->add(new Zend_Acl_Resource('error'));
$this->add(new Zend_Acl_Resource('index'));
$this->add(new Zend_Acl_Resource('user'));
$this->add(new Zend_Acl_Resource('auth'));
}
protected function _allow()
{
$this->allow('admin','error');
$this->allow('member-standard','error');
$this->allow('guest','error');
$this->allow('admin','auth');
$this->allow('member-standard','auth');
$this->allow('guest','auth');
$this->allow('member-standard','index');
$this->allow('guest','index');
$this->allow('admin','index');
$this->allow('admin','user');
$this->allow('member-standard','user','list',new My_Acl_Assert_CleanIPAssertion());
$this->allow('member-premium','user','edit');
//$this->allow('member-premium','user','add');
$this->allow('member-premium','index','about');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment