本文整理匯總了PHP中Zend\Permissions\Acl\Acl::getResource方法的典型用法代碼示例。如果您正苦於以下問題:PHP Acl::getResource方法的具體用法?PHP Acl::getResource怎麽用?PHP Acl::getResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Permissions\Acl\Acl
的用法示例。
在下文中一共展示了Acl::getResource方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testResourceAddAndGetOneWithAddResourceMethod
/**
* Ensures that basic addition and retrieval of a single Resource works
*
* @group ZF-1167
*/
public function testResourceAddAndGetOneWithAddResourceMethod()
{
$resourceArea = new Resource\GenericResource('area');
$resource = $this->_acl->addResource($resourceArea)->getResource($resourceArea->getResourceId());
$this->assertTrue($resourceArea === $resource);
$resource = $this->_acl->getResource($resourceArea);
$this->assertTrue($resourceArea === $resource);
}
示例2: initAcl
public function initAcl(MvcEvent $e)
{
$application = $e->getApplication();
$sm = $application->getServiceManager();
$acl = new Acl();
$roles = $sm->get("Application\\Model\\RolesBO");
$recursos = $sm->get("Application\\Model\\RecursosBO");
$rolesRecursos = $sm->get("Application\\Model\\RolesRecursosBO");
$usuarios = $sm->get("Application\\Model\\UsuariosBO");
// Se listan todos los recursos y se los agrega a la ACL
foreach ($recursos->obtenerTodos() as $recurso) {
if (!$acl->hasResource($recurso->getRecursosID())) {
$genericResource = new GenericResource($recurso->getRecursosID());
$acl->addResource($genericResource);
}
}
// Se registra el rol en la ACL
$sesion = new Container("CoreAppSesion");
if (!$acl->hasRole($sesion->user_rol_id)) {
$genericRole = new GenericRole($sesion->user_rol_id);
$acl->addRole($genericRole);
}
$services = $application->getServiceManager();
// obtenemos todos los recuersosque tiene la ACL
foreach ($acl->getResources() as $resource) {
// Obtenemos los recursos disponibles para el rol
foreach ($rolesRecursos->obtenerRecursosPorRol($sesion->user_rol_id) as $recursoAsignado) {
// Si el recurso asignado es el mismo recurso de la ACL lo permitimos
if ($resource == $recursoAsignado->getAppRecursosID()) {
$acl->allow($genericRole, $acl->getResource($resource));
}
}
}
// Si el recurso no esta permitido lo denegamos
foreach ($acl->getResources() as $resource) {
if (!$acl->isAllowed($genericRole, $acl->getResource($resource))) {
$acl->deny($genericRole, $acl->getResource($resource));
}
}
$this->acl = $acl;
}