Пример #1
0
    /**
     * Sets up ACL
     *
     * @return Zend_Acl
     */
    protected function _getAcl()
    {
        $acl = new \Zend\Acl\Acl();

        $acl->addRole(new Role\GenericRole('guest'));
        $acl->addRole(new Role\GenericRole('member'), 'guest');
        $acl->addRole(new Role\GenericRole('admin'), 'member');
        $acl->addRole(new Role\GenericRole('special'), 'member');

        $acl->addResource(new Resource\GenericResource('guest_foo'));
        $acl->addResource(new Resource\GenericResource('member_foo'), 'guest_foo');
        $acl->addResource(new Resource\GenericResource('admin_foo', 'member_foo'));
        $acl->addResource(new Resource\GenericResource('special_foo'), 'member_foo');

        $acl->allow('guest', 'guest_foo');
        $acl->allow('member', 'member_foo');
        $acl->allow('admin', 'admin_foo');
        $acl->allow('special', 'special_foo');
        $acl->allow('special', 'admin_foo', 'read');

        return array('acl' => $acl, 'role' => 'special');
    }
Пример #2
0
<?php

require_once '../SimplOn/Utilities/Acl/Acl.php';
require_once '../SimplOn/Utilities/Acl/Role.php';
require_once '../SimplOn/Utilities/Acl/Resource.php';
require_once '../SimplOn/Utilities/Acl/Role/GenericRole.php';
require_once '../SimplOn/Utilities/Acl/Resource/GenericResource.php';
require_once '../SimplOn/Utilities/Acl/Role/Registry.php';
$acl = new Zend\Acl\Acl();
$acl->addRole(new Zend\Acl\Role\GenericRole('guest'))->addRole(new Zend\Acl\Role\GenericRole('member'))->addRole(new Zend\Acl\Role\GenericRole('admin'));
$parents = array('guest', 'member', 'admin');
$acl->addRole(new Zend\Acl\Role\GenericRole('someUser'), $parents);
$acl->addResource(new Zend\Acl\Resource\GenericResource('someResource'));
$acl->deny('guest', 'someResource');
$acl->allow('member', 'someResource');
echo $acl->isAllowed('someUser', 'someResource') ? 'allowed' : 'denied';