Chris@0
|
1 <?php
|
Chris@0
|
2 /*
|
Chris@0
|
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
Chris@0
|
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
Chris@0
|
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
Chris@0
|
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
Chris@0
|
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
Chris@0
|
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
Chris@0
|
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
Chris@0
|
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
Chris@0
|
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
Chris@0
|
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
Chris@0
|
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Chris@0
|
14 *
|
Chris@0
|
15 * This software consists of voluntary contributions made by many individuals
|
Chris@0
|
16 * and is licensed under the MIT license. For more information, see
|
Chris@0
|
17 * <http://www.doctrine-project.org>.
|
Chris@0
|
18 */
|
Chris@0
|
19
|
Chris@0
|
20 namespace Doctrine\Common\Collections\Expr;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * Comparison of a field with a value by the given operator.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @author Benjamin Eberlei <kontakt@beberlei.de>
|
Chris@0
|
26 * @since 2.3
|
Chris@0
|
27 */
|
Chris@0
|
28 class Comparison implements Expression
|
Chris@0
|
29 {
|
Chris@12
|
30 const EQ = '=';
|
Chris@12
|
31 const NEQ = '<>';
|
Chris@12
|
32 const LT = '<';
|
Chris@12
|
33 const LTE = '<=';
|
Chris@12
|
34 const GT = '>';
|
Chris@12
|
35 const GTE = '>=';
|
Chris@12
|
36 const IS = '='; // no difference with EQ
|
Chris@12
|
37 const IN = 'IN';
|
Chris@12
|
38 const NIN = 'NIN';
|
Chris@12
|
39 const CONTAINS = 'CONTAINS';
|
Chris@12
|
40 const MEMBER_OF = 'MEMBER_OF';
|
Chris@12
|
41 const STARTS_WITH = 'STARTS_WITH';
|
Chris@12
|
42 const ENDS_WITH = 'ENDS_WITH';
|
Chris@0
|
43 /**
|
Chris@0
|
44 * @var string
|
Chris@0
|
45 */
|
Chris@0
|
46 private $field;
|
Chris@0
|
47
|
Chris@0
|
48 /**
|
Chris@0
|
49 * @var string
|
Chris@0
|
50 */
|
Chris@0
|
51 private $op;
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@0
|
54 * @var Value
|
Chris@0
|
55 */
|
Chris@0
|
56 private $value;
|
Chris@0
|
57
|
Chris@0
|
58 /**
|
Chris@0
|
59 * @param string $field
|
Chris@0
|
60 * @param string $operator
|
Chris@0
|
61 * @param mixed $value
|
Chris@0
|
62 */
|
Chris@0
|
63 public function __construct($field, $operator, $value)
|
Chris@0
|
64 {
|
Chris@0
|
65 if ( ! ($value instanceof Value)) {
|
Chris@0
|
66 $value = new Value($value);
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@0
|
69 $this->field = $field;
|
Chris@0
|
70 $this->op = $operator;
|
Chris@0
|
71 $this->value = $value;
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 /**
|
Chris@0
|
75 * @return string
|
Chris@0
|
76 */
|
Chris@0
|
77 public function getField()
|
Chris@0
|
78 {
|
Chris@0
|
79 return $this->field;
|
Chris@0
|
80 }
|
Chris@0
|
81
|
Chris@0
|
82 /**
|
Chris@0
|
83 * @return Value
|
Chris@0
|
84 */
|
Chris@0
|
85 public function getValue()
|
Chris@0
|
86 {
|
Chris@0
|
87 return $this->value;
|
Chris@0
|
88 }
|
Chris@0
|
89
|
Chris@0
|
90 /**
|
Chris@0
|
91 * @return string
|
Chris@0
|
92 */
|
Chris@0
|
93 public function getOperator()
|
Chris@0
|
94 {
|
Chris@0
|
95 return $this->op;
|
Chris@0
|
96 }
|
Chris@0
|
97
|
Chris@0
|
98 /**
|
Chris@0
|
99 * {@inheritDoc}
|
Chris@0
|
100 */
|
Chris@0
|
101 public function visit(ExpressionVisitor $visitor)
|
Chris@0
|
102 {
|
Chris@0
|
103 return $visitor->walkComparison($this);
|
Chris@0
|
104 }
|
Chris@0
|
105 }
|