[!!!][TASK] Extbase: Remove preparsing of queries
[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\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Extbase\Persistence\QueryInterface;
19
20 /**
21 * Filters node-tuples based on the outcome of a binary operation.
22 *
23 * For any comparison, operand2 always evaluates to a scalar value. In contrast,
24 * operand1 may evaluate to an array of values (for example, the value of a multi-valued
25 * property), in which case the comparison is separately performed for each element
26 * of the array, and the Comparison constraint is satisfied as a whole if the
27 * comparison against any element of the array is satisfied.
28 *
29 * If operand1 and operand2 evaluate to values of different property types, the
30 * value of operand2 is converted to the property type of the value of operand1.
31 * If the type conversion fails, the query is invalid.
32 *
33 * If operator is not supported for the property type of operand1, the query is invalid.
34 *
35 * If operand1 evaluates to null (for example, if the operand evaluates the value
36 * of a property which does not exist), the constraint is not satisfied.
37 *
38 * The OPERATOR_EQUAL_TO operator is satisfied only if the value of operand1
39 * equals the value of operand2.
40 *
41 * The OPERATOR_NOT_EQUAL_TO operator is satisfied unless the value of
42 * operand1 equals the value of operand2.
43 *
44 * The OPERATOR_LESSS_THAN operator is satisfied only if the value of
45 * operand1 is ordered before the value of operand2.
46 *
47 * The OPERATOR_LESS_THAN_OR_EQUAL_TO operator is satisfied unless the value
48 * of operand1 is ordered after the value of operand2.
49 *
50 * The OPERATOR_GREATER_THAN operator is satisfied only if the value of
51 * operand1 is ordered after the value of operand2.
52 *
53 * The OPERATOR_GREATER_THAN_OR_EQUAL_TO operator is satisfied unless the
54 * value of operand1 is ordered before the value of operand2.
55 *
56 * The OPERATOR_LIKE operator is satisfied only if the value of operand1
57 * matches the pattern specified by the value of operand2, where in the pattern:
58 * the character "%" matches zero or more characters, and
59 * the character "_" (underscore) matches exactly one character, and
60 * the string "\x" matches the character "x", and
61 * all other characters match themselves.
62 */
63 class Comparison implements ComparisonInterface
64 {
65 /**
66 * @var PropertyValueInterface
67 */
68 protected $operand1;
69
70 /**
71 * @var int
72 */
73 protected $operator;
74
75 /**
76 * @var mixed
77 */
78 protected $operand2;
79
80 /**
81 * @var string
82 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
83 */
84 protected $parameterIdentifier;
85
86 /**
87 * Constructs this Comparison instance
88 *
89 * @param PropertyValueInterface $operand1
90 * @param int $operator one of QueryInterface::OPERATOR_*
91 * @param mixed $operand2
92 */
93 public function __construct(PropertyValueInterface $operand1, $operator, $operand2)
94 {
95 $this->operand1 = $operand1;
96 $this->operator = $operator;
97 $this->operand2 = $operand2;
98 }
99
100 /**
101 * Gets the first operand.
102 *
103 * @return PropertyValueInterface the operand; non-null
104 */
105 public function getOperand1()
106 {
107 return $this->operand1;
108 }
109
110 /**
111 * Gets the operator.
112 *
113 * @return string One of QueryInterface::OPERATOR_*
114 */
115 public function getOperator()
116 {
117 $operator = $this->operator;
118
119 if ($this->getOperand2() === null) {
120 if ($operator === QueryInterface::OPERATOR_EQUAL_TO) {
121 $operator = QueryInterface::OPERATOR_EQUAL_TO_NULL;
122 } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) {
123 $operator = QueryInterface::OPERATOR_NOT_EQUAL_TO_NULL;
124 }
125 }
126
127 return $operator;
128 }
129
130 /**
131 * Gets the second operand.
132 *
133 * @return mixed the operand; non-null
134 */
135 public function getOperand2()
136 {
137 return $this->operand2;
138 }
139
140 /**
141 * @param string $parameterIdentifier
142 * @return void
143 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
144 */
145 public function setParameterIdentifier($parameterIdentifier)
146 {
147 GeneralUtility::logDeprecatedFunction();
148 $this->parameterIdentifier = $parameterIdentifier;
149 }
150
151 /**
152 * @return string
153 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
154 */
155 public function getParameterIdentifier()
156 {
157 GeneralUtility::logDeprecatedFunction();
158 return $this->parameterIdentifier;
159 }
160
161 /**
162 * Fills an array with the names of all bound variables in the constraints
163 *
164 * @param array &$boundVariables
165 * @return void
166 */
167 public function collectBoundVariableNames(&$boundVariables)
168 {
169 }
170 }