72c68da7a32c01a22acc5e6ec2b67d6dfc9398a8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Qom / Comparison.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Extbase\Persistence\QueryInterface;
18
19 /**
20 * Filters node-tuples based on the outcome of a binary operation.
21 *
22 * For any comparison, operand2 always evaluates to a scalar value. In contrast,
23 * operand1 may evaluate to an array of values (for example, the value of a multi-valued
24 * property), in which case the comparison is separately performed for each element
25 * of the array, and the Comparison constraint is satisfied as a whole if the
26 * comparison against any element of the array is satisfied.
27 *
28 * If operand1 and operand2 evaluate to values of different property types, the
29 * value of operand2 is converted to the property type of the value of operand1.
30 * If the type conversion fails, the query is invalid.
31 *
32 * If operator is not supported for the property type of operand1, the query is invalid.
33 *
34 * If operand1 evaluates to null (for example, if the operand evaluates the value
35 * of a property which does not exist), the constraint is not satisfied.
36 *
37 * The OPERATOR_EQUAL_TO operator is satisfied only if the value of operand1
38 * equals the value of operand2.
39 *
40 * The OPERATOR_NOT_EQUAL_TO operator is satisfied unless the value of
41 * operand1 equals the value of operand2.
42 *
43 * The OPERATOR_LESSS_THAN operator is satisfied only if the value of
44 * operand1 is ordered before the value of operand2.
45 *
46 * The OPERATOR_LESS_THAN_OR_EQUAL_TO operator is satisfied unless the value
47 * of operand1 is ordered after the value of operand2.
48 *
49 * The OPERATOR_GREATER_THAN operator is satisfied only if the value of
50 * operand1 is ordered after the value of operand2.
51 *
52 * The OPERATOR_GREATER_THAN_OR_EQUAL_TO operator is satisfied unless the
53 * value of operand1 is ordered before the value of operand2.
54 *
55 * The OPERATOR_LIKE operator is satisfied only if the value of operand1
56 * matches the pattern specified by the value of operand2, where in the pattern:
57 * the character "%" matches zero or more characters, and
58 * the character "_" (underscore) matches exactly one character, and
59 * the string "\x" matches the character "x", and
60 * all other characters match themselves.
61 */
62 class Comparison implements ComparisonInterface
63 {
64 /**
65 * @var PropertyValueInterface
66 */
67 protected $operand1;
68
69 /**
70 * @var int
71 */
72 protected $operator;
73
74 /**
75 * @var mixed
76 */
77 protected $operand2;
78
79 /**
80 * @var string
81 */
82 protected $parameterIdentifier;
83
84 /**
85 * Constructs this Comparison instance
86 *
87 * @param PropertyValueInterface $operand1
88 * @param int $operator one of QueryInterface::OPERATOR_*
89 * @param mixed $operand2
90 */
91 public function __construct(PropertyValueInterface $operand1, $operator, $operand2)
92 {
93 $this->operand1 = $operand1;
94 $this->operator = $operator;
95 $this->operand2 = $operand2;
96 }
97
98 /**
99 * Gets the first operand.
100 *
101 * @return PropertyValueInterface the operand; non-null
102 */
103 public function getOperand1()
104 {
105 return $this->operand1;
106 }
107
108 /**
109 * Gets the operator.
110 *
111 * @return string One of QueryInterface::OPERATOR_*
112 */
113 public function getOperator()
114 {
115 $operator = $this->operator;
116
117 if ($this->getOperand2() === null) {
118 if ($operator === QueryInterface::OPERATOR_EQUAL_TO) {
119 $operator = QueryInterface::OPERATOR_EQUAL_TO_NULL;
120 } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) {
121 $operator = QueryInterface::OPERATOR_NOT_EQUAL_TO_NULL;
122 }
123 }
124
125 return $operator;
126 }
127
128 /**
129 * Gets the second operand.
130 *
131 * @return mixed the operand; non-null
132 */
133 public function getOperand2()
134 {
135 return $this->operand2;
136 }
137
138 /**
139 * @param string $parameterIdentifier
140 * @return void
141 */
142 public function setParameterIdentifier($parameterIdentifier)
143 {
144 $this->parameterIdentifier = $parameterIdentifier;
145 }
146
147 /**
148 * @return string
149 */
150 public function getParameterIdentifier()
151 {
152 return $this->parameterIdentifier;
153 }
154
155 /**
156 * Fills an array with the names of all bound variables in the constraints
157 *
158 * @param array &$boundVariables
159 * @return void
160 */
161 public function collectBoundVariableNames(&$boundVariables)
162 {
163 }
164 }