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