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

LocationCreate.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\LocationService;
14
18 class LocationCreate extends BaseParser
19 {
25 protected $locationService;
26
32 protected $parserTools;
33
40 public function __construct(LocationService $locationService, ParserTools $parserTools)
41 {
42 $this->locationService = $locationService;
43 $this->parserTools = $parserTools;
44 }
45
54 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
55 {
56 if (!array_key_exists('ParentLocation', $data) || !is_array($data['ParentLocation'])) {
57 throw new Exceptions\Parser("Missing or invalid 'ParentLocation' element for LocationCreate.");
58 }
59
60 if (!array_key_exists('_href', $data['ParentLocation'])) {
61 throw new Exceptions\Parser("Missing '_href' attribute for ParentLocation element in LocationCreate.");
62 }
63
64 $locationHrefParts = explode('/', $this->requestParser->parseHref($data['ParentLocation']['_href'], 'locationPath'));
65
66 $locationCreateStruct = $this->locationService->newLocationCreateStruct(
67 array_pop($locationHrefParts)
68 );
69
70 if (array_key_exists('priority', $data)) {
71 $locationCreateStruct->priority = (int)$data['priority'];
72 }
73
74 if (array_key_exists('hidden', $data)) {
75 $locationCreateStruct->hidden = $this->parserTools->parseBooleanValue($data['hidden']);
76 }
77
78 if (array_key_exists('remoteId', $data)) {
79 $locationCreateStruct->remoteId = $data['remoteId'];
80 }
81
82 if (!array_key_exists('sortField', $data)) {
83 throw new Exceptions\Parser("Missing 'sortField' element for LocationCreate.");
84 }
85
86 $locationCreateStruct->sortField = $this->parserTools->parseDefaultSortField($data['sortField']);
87
88 if (!array_key_exists('sortOrder', $data)) {
89 throw new Exceptions\Parser("Missing 'sortOrder' element for LocationCreate.");
90 }
91
92 $locationCreateStruct->sortOrder = $this->parserTools->parseDefaultSortOrder($data['sortOrder']);
93
94 return $locationCreateStruct;
95 }
96 }
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\LocationCreate
Parser for LocationCreate.
Definition: LocationCreate.php:19
eZ\Publish\Core\REST\Server\Input\Parser\LocationCreate\__construct
__construct(LocationService $locationService, ParserTools $parserTools)
Construct.
Definition: LocationCreate.php:40
eZ\Publish\Core\REST\Server\Input\Parser\LocationCreate\$locationService
$locationService
Definition: LocationCreate.php:25
eZ\Publish\Core\REST\Server\Input\Parser\LocationCreate\parse
parse(array $data, ParsingDispatcher $parsingDispatcher)
Parse input structure.
Definition: LocationCreate.php:54
eZ\Publish\Core\REST\Server\Input\Parser\LocationCreate\$parserTools
$parserTools
Definition: LocationCreate.php:32
eZ\Publish\API\Repository\LocationService
Definition: API/Repository/LocationService.php:21
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+.