コード例 #1
0
ファイル: AclService.php プロジェクト: spalax/zf2-simple-acl
 /**
  * @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);
 }
コード例 #2
0
 public function testGetRouteByName()
 {
     $stack = new SimpleRouteStack();
     $route = new TestAsset\DummyRoute();
     $stack->addRoute('foo', $route);
     $this->assertEquals($route, $stack->getRoute('foo'));
 }