Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

PolicyCreate.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Server\Input\Parser;
8
9 use eZ\Publish\Core\REST\Common\Input\BaseParser;
10 use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
11 use eZ\Publish\Core\REST\Common\Input\ParserTools;
12 use eZ\Publish\Core\REST\Common\Exceptions;
13 use eZ\Publish\API\Repository\RoleService;
14
18 class PolicyCreate extends BaseParser
19 {
25 protected $roleService;
26
32 protected $parserTools;
33
40 public function __construct(RoleService $roleService, ParserTools $parserTools)
41 {
42 $this->roleService = $roleService;
43 $this->parserTools = $parserTools;
44 }
45
54 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
55 {
56 if (!array_key_exists('module', $data)) {
57 throw new Exceptions\Parser("Missing 'module' attribute for PolicyCreate.");
58 }
59
60 if (!array_key_exists('function', $data)) {
61 throw new Exceptions\Parser("Missing 'function' attribute for PolicyCreate.");
62 }
63
64 $policyCreate = $this->roleService->newPolicyCreateStruct($data['module'], $data['function']);
65
66 // @todo XSD says that limitations is mandatory,
67 // but polices can be created without limitations
68 if (array_key_exists('limitations', $data)) {
69 if (!is_array($data['limitations'])) {
70 throw new Exceptions\Parser("Invalid format for 'limitations' in PolicyCreate.");
71 }
72
73 if (!isset($data['limitations']['limitation']) || !is_array($data['limitations']['limitation'])) {
74 throw new Exceptions\Parser("Invalid format for 'limitations' in PolicyCreate.");
75 }
76
77 foreach ($data['limitations']['limitation'] as $limitationData) {
78 $policyCreate->addLimitation(
79 $this->parserTools->parseLimitation($limitationData)
80 );
81 }
82 }
83
84 return $policyCreate;
85 }
86 }
eZ\Publish\Core\REST\Common\Input\BaseParser
Definition: BaseParser.php:12
eZ\Publish\Core\REST\Common\Input\ParserTools
Tools object to be used in Input Parsers.
Definition: ParserTools.php:17
eZ\Publish\Core\REST\Common\Input\ParsingDispatcher
Parsing dispatcher.
Definition: ParsingDispatcher.php:15
eZ\Publish\Core\REST\Server\Input\Parser\PolicyCreate
Parser for PolicyCreate.
Definition: PolicyCreate.php:19
eZ\Publish\Core\REST\Server\Input\Parser\PolicyCreate\$parserTools
$parserTools
Definition: PolicyCreate.php:32
eZ\Publish\Core\REST\Server\Input\Parser\PolicyCreate\__construct
__construct(RoleService $roleService, ParserTools $parserTools)
Construct.
Definition: PolicyCreate.php:40
eZ\Publish\Core\REST\Server\Input\Parser\PolicyCreate\parse
parse(array $data, ParsingDispatcher $parsingDispatcher)
Parse input structure.
Definition: PolicyCreate.php:54
eZ\Publish\Core\REST\Server\Input\Parser\PolicyCreate\$roleService
$roleService
Definition: PolicyCreate.php:25
eZ\Publish\API\Repository\RoleService
This service provides methods for managing Roles and Policies.
Definition: API/Repository/RoleService.php:26
eZ\Publish\Core\REST\Common\Exceptions
Definition: Core/REST/Common/Exceptions/ForbiddenException.php:7
eZ\Publish\Core\REST\Server\Input\Parser
Definition: ContentCreate.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.