本文整理汇总了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));
}
示例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);
}