当前位置: 首页>>代码示例>>PHP>>正文


PHP Acl::hasResource方法代码示例

本文整理汇总了PHP中Zend\Permissions\Acl\Acl::hasResource方法的典型用法代码示例。如果您正苦于以下问题:PHP Acl::hasResource方法的具体用法?PHP Acl::hasResource怎么用?PHP Acl::hasResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Permissions\Acl\Acl的用法示例。


在下文中一共展示了Acl::hasResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initAcl

 public function initAcl(MvcEvent $e)
 {
     //Creamos el objeto ACL
     $acl = new Acl();
     //Incluimos la lista de roles y permisos, nos devuelve un array
     $roles = (require 'config/autoload/acl.roles.php');
     foreach ($roles as $role => $resources) {
         //Indicamos que el rol será genérico
         $role = new \Zend\Permissions\Acl\Role\GenericRole($role);
         //Añadimos el rol al ACL
         $acl->addRole($role);
         //Recorremos los recursos o rutas permitidas
         foreach ($resources["allow"] as $resource) {
             //Si el recurso no existe lo añadimos
             if (!$acl->hasResource($resource)) {
                 $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resource));
             }
             //Permitimos a ese rol ese recurso
             $acl->allow($role, $resource);
         }
         foreach ($resources["deny"] as $resource) {
             //Si el recurso no existe lo añadimos
             if (!$acl->hasResource($resource)) {
                 $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resource));
             }
             //Denegamos a ese rol ese recurso
             $acl->deny($role, $resource);
         }
     }
     //Establecemos la lista de control de acceso
     $e->getViewModel()->acl = $acl;
 }
开发者ID:patkings,项目名称:ejemploZF2,代码行数:32,代码来源:Module.php

示例2: testBuildCanAcceptXMLAsString

 public function testBuildCanAcceptXMLAsString()
 {
     $content = file_get_contents(__DIR__ . '/fixtures/test.xml');
     $this->object = new AclBuilder(new StringType($content), $this->acl);
     $this->assertTrue($this->object->build());
     $this->assertTrue($this->acl->hasRole('guest'));
     $this->assertTrue($this->acl->hasResource('logout'));
     $this->assertTrue($this->acl->isAllowed('guest', 'login'));
     $this->assertTrue($this->acl->isAllowed('user', null, 'GET'));
 }
开发者ID:chippyash,项目名称:zend-acl-xml-builder,代码行数:10,代码来源:AclBuilderTest.php

示例3: _load

 private function _load()
 {
     if ($this->loaded == false) {
         // Add roles
         $config = $this->serviceLocator->get('config');
         if (isset($config['acl']['role_providers'])) {
             $roles = [];
             foreach ($config['acl']['role_providers'] as $class => $options) {
                 /** @var \Acl\Provider\Role\ProviderInterface $roleProvider */
                 $roleProvider = $this->serviceLocator->get($class);
                 $roles = $roles + $roleProvider->getRoles();
             }
             foreach ($roles as $role) {
                 /** @var \Acl\Entity\Role $role */
                 $this->acl->addRole($role, $role->getParents());
             }
         }
         // Add resources
         if (isset($config['acl']['resource_providers'])) {
             foreach ($config['acl']['resource_providers'] as $class => $options) {
                 /** @var \Acl\Provider\Resource\ProviderInterface $resourceProvider */
                 $resourceProvider = $this->serviceLocator->get($class);
                 $resources = $resourceProvider->getResources();
                 if ($resources) {
                     foreach ($resources as $r) {
                         if (!$this->acl->hasResource($r)) {
                             $this->acl->addResource($r);
                         }
                     }
                 }
             }
         }
         // Add rules
         if (isset($config['acl']['rule_providers'])) {
             $rules = [];
             foreach ($config['acl']['rule_providers'] as $class => $options) {
                 /** @var \Acl\Provider\Rule\ProviderInterface $ruleProvider */
                 $ruleProvider = $this->serviceLocator->get($class);
                 $rules = $rules + $ruleProvider->getRules();
             }
             foreach ($rules as $rule) {
                 /** @var \Acl\Entity\Rule $rule */
                 if ($rule->allow) {
                     $this->acl->allow($rule->obj_id, $rule->resource, $rule->privilege);
                 } else {
                     $this->acl->deny($rule->obj_id, $rule->resource, $rule->privilege);
                 }
             }
         }
         $this->loaded = true;
     }
 }
开发者ID:hoangpt,项目名称:nextcms,代码行数:52,代码来源:Acl.php

示例4: loadPrivilege

 public function loadPrivilege()
 {
     if (!$this->acl || !$this->acl instanceof \Zend\Permissions\Acl\Acl) {
         return null;
     }
     $userService = $this->getServiceLocator()->get('User\\Service\\User');
     /*@var $userService \User\Service\User */
     if (!$userService->hasIdentity()) {
         return null;
     }
     $user = $userService->getUser();
     if (in_array($user->getRole(), [\User\Model\User::ROLE_ADMIN, \User\Model\User::ROLE_SUPERADMIN, \User\Model\User::ROLE_GUEST])) {
         return null;
     }
     $dependence = $this->acl->getDependencies();
     $resources = null;
     if ($resources) {
         foreach ($resources as $resource) {
             if ($this->acl->hasResource($resource['resource'])) {
                 $this->acl->allow($user->getRole(), $resource['resource'], $resource['privilege']);
                 if (isset($dependence['/' . str_replace(':', '/', $resource['resource']) . '/' . $resource['privilege']])) {
                     foreach ($dependence['/' . str_replace(':', '/', $resource['resource']) . '/' . $resource['privilege']] as $depen) {
                         $arr = explode('/', $depen);
                         if (count($arr) == 4) {
                             if ($this->acl->hasResource($arr[1] . ':' . $arr[2])) {
                                 $this->acl->allow($user->getRole(), $arr[1] . ':' . $arr[2], $arr[3]);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this->acl;
 }
开发者ID:NguyenQuiDuong,项目名称:Funixtest,代码行数:35,代码来源:Authorize.php

示例5: hasResource

 /**
  * @param string|\Zend\Permissions\Acl\Resource\ResourceInterface $resource
  * @return bool|void
  */
 public function hasResource($resource)
 {
     if (is_null($this->acl)) {
         $this->init();
     }
     return $this->acl->hasResource($resource);
 }
开发者ID:spalax,项目名称:zf2-simple-acl,代码行数:11,代码来源:AclService.php

示例6: autenticaAction

 /**
  * autentica o usuário
  */
 public function autenticaAction()
 {
     if ($this->getRequest()->isPost()) {
         $this->adapter->setOptions(array('object_manager' => Conn::getConn(), 'identity_class' => 'MyClasses\\Entities\\AclUsuario', 'identity_property' => 'login', 'credential_property' => 'senha'));
         $this->adapter->setIdentityValue($this->getRequest()->getPost('login'));
         $this->adapter->setCredentialValue(sha1($this->getRequest()->getPost('senha')));
         $result = $this->auth->authenticate($this->adapter);
         if ($result->isValid()) {
             $equipes = $result->getIdentity()->getEquipes();
             $acl = new Acl();
             $acl->addRole(new Role($equipes[0]->getPerfil()));
             $recursos = $equipes[0]->getRecursos();
             foreach ($recursos as $recurso) {
                 if (!$acl->hasResource($recurso->getRecurso())) {
                     /* echo "add recurso: ".
                        $perfil->getPerfil().", ".
                        $recurso->getRecurso()->getRecurso().", ".
                        $recurso->getPermissao(); */
                     $acl->addResource(new Resource($recurso->getRecurso()));
                     $acl->allow($equipes[0]->getPerfil(), $recurso->getRecurso());
                 }
             }
             $this->auth->getStorage()->write(array($result->getIdentity(), $equipes[0]->getPerfil(), $acl));
             $this->layout()->id = $result->getIdentity()->getId();
             $this->layout()->nome = $result->getIdentity()->getNome();
             return new ViewModel(array('nome' => $result->getIdentity()->getNome()));
         } else {
             return new ViewModel(array('erro' => array_pop($result->getMessages())));
         }
     }
 }
开发者ID:Jorgeley,项目名称:Real-State,代码行数:34,代码来源:IndexController.php

示例7: addAclResource

 /**
  * @param Acl $acl
  * @param $resource
  */
 protected function addAclResource(ZendAcl $acl, AclResource $resource)
 {
     if (!$acl->hasResource($resource->getResource())) {
         $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resource->getResource()));
     }
     return $this;
 }
开发者ID:fousheezy,项目名称:auth,代码行数:11,代码来源:Acl.php

示例8: getAcl

 /**
  * getAcl - This cannot be called before resources are parsed
  *
  * @param string $resourceId resourceId
  * @param string $providerId  @deprecated No Longer Required - providerId
  *
  * @return Acl
  */
 public function getAcl($resourceId, $providerId)
 {
     if (!isset($this->acl)) {
         $this->buildAcl();
     }
     /* resources privileges
            we load the every time so they maybe updated dynamically
        */
     $resources = $this->getResources($resourceId, $providerId);
     foreach ($resources as $resource) {
         if (!$this->acl->hasResource($resource)) {
             $this->acl->addResource($resource, $resource->getParentResource());
         }
         $privileges = $resource->getPrivileges();
         if (!empty($privileges)) {
             foreach ($privileges as $privilege) {
                 if (!$this->acl->hasResource($privilege)) {
                     $this->acl->addResource($privilege, $resource);
                 }
             }
         }
     }
     // get only for resources
     $rules = $this->getRules($resources);
     /** @var AclRule $aclRule */
     foreach ($rules as $aclRule) {
         if ($aclRule->getRule() == AclRule::RULE_ALLOW) {
             $this->acl->allow($aclRule->getRoleId(), $aclRule->getResourceId(), $aclRule->getPrivileges(), $aclRule->getAssertion());
         } elseif ($aclRule->getRule() == AclRule::RULE_DENY) {
             $this->acl->deny($aclRule->getRoleId(), $aclRule->getResourceId(), $aclRule->getPrivileges(), $aclRule->getAssertion());
         }
     }
     return $this->acl;
 }
开发者ID:reliv,项目名称:rcm-user,代码行数:42,代码来源:AuthorizeService.php

示例9: createService

 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config.helper')->get('acl');
     $acl = new Acl();
     foreach ($config['roles'] as $role => $parents) {
         if (empty($parents)) {
             $parents = null;
         }
         $role = new GenericRole($role);
         $acl->addRole($role, $parents);
     }
     foreach ($config['resources'] as $permission => $controllers) {
         foreach ($controllers as $controller => $actions) {
             if (!$acl->hasResource($controller)) {
                 $acl->addResource(new GenericResource($controller));
             }
             foreach ($actions as $action => $role) {
                 if ($action == '*') {
                     $action = null;
                 }
                 if ($permission == 'allow') {
                     $acl->allow($role, $controller, $action);
                 } elseif ($permission == 'deny') {
                     $acl->deny($role, $controller, $action);
                 } else {
                     throw new Exception('No valid permission defined: ' . $permission);
                 }
             }
         }
     }
     if (class_exists('Zend\\View\\Helper\\Navigation')) {
         Navigation::setDefaultAcl($acl);
     }
     return $acl;
 }
开发者ID:alex-oleshkevich,项目名称:zf-extras,代码行数:35,代码来源:AclServiceFactory.php

示例10: createService

 /**
  * Create the service using the configuration from the modules config-file
  *
  * @param ServiceLocator $services The ServiceLocator
  *
  * @see \Zend\ServiceManager\FactoryInterface::createService()
  * @return Hybrid_Auth
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     $config = $config['acl'];
     if (!isset($config['roles']) || !isset($config['resources'])) {
         throw new \Exception('Invalid ACL Config found');
     }
     $roles = $config['roles'];
     if (!isset($roles[self::DEFAULT_ROLE])) {
         $roles[self::DEFAULT_ROLE] = '';
     }
     $this->admins = $config['admins'];
     if (!isset($this->admins)) {
         throw new \UnexpectedValueException('No admin-user set');
     }
     $acl = new Acl();
     foreach ($roles as $name => $parent) {
         if (!$acl->hasRole($name)) {
             if (empty($parent)) {
                 $parent = array();
             } else {
                 $parent = explode(',', $parent);
             }
             $acl->addRole(new Role($name), $parent);
         }
     }
     foreach ($config['resources'] as $permission => $controllers) {
         foreach ($controllers as $controller => $actions) {
             if ($controller == 'all') {
                 $controller = null;
             } else {
                 if (!$acl->hasResource($controller)) {
                     $acl->addResource(new Resource($controller));
                 }
             }
             foreach ($actions as $action => $role) {
                 if ($action == 'all') {
                     $action = null;
                 }
                 $assert = null;
                 if (is_array($role)) {
                     $assert = $serviceLocator->get($role['assert']);
                     $role = $role['role'];
                 }
                 $role = explode(',', $role);
                 foreach ($role as $roleItem) {
                     if ($permission == 'allow') {
                         $acl->allow($roleItem, $controller, $action, $assert);
                     } elseif ($permission == 'deny') {
                         $acl->deny($roleItem, $controller, $action, $assert);
                     } else {
                         continue;
                     }
                 }
             }
         }
     }
     return $acl;
 }
开发者ID:krsreenatha,项目名称:php.ug,代码行数:67,代码来源:AclFactory.php

示例11: addResources

 private function addResources(Acl $acl)
 {
     foreach ($this->modules as $module) {
         if (!$acl->hasResource($module)) {
             $acl->addResource(strtolower($module));
         }
     }
 }
开发者ID:omusico,项目名称:zf2-demo,代码行数:8,代码来源:AclFactory.php

示例12: getResourcesACL

 public function getResourcesACL(\Zend\Permissions\Acl\Acl $acl, \Doctrine\ORM\EntityManager $em)
 {
     $repo = $em->getRepository('Security\\Entity\\RecursoSistema');
     foreach ($repo->fetchPairs() as $recurso) {
         $acl->addResource($recurso);
     }
     // carrega os recurso desprotegidos
     foreach ($this->getRecursosDesprotegidos() as $recurso) {
         if (!$acl->hasResource($recurso)) {
             $acl->addResource($recurso);
         }
     }
     return $acl;
 }
开发者ID:ericoautocad,项目名称:module-security-zf2,代码行数:14,代码来源:ACL.php

示例13: initAcl

 /**
  */
 private function initAcl()
 {
     if (!is_null($this->acl)) {
         return;
     }
     $this->acl = new Acl();
     $config = $this->getServiceLocator()->get('Config');
     $roles = $config['acl']['roles'];
     $allResources = array();
     foreach ($roles as $role => $resources) {
         $role = new GenericRole($role);
         $this->acl->addRole($role);
         $allResources = array_merge($resources, $allResources);
         foreach ($resources as $resource) {
             if (!$this->acl->hasResource($resource)) {
                 $this->acl->addResource(new GenericResource($resource));
             }
         }
         foreach ($allResources as $resource) {
             $this->acl->allow($role, $resource);
         }
     }
 }
开发者ID:dsi-agpt,项目名称:minibus,代码行数:25,代码来源:FileAuthService.php

示例14: testResourceInherits

 /**
  * Tests basic Resource inheritance
  *
  * @return void
  */
 public function testResourceInherits()
 {
     $resourceCity = new Resource\GenericResource('city');
     $resourceBuilding = new Resource\GenericResource('building');
     $resourceRoom = new Resource\GenericResource('room');
     $this->_acl->addResource($resourceCity)->addResource($resourceBuilding, $resourceCity->getResourceId())->addResource($resourceRoom, $resourceBuilding);
     $this->assertTrue($this->_acl->inheritsResource($resourceBuilding, $resourceCity, true));
     $this->assertTrue($this->_acl->inheritsResource($resourceRoom, $resourceBuilding, true));
     $this->assertTrue($this->_acl->inheritsResource($resourceRoom, $resourceCity));
     $this->assertFalse($this->_acl->inheritsResource($resourceCity, $resourceBuilding));
     $this->assertFalse($this->_acl->inheritsResource($resourceBuilding, $resourceRoom));
     $this->assertFalse($this->_acl->inheritsResource($resourceCity, $resourceRoom));
     $this->_acl->removeResource($resourceBuilding);
     $this->assertFalse($this->_acl->hasResource($resourceRoom));
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:20,代码来源:AclTest.php

示例15: loadResource

 /**
  * @deprecated this method will be removed in BjyAuthorize 2.0.x
  *
  * @param string[]|\Zend\Permissions\Acl\Resource\ResourceInterface[] $resources
  * @param mixed|null                                                  $parent
  */
 protected function loadResource(array $resources, $parent = null)
 {
     foreach ($resources as $key => $value) {
         if (is_string($key)) {
             $key = new GenericResource($key);
         } elseif (is_int($key)) {
             $key = new GenericResource($value);
         }
         if (is_array($value)) {
             $this->acl->addResource($key, $parent);
             $this->loadResource($value, $key);
         } elseif (!$this->acl->hasResource($key)) {
             $this->acl->addResource($key, $parent);
         }
     }
 }
开发者ID:kristjanAnd,项目名称:SimpleIV,代码行数:22,代码来源:Authorize.php


注:本文中的Zend\Permissions\Acl\Acl::hasResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。