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

ObjectStateCreate.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\ObjectStateService;
14
18 class ObjectStateCreate extends BaseParser
19 {
25 protected $objectStateService;
26
28 protected $parserTools;
29
36 public function __construct(ObjectStateService $objectStateService, ParserTools $parserTools)
37 {
38 $this->objectStateService = $objectStateService;
39 $this->parserTools = $parserTools;
40 }
41
50 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
51 {
52 if (!array_key_exists('identifier', $data)) {
53 throw new Exceptions\Parser("Missing 'identifier' attribute for ObjectStateCreate.");
54 }
55
56 $objectStateCreateStruct = $this->objectStateService->newObjectStateCreateStruct($data['identifier']);
57
58 if (!array_key_exists('priority', $data)) {
59 throw new Exceptions\Parser("Missing 'priority' attribute for ObjectStateCreate.");
60 }
61
62 $objectStateCreateStruct->priority = (int)$data['priority'];
63
64 if (!array_key_exists('defaultLanguageCode', $data)) {
65 throw new Exceptions\Parser("Missing 'defaultLanguageCode' attribute for ObjectStateCreate.");
66 }
67
68 $objectStateCreateStruct->defaultLanguageCode = $data['defaultLanguageCode'];
69
70 if (!array_key_exists('names', $data) || !is_array($data['names'])) {
71 throw new Exceptions\Parser("Missing or invalid 'names' element for ObjectStateCreate.");
72 }
73
74 if (!array_key_exists('value', $data['names']) || !is_array($data['names']['value'])) {
75 throw new Exceptions\Parser("Missing or invalid 'names' element for ObjectStateCreate.");
76 }
77
78 $objectStateCreateStruct->names = $this->parserTools->parseTranslatableList($data['names']);
79
80 // @todo XSD says that descriptions field is mandatory. Does that make sense?
81 if (array_key_exists('descriptions', $data) && is_array($data['descriptions'])) {
82 $objectStateCreateStruct->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']);
83 }
84
85 return $objectStateCreateStruct;
86 }
87 }
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\ObjectStateCreate
Parser for ObjectStateCreate.
Definition: ObjectStateCreate.php:19
eZ\Publish\Core\REST\Server\Input\Parser\ObjectStateCreate\__construct
__construct(ObjectStateService $objectStateService, ParserTools $parserTools)
Construct.
Definition: ObjectStateCreate.php:36
eZ\Publish\Core\REST\Server\Input\Parser\ObjectStateCreate\parse
parse(array $data, ParsingDispatcher $parsingDispatcher)
Parse input structure.
Definition: ObjectStateCreate.php:50
eZ\Publish\Core\REST\Server\Input\Parser\ObjectStateCreate\$objectStateService
$objectStateService
Definition: ObjectStateCreate.php:25
eZ\Publish\Core\REST\Server\Input\Parser\ObjectStateCreate\$parserTools
$parserTools
Definition: ObjectStateCreate.php:28
eZ\Publish\API\Repository\ObjectStateService
Definition: API/Repository/ObjectStateService.php:23
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+.