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

Core/REST/Server/Input/Parser/SortClause/Field.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Server\Input\Parser\SortClause;
8
9 use eZ\Publish\API\Repository\Values\Content\Query;
10 use eZ\Publish\Core\REST\Common\Input\BaseParser;
11 use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
12 use eZ\Publish\Core\REST\Common\Exceptions;
13 use eZ\Publish\API\Repository\Values\Content\Query\SortClause\Field as FieldSortClause;
14
15 class Field extends BaseParser
16 {
25 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
26 {
27 if (!isset($data['Field'])) {
28 throw new Exceptions\Parser("The <Field> sort clause doesn't exist in the input structure");
29 }
30
31 if (!is_array($data['Field'])) {
32 throw new Exceptions\Parser('The <Field> sort clause has missing arguments: contentTypeIdentifier, fieldDefinitionIdentifier');
33 }
34
35 $data['Field'] = $this->normalizeData($data['Field']);
36
37 $direction = isset($data['Field']['direction']) ? $data['Field']['direction'] : null;
38
39 if (!in_array($direction, [Query::SORT_ASC, Query::SORT_DESC])) {
40 throw new Exceptions\Parser('Invalid direction format in <Field> sort clause');
41 }
42
43 if (isset($data['Field']['identifier'])) {
44 if (false === strpos($data['Field']['identifier'], '/')) {
45 throw new Exceptions\Parser('<Field> sort clause parameter "identifier" value has to be in "contentTypeIdentifier/fieldDefinitionIdentifier" format');
46 }
47
48 list($contentTypeIdentifier, $fieldDefinitionIdentifier) = explode('/', $data['Field']['identifier'], 2);
49 } else {
50 if (!isset($data['Field']['contentTypeIdentifier'])) {
51 throw new Exceptions\Parser('<Field> sort clause have missing parameter "contentTypeIdentifier"');
52 }
53 if (!isset($data['Field']['fieldDefinitionIdentifier'])) {
54 throw new Exceptions\Parser('<Field> sort clause have missing parameter "fieldDefinitionIdentifier"');
55 }
56
57 $contentTypeIdentifier = $data['Field']['contentTypeIdentifier'];
58 $fieldDefinitionIdentifier = $data['Field']['fieldDefinitionIdentifier'];
59 }
60
61 return new FieldSortClause($contentTypeIdentifier, $fieldDefinitionIdentifier, $direction);
62 }
63
72 private function normalizeData($data)
73 {
74 $normalizedData = [];
75
76 foreach ($data as $key => $value) {
77 if ('#text' === $key) {
78 $key = 'direction';
79 }
80
81 $normalizedData[trim($key, '_')] = $value;
82 }
83
84 return $normalizedData;
85 }
86 }
eZ\Publish\API\Repository\Values\Content\Query\SortClause\Field
Sets sort direction on a field value for a content query.
Definition: API/Repository/Values/Content/Query/SortClause/Field.php:26
eZ\Publish\API\Repository\Values\Content\Query
This class is used to perform a Content query.
Definition: API/Repository/Values/Content/Query.php:15
eZ\Publish\API\Repository\Values\Content\Query\SORT_DESC
const SORT_DESC
Definition: API/Repository/Values/Content/Query.php:18
eZ\Publish\API\Repository\Values\Content\Query\SORT_ASC
const SORT_ASC
Definition: API/Repository/Values/Content/Query.php:16
eZ\Publish\Core\REST\Common\Input\BaseParser
Definition: BaseParser.php:12
eZ\Publish\Core\REST\Common\Input\ParsingDispatcher
Parsing dispatcher.
Definition: ParsingDispatcher.php:15
eZ\Publish\Core\REST\Server\Input\Parser\SortClause\Field
Definition: Core/REST/Server/Input/Parser/SortClause/Field.php:16
eZ\Publish\Core\REST\Server\Input\Parser\SortClause\Field\normalizeData
normalizeData($data)
Normalize passed Field Sort Clause data by making both xml and json parameters to have same names (by...
Definition: Core/REST/Server/Input/Parser/SortClause/Field.php:72
eZ\Publish\Core\REST\Server\Input\Parser\SortClause\Field\parse
parse(array $data, ParsingDispatcher $parsingDispatcher)
Parse input structure for Field sort clause.
Definition: Core/REST/Server/Input/Parser/SortClause/Field.php:25
eZ\Publish\Core\REST\Common\Exceptions
Definition: Core/REST/Common/Exceptions/ForbiddenException.php:7
eZ\Publish\Core\REST\Server\Input\Parser\SortClause
Definition: DataKeyValueObjectClass.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.