-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAggregate.php
More file actions
57 lines (49 loc) · 1.57 KB
/
Aggregate.php
File metadata and controls
57 lines (49 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\Solr\Query\Common\CriterionVisitor;
use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface;
use Ibexa\Contracts\Solr\Query\CriterionVisitor;
/**
* Visits the criterion tree into a Solr query.
*/
class Aggregate extends CriterionVisitor
{
/**
* Array of available visitors.
*
* @var iterable<\Ibexa\Contracts\Solr\Query\CriterionVisitor>
*/
protected iterable $visitors;
/**
* Construct from optional visitor array.
*
* @param iterable<\Ibexa\Contracts\Solr\Query\CriterionVisitor> $visitors
*/
public function __construct(iterable $visitors)
{
$this->visitors = $visitors;
}
/**
* Check if visitor is applicable to current criterion.
*/
public function canVisit(CriterionInterface $criterion): bool
{
return true;
}
/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException
*/
public function visit(CriterionInterface $criterion, ?CriterionVisitor $subVisitor = null): string
{
foreach ($this->visitors as $visitor) {
if ($visitor->canVisit($criterion)) {
return $visitor->visit($criterion, $this);
}
}
throw new NotImplementedException('No visitor available for: ' . $criterion::class);
}
}