|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Cubiche package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) Cubiche |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace Cubiche\Infrastructure\Repository\Doctrine\ODM\MongoDB\Query; |
|
12
|
|
|
|
|
13
|
|
|
use Cubiche\Core\Comparable\CallbackComparator; |
|
14
|
|
|
use Cubiche\Core\Comparable\Comparator; |
|
15
|
|
|
use Cubiche\Core\Comparable\MultiComparator; |
|
16
|
|
|
use Cubiche\Core\Comparable\ReverseComparator; |
|
17
|
|
|
use Cubiche\Core\Comparable\SelectorComparator; |
|
18
|
|
|
use Cubiche\Core\Visitor\Visitor; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Comparator Visitor Class. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Karel Osorio Ramírez <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class ComparatorVisitor extends Visitor |
|
26
|
|
|
{ |
|
27
|
|
|
use VisitorTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param QueryBuilder $queryBuilder |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(QueryBuilder $queryBuilder) |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct(); |
|
35
|
|
|
|
|
36
|
|
|
$this->queryBuilder = $queryBuilder; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
|
|
public function visitComparator(Comparator $comparator) |
|
43
|
|
|
{ |
|
44
|
|
|
throw $this->notSupportedException($comparator); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
public function visitReverseComparator(ReverseComparator $comparator) |
|
51
|
|
|
{ |
|
52
|
|
|
$reverse = $comparator->comparator()->reverse(); |
|
|
|
|
|
|
53
|
|
|
if ($reverse instanceof ReverseComparator) { |
|
54
|
|
|
throw $this->notSupportedException($comparator); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $reverse->accept($this); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function visitCallbackComparator(CallbackComparator $comparator) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->notSupportedException($comparator); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
|
|
public function visitMultiComparator(MultiComparator $comparator) |
|
72
|
|
|
{ |
|
73
|
|
|
$comparator->firstComparator()->accept($this); |
|
74
|
|
|
$comparator->secondComparator()->accept($this); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
|
|
public function visitSelectorComparator(SelectorComparator $comparator) |
|
81
|
|
|
{ |
|
82
|
|
|
$field = $this->createField($comparator->selector()); |
|
|
|
|
|
|
83
|
|
|
$this->queryBuilder->sort($field->name(), $comparator->direction()->value()); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.