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

CriterionVisitorDispatcher.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Search\Elasticsearch\Content;
8
9 use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
10 use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
11 use RuntimeException;
12
18 class CriterionVisitorDispatcher
19 {
23 const CONTEXT_QUERY = 'query';
24
28 const CONTEXT_FILTER = 'filter';
29
35 protected $contextMethodMap = [
36 self::CONTEXT_QUERY => 'visitQuery',
37 self::CONTEXT_FILTER => 'visitFilter',
38 ];
39
45 protected $visitors = [];
46
52 public function __construct(array $visitors = [])
53 {
54 foreach ($visitors as $visitor) {
55 $this->addVisitor($visitor);
56 }
57 }
58
64 public function addVisitor(CriterionVisitor $visitor)
65 {
66 $this->visitors[] = $visitor;
67 }
68
80 public function dispatch(Criterion $criterion, $context, array $languageFilter = [])
81 {
82 if (!isset($this->contextMethodMap[$context])) {
83 throw new RuntimeException(
84 "Given context '{$context}' is not recognized"
85 );
86 }
87
88 foreach ($this->visitors as $visitor) {
89 if ($visitor->canVisit($criterion)) {
90 return $visitor->{ $this->contextMethodMap[$context] }($criterion, $this, $languageFilter);
91 }
92 }
93
94 throw new NotImplementedException(
95 'No visitor available for: ' . get_class($criterion) . ' with operator ' . $criterion->operator
96 );
97 }
98 }
eZ\Publish\API\Repository\Exceptions\NotImplementedException
This Exception is thrown if a feature has not been implemented intentionally.
Definition: API/Repository/Exceptions/NotImplementedException.php:15
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion.php:15
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher
Dispatches Criterion objects to a visitor depending on the query context.
Definition: CriterionVisitorDispatcher.php:19
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher\__construct
__construct(array $visitors=[])
Construct from optional visitor array.
Definition: CriterionVisitorDispatcher.php:52
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher\CONTEXT_QUERY
const CONTEXT_QUERY
Query visiting context.
Definition: CriterionVisitorDispatcher.php:23
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher\addVisitor
addVisitor(CriterionVisitor $visitor)
Adds visitor.
Definition: CriterionVisitorDispatcher.php:64
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher\dispatch
dispatch(Criterion $criterion, $context, array $languageFilter=[])
Map field value to a proper Elasticsearch representation.
Definition: CriterionVisitorDispatcher.php:80
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher\CONTEXT_FILTER
const CONTEXT_FILTER
Filter visiting context.
Definition: CriterionVisitorDispatcher.php:28
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher\$visitors
$visitors
Definition: CriterionVisitorDispatcher.php:45
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher\$contextMethodMap
$contextMethodMap
Definition: CriterionVisitorDispatcher.php:35
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor
Visits the criterion tree into a hash representation of Elasticsearch query/filter AST.
Definition: CriterionVisitor.php:19
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion/Ancestor.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.