Exemplo n.º 1
0
 /**
  * Parse input structure
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     if (!array_key_exists('module', $data)) {
         throw new Exceptions\Parser("Missing 'module' attribute for PolicyCreate.");
     }
     if (!array_key_exists('function', $data)) {
         throw new Exceptions\Parser("Missing 'function' attribute for PolicyCreate.");
     }
     $policyCreate = $this->roleService->newPolicyCreateStruct($data['module'], $data['function']);
     // @todo XSD says that limitations is mandatory,
     // but polices can be created without limitations
     if (array_key_exists('limitations', $data)) {
         if (!is_array($data['limitations'])) {
             throw new Exceptions\Parser("Invalid format for 'limitations' in PolicyCreate.");
         }
         if (!isset($data['limitations']['limitation']) || !is_array($data['limitations']['limitation'])) {
             throw new Exceptions\Parser("Invalid format for 'limitations' in PolicyCreate.");
         }
         foreach ($data['limitations']['limitation'] as $limitationData) {
             $policyCreate->addLimitation($this->parserTools->parseLimitation($limitationData));
         }
     }
     return $policyCreate;
 }
Exemplo n.º 2
0
 /**
  * Instantiates a policy create class.
  *
  * @param string $module
  * @param string $function
  *
  * @return \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct
  */
 public function newPolicyCreateStruct($module, $function)
 {
     return $this->service->newPolicyCreateStruct($module, $function);
 }
Exemplo n.º 3
0
 /**
  * Add new policies to the $role Role.
  *
  * @param \eZ\Publish\API\Repository\Values\User\Role $role
  * @param \eZ\Publish\API\Repository\RoleService $roleService
  * @param array $policy
  */
 private function addPolicy(Role $role, RoleService $roleService, array $policy)
 {
     $policyCreateStruct = $roleService->newPolicyCreateStruct($policy['module'], $policy['function']);
     if (array_key_exists('limitations', $policy)) {
         foreach ($policy['limitations'] as $limitation) {
             $limitationObject = $this->createLimitation($roleService, $limitation);
             $policyCreateStruct->addLimitation($limitationObject);
         }
     }
     $roleService->addPolicy($role, $policyCreateStruct);
 }