1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\URL\Query; |
8
|
|
|
|
9
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotImplementedException; |
10
|
|
|
use eZ\Publish\API\Repository\Values\URL\Query\Criterion; |
11
|
|
|
use eZ\Publish\Core\Persistence\Database\SelectQuery; |
12
|
|
|
|
13
|
|
|
class CriteriaConverter |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Criterion handlers. |
17
|
|
|
* |
18
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\URL\Query\CriterionHandler[] |
19
|
|
|
*/ |
20
|
|
|
protected $handlers; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Construct from an optional array of Criterion handlers. |
24
|
|
|
* |
25
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\URL\Query\CriterionHandler[] $handlers |
26
|
|
|
*/ |
27
|
|
|
public function __construct(array $handlers = []) |
28
|
|
|
{ |
29
|
|
|
$this->handlers = $handlers; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Adds handler. |
34
|
|
|
* |
35
|
|
|
* @param \eZ\Publish\Core\Persistence\Legacy\URL\Query\CriterionHandler $handler |
36
|
|
|
*/ |
37
|
|
|
public function addHandler(CriterionHandler $handler) |
38
|
|
|
{ |
39
|
|
|
$this->handlers[] = $handler; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Generic converter of criteria into query fragments. |
44
|
|
|
* |
45
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotImplementedException if Criterion is not applicable to its target |
46
|
|
|
* |
47
|
|
|
* @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query |
48
|
|
|
* @param \eZ\Publish\API\Repository\Values\URL\Query\Criterion $criterion |
49
|
|
|
* @return \eZ\Publish\Core\Persistence\Database\Expression|string |
50
|
|
|
*/ |
51
|
|
|
public function convertCriteria(SelectQuery $query, Criterion $criterion) |
52
|
|
|
{ |
53
|
|
|
foreach ($this->handlers as $handler) { |
54
|
|
|
if ($handler->accept($criterion)) { |
55
|
|
|
return $handler->handle($this, $query, $criterion); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
throw new NotImplementedException( |
60
|
|
|
'No visitor available for: ' . get_class($criterion) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|