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

Core/REST/Server/Input/Parser/Criterion/LogicalOperator.php
Go to the documentation of this file.
1 <?php
2
7 declare(strict_types=1);
8
9 namespace eZ\Publish\Core\REST\Server\Input\Parser\Criterion;
10
11 use Exception;
12 use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
13 use eZ\Publish\Core\REST\Server\Input\Parser\Criterion;
14
18 class LogicalOperator extends Criterion
19 {
31 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
32 {
33 throw new Exception('@todo implement');
34 }
35
41 protected function getFlattenedCriteriaData(array $criteriaByType): array
42 {
43 if ($this->isZeroBasedArray($criteriaByType)) {
44 $oldFormat = $criteriaByType;
45 $criteriaByType = $this->normalizeCriteriaByType($criteriaByType);
46 @trigger_error(
47 sprintf(
48 'REST View: Passing criteria as a list of objects to a logical operator is deprecated ' .
49 'and will cause Bad Request error in eZ Platform 3.0. Instead of "%s" provide "%s"',
50 json_encode($oldFormat),
51 json_encode($criteriaByType)
52 ),
53 E_USER_DEPRECATED
54 );
55 }
56
57 $criteria = [];
58 foreach ($criteriaByType as $type => $criterion) {
59 if (!is_array($criterion) || !$this->isZeroBasedArray($criterion)) {
60 $criterion = [$criterion];
61 }
62
63 foreach ($criterion as $criterionElement) {
64 $criteria[] = [
65 'type' => $type,
66 'data' => $criterionElement,
67 ];
68 }
69 }
70
71 return $criteria;
72 }
73
81 protected function isZeroBasedArray(array $value): bool
82 {
83 reset($value);
84
85 return empty($value) || key($value) === 0;
86 }
87
111 private function normalizeCriteriaByType(array $criterionList): array
112 {
113 $criteriaByType = [];
114 foreach ($criterionList as $criterion) {
115 foreach ($criterion as $criterionType => $value) {
116 if (!isset($criteriaByType[$criterionType])) {
117 $criteriaByType[$criterionType] = [];
118 }
119
120 $criteriaByType[$criterionType][] = $value;
121 }
122 }
123
124 return $criteriaByType;
125 }
126 }
eZ\Publish\Core\REST\Common\Input\ParsingDispatcher
Parsing dispatcher.
Definition: ParsingDispatcher.php:15
eZ\Publish\Core\REST\Server\Input\Parser\Criterion\LogicalOperator
Parser for LogicalOperator Criterion.
Definition: Core/REST/Server/Input/Parser/Criterion/LogicalOperator.php:19
eZ\Publish\Core\REST\Server\Input\Parser\Criterion\LogicalOperator\normalizeCriteriaByType
normalizeCriteriaByType(array $criterionList)
Normalize list of criteria to be provided as the expected criterion type to its value map.
Definition: Core/REST/Server/Input/Parser/Criterion/LogicalOperator.php:111
eZ\Publish\Core\REST\Server\Input\Parser\Criterion\LogicalOperator\isZeroBasedArray
isZeroBasedArray(array $value)
Checks if the given $value is zero based.
Definition: Core/REST/Server/Input/Parser/Criterion/LogicalOperator.php:81
eZ\Publish\Core\REST\Server\Input\Parser\Criterion\LogicalOperator\getFlattenedCriteriaData
getFlattenedCriteriaData(array $criteriaByType)
Definition: Core/REST/Server/Input/Parser/Criterion/LogicalOperator.php:41
eZ\Publish\Core\REST\Server\Input\Parser\Criterion\LogicalOperator\parse
parse(array $data, ParsingDispatcher $parsingDispatcher)
Parses input structure to a Criterion object.
Definition: Core/REST/Server/Input/Parser/Criterion/LogicalOperator.php:31
eZ\Publish\Core\REST\Server\Input\Parser\Criterion
Parser for ViewInput.
Definition: Core/REST/Server/Input/Parser/Criterion.php:17
eZ\Publish\Core\REST\Server\Input\Parser\Criterion
Definition: Core/REST/Server/Input/Parser/Criterion/Ancestor.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.