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


PHP Acl::inheritsResource方法代码示例

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


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

示例1: 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

示例2: restrictRoute

 /**
  * @param Acl $acl
  * @param $restriction
  * @param RoleRole $role
  * @param RouteResource $resource
  */
 protected function restrictRoute(Acl $acl, $restriction, RoleRole $role = null, RouteResource $resource = null)
 {
     if (is_null($resource)) {
         return $acl->{$restriction}($role, $resource);
     }
     $func = function ($route, array $names) use(&$func, $acl, $resource, $restriction, $role) {
         if (!count($names)) {
             throw new \DomainException("Names could not be empty");
         }
         if (!$route instanceof SimpleRouteStack) {
             if ($route instanceof \Iterator) {
                 $routes = $route;
             } else {
                 return;
             }
         } else {
             $routes = $route->getRoutes();
         }
         foreach ($routes as $name => $route) {
             $routeNames = array_merge($names, array($name));
             $parentResource = new RouteResource(join('/', $names));
             $childResource = new RouteResource(join('/', $routeNames));
             if (!$acl->hasResource($childResource)) {
                 $acl->addResource($childResource, $parentResource);
             }
             if ($acl->hasResource($resource) && $acl->inheritsResource($childResource, $resource)) {
                 $acl->{$restriction ? 'allow' : 'deny'}($role, $childResource);
             }
             if ($route instanceof SimpleRouteStack) {
                 $func($route->getRoutes(), $routeNames);
             }
         }
     };
     $firstPart = $resource->getFirstPart();
     if (!$acl->hasResource($firstPart)) {
         $acl->addResource(new RouteResource($firstPart), null);
     }
     $func($this->routeStack->getRoute($firstPart), array($firstPart));
     return $acl->{$restriction ? 'allow' : 'deny'}($role, $resource);
 }
开发者ID:spalax,项目名称:zf2-simple-acl,代码行数:46,代码来源:AclService.php


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