本文整理汇总了PHP中Zend_Acl::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Acl::add方法的具体用法?PHP Zend_Acl::add怎么用?PHP Zend_Acl::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Acl
的用法示例。
在下文中一共展示了Zend_Acl::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* (non-PHPdoc)
* @see Zend_Application_Resource_ResourceAbstract#init()
*/
public function init()
{
$this->_acl = new Zend_Acl();
// static roles
$this->_acl->addRole(new Zend_Acl_Role('all'));
$this->_acl->addRole(new Zend_Acl_Role('anonymous'), 'all');
$this->_acl->addRole(new Zend_Acl_Role('identified'), 'all');
// dinamic roles
foreach ($this->_roles as $roleName) {
if (!$this->_acl->hasRole($roleName)) {
$this->_acl->addRole(new Zend_Acl_Role($roleName), 'identified');
}
}
// var_dump($this->_resources);exit;
// rules
foreach ($this->_resources as $module => $grants) {
$module = strtolower($module);
$this->_acl->add(new Zend_Acl_Resource($module));
foreach ($grants as $controller => $grant) {
$controller = strtolower($controller);
foreach ($grant as $action => $roles) {
$resource = $controller . self::RESOURCE_SEPARATOR . $action;
foreach (explode(',', $roles) as $role) {
if (!empty($role)) {
$this->_acl->allow(trim($role), $module, $resource);
}
}
}
}
}
Zend_Registry::set('acl', $this->_acl);
return $this->_acl;
}
示例2: __construct
public function __construct()
{
$acl = new Zend_Acl();
//ролі
$acl->addRole(new Zend_Acl_Role('guest'));
//user наслідує усі параметри guest
$acl->addRole(new Zend_Acl_Role('user'), 'guest');
$acl->addRole(new Zend_Acl_Role('admin'));
//ресурси - доступні контролери
$acl->add(new Zend_Acl_Resource('users'));
$acl->add(new Zend_Acl_Resource('index'));
//дозвіл
$acl->deny();
//заборонити доступ всім
$acl->allow('admin', null);
//дозволити доступ admin-у до всього
//users це resource - контролер
// далі $privilege - екшн
$acl->allow('guest', 'users', array('login', 'registration', 'confirm'));
$acl->allow('guest', 'index');
$acl->allow('user', 'users', array('logout'));
$acl->deny('user', 'users', array('login', 'registration'));
//глобальний доступ до змінної
//щоб використати у видах
Zend_Registry::set('acl', $acl);
/*
//isAllowed() - чи має доступ $role до $resourse і $privilege
//$resource - контролер
//$privilege - екшн
if($acl->isAllowed($role, $resource, $privilege)){
} */
}
示例3: __construct
/** The constuctor for the class
* @access public
* @param Zend_Acl $aclData
* @param $roleName string
* @return void
**/
public function __construct(Zend_Acl $aclData, $roleName = 'public')
{
$this->_roleName = $roleName;
if (NULL !== $aclData) {
$this->setAcl($aclData);
}
$front = Zend_Controller_Front::getInstance();
/** If an error handler hasn't been setup in the front controller, setup one */
if (!$front->getParam('noErrorHandler') && !$front->hasPlugin('Zend_Controller_Plugin_ErrorHandler')) {
// Register with stack index of 100
$front->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(), 100);
}
/** Allow error handler in the acl */
$errorHandler = Zend_Controller_Front::getInstance()->getPlugin('Zend_Controller_Plugin_ErrorHandler');
$defaultErrorModule = $errorHandler->getErrorHandlerModule();
$defaultErrorController = $errorHandler->getErrorHandlerController();
$defaultErrorAction = $errorHandler->getErrorHandlerAction();
if (NULL !== $defaultErrorModule && $defaultErrorModule != 'default') {
if (!$this->getAcl()->has($defaultErrorModule)) {
require_once 'Zend/Acl/Resource.php';
$this->_acl->add(new Zend_Acl_Resource($defaultErrorModule));
$this->_acl->add(new Zend_Acl_Resource($defaultErrorModule . ':' . $defaultErrorController, $defaultErrorModule));
$this->_acl->allow($this->_roleName, $defaultErrorModule . ':' . $defaultErrorController, $defaultErrorAction);
}
} else {
if (!$this->getAcl()->has($defaultErrorController)) {
$this->_acl->add(new Zend_Acl_Resource($defaultErrorController));
}
$this->_acl->allow($this->_roleName, $defaultErrorController, $defaultErrorAction);
}
$this->setDeniedAction('denied', $defaultErrorController, $defaultErrorModule);
}
示例4: init
/**
* Hook into action controller initialization
*
* @return void
*/
public function init()
{
// add resource for this controller
$controller = $this->getAction()->getRequest()->getControllerName();
if (!$this->_acl->has($controller)) {
$this->_acl->add(new Zend_Acl_Resource($controller));
}
}
示例5: preDispatch
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
try {
$module = $request->getModuleName();
if ($module == 'admin') {
$moduleList = new Zend_Session_Namespace('moduleList');
$userInfo = new Zend_Session_Namespace('userInfo');
$module = $moduleList->module;
$allowed_module = $userInfo->module_list;
//generating all resources
$acl = new Zend_Acl();
//generating user permission
$acl->addRole(new Zend_Acl_Role('admin'));
$acl->addRole(new Zend_Acl_Role('anonymous'));
$acl->add(new Zend_Acl_Resource('index'));
$acl->add(new Zend_Acl_Resource('ajax'));
$acl->allow('admin', 'index');
$acl->allow('admin', 'ajax');
if (!empty($module)) {
foreach ($module as $value) {
if (!$acl->has($value['controller'])) {
$acl->add(new Zend_Acl_Resource($value['controller']));
}
if (in_array($value['id'], $allowed_module)) {
if ($value['action'] != null) {
$acl->allow('admin', $value['controller'], $value['action']);
} else {
$acl->allow('admin', $value['controller']);
}
}
}
}
//allowing anonymous user to get into the login page
$acl->allow('anonymous', 'index', 'index');
$acl->allow('anonymous', 'index', 'login');
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
$role = 'admin';
} else {
$role = 'anonymous';
}
$controller = $request->controller;
$action = $request->action;
if (!$acl->isAllowed($role, $controller, $action)) {
$request->setModuleName('admin');
$request->setControllerName('error');
$request->setActionName('acl');
$request->setParam('type', 1);
}
}
} catch (Zend_Acl_Exception $e) {
$request->setModuleName('admin');
$request->setControllerName('error');
$request->setActionName('acl');
$request->setParam('type', 2);
}
}
示例6: __construct
public function __construct()
{
$acl = new Zend_Acl();
$acl->addRole(new Zend_Acl_Role('guest'));
$acl->addRole(new Zend_Acl_Role('admin'));
$acl->add(new Zend_Acl_Resource('admin'));
$acl->add(new Zend_Acl_Resource('index'));
$acl->deny();
$acl->allow('admin', null);
$acl->allow('guest', 'admin', array('login'));
$acl->allow('guest', 'index');
Zend_Registry::set('acl', $acl);
}
示例7: _setupAcl
/**
* Setup the ACL
*
* @return void
*/
protected function _setupAcl()
{
if (!$this->_acl->has($this)) {
$this->_acl->add($this);
$this->_setupPrivileges();
}
}
示例8: checkAccess
public function checkAccess(Zend_Controller_Request_Abstract $request)
{
$resource = new User_Model_Acl_Resource();
$resource->getPrivileges($request);
if (!$resource->privileges || !$resource->resource_id) {
//error in getting resource privileges or nobody is allowed access, deny access and redirect to forbidden
return false;
}
$acl = new Zend_Acl();
$acl->add(new Zend_Acl_Resource($resource->resource_id));
foreach ($resource->privileges as $key => $privilege) {
if (!$acl->hasRole($privilege["role_id"])) {
$acl->addRole(new Zend_Acl_Role($privilege["role_id"]));
$acl->allow($privilege["role_id"], $resource->resource_id);
}
}
$authorization = Zend_Auth::getInstance();
if ($authorization->hasIdentity()) {
$user = $authorization->getIdentity();
if ($acl->hasRole($user['role_id']) && $acl->isAllowed($user['role_id'], $resource->resource_id)) {
//role has access
return true;
}
//user role does not have access to this resource
return false;
} else {
$aclrole = new User_Model_Acl_Role();
$aclrole->getDefaultRole();
if (!$aclrole->default_role || !$acl->hasRole($aclrole->default_role) || !$acl->isAllowed($aclrole->default_role, $resource->resource_id)) {
//redirect to login
return false;
}
}
return true;
}
示例9: setAcl
public function setAcl(Zend_Acl $acl)
{
if (!$acl->has($this->getResourceId())) {
$acl->add($this)->deny(Model_Role::GUEST, $this, array('view', 'delete'));
}
$this->_acl = $acl;
}
示例10: getAcl
public function getAcl()
{
Zend_Registry::get('log')->info(__METHOD__);
$acl = new Zend_Acl();
$acl->addRole(new Zend_Acl_Role(1));
$acl->add(new Zend_Acl_Resource('As'));
$acl->add(new Zend_Acl_Resource('Bs'));
$acl->add(new Zend_Acl_Resource('A'));
$acl->add(new Zend_Acl_Resource('B'));
$acl->allow(1, 'As');
//$acl->allow(1, 'Bs');
$acl->allow(1, 'A', 'edit', new App_Acl_Assert_ResourceAccess());
$acl->allow(1, 'A', 'edit:all');
$acl->allow(1, 'A', 'delete', new App_Acl_Assert_ResourceAccess());
$acl->allow(1, 'A', 'delete:mine');
return $acl;
}
示例11: addAllResources
/**
* @return void
*/
public function addAllResources()
{
$query = Doctrine_Query::create()->select('c.name, m.name')->from('Model_Entity_Controller c')->leftJoin('c.Module m')->useQueryCache(Kebab_Cache_Query::isEnable());
$resources = $query->execute();
foreach ($resources as $resource) {
parent::add(new Zend_Acl_Resource($resource->Module->name . '_' . $resource->name));
}
}
示例12:
function __construct($class = NULL)
{
$CI =& get_instance();
$CI->load->library('zend');
$CI->zend->load('Zend/Acl');
$CI->zend->load('Zend/Acl/Role');
$CI->zend->load('Zend/Acl/Resource');
$acl = new Zend_Acl();
//Add the Role
$acl->addRole(new Zend_Acl_Role('NU'));
$acl->addRole(new Zend_Acl_Role('memUser'), 'member');
//Add Resource
$acl->add(new Zend_Acl_Resource('users_login'));
$acl->add(new Zend_Acl_Resource('users_profile'), 'users_login');
$acl->allow('member', 'users_login');
$acl->allow('memUser', 'users_profile');
}
示例13: testgetResources
/**
* @group ZF-8468
*/
public function testgetResources()
{
$this->assertEquals(array(), $this->_acl->getResources());
$this->_acl->add(new Zend_Acl_Resource('someResource'));
$this->_acl->add(new Zend_Acl_Resource('someOtherResource'));
$expected = array('someResource', 'someOtherResource');
$this->assertEquals($expected, $this->_acl->getResources());
}
示例14: __construct
public function __construct()
{
$acl = new Zend_Acl();
// добавляем роли
$acl->addRole(new Zend_Acl_Role('guest'));
$acl->addRole(new Zend_Acl_Role('admin'));
// добавляем ресурсы
$acl->add(new Zend_Acl_Resource('sites'));
$acl->add(new Zend_Acl_Resource('index'));
$acl->add(new Zend_Acl_Resource('logs'));
$acl->add(new Zend_Acl_Resource('auth'));
$acl->add(new Zend_Acl_Resource('maps'));
$acl->add(new Zend_Acl_Resource('best'));
$acl->add(new Zend_Acl_Resource('news'));
// если нет роли то все запрещаем
$acl->deny();
// админу по умолчанию разрешено все
$acl->allow('admin', null);
// гостю только контроллер с экшеном для входа
$acl->allow('guest', 'auth', array('index', 'check'));
$acl->allow('guest', 'maps', array('cronmaps'));
$acl->allow('guest', array('module' => 'best', 'controller' => 'news'), array('scan', 'redirect'));
// если надо запретить экшены в разрешенном контроллере
/*$acl->deny('user', 'users', array(
'login', 'registration'
));
*
*/
Zend_Registry::set('acl', $acl);
}
示例15: getAcl
/**
* Get ACL lists
*
* @return Zend_Acl
*/
public function getAcl()
{
if (null === $this->_acl) {
$acl = new Zend_Acl();
$acl->add(new Zend_Acl_Resource('admin'))->add(new Zend_Acl_Resource('kap'))->add(new Zend_Acl_Resource('members'))->addRole(new Zend_Acl_Role('guest'))->addRole(new Zend_Acl_Role('kap'), 'guest')->addRole(new Zend_Acl_Role('admin'), 'kap')->deny()->allow('admin', 'admin')->allow('admin', 'members')->allow('admin', 'kap')->allow('kap', 'kap')->allow('kap', 'members')->allow('guest', 'members', array('index', 'team', 'player', 'turnir', 'old', 'regno'));
$this->_acl = $acl;
}
return $this->_acl;
}