1<?php 2 3/* 4 * This file is part of the TYPO3 CMS project. 5 * 6 * It is free software; you can redistribute it and/or modify it under 7 * the terms of the GNU General Public License, either version 2 8 * of the License, or any later version. 9 * 10 * For the full copyright and license information, please read the 11 * LICENSE.txt file that was distributed with this source code. 12 * 13 * The TYPO3 project - inspiring people to share! 14 */ 15 16namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom; 17 18use 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_LESS_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 * @internal only to be used within Extbase, not part of TYPO3 Core API. 63 */ 64class Comparison implements ComparisonInterface 65{ 66 /** 67 * @var PropertyValueInterface 68 */ 69 protected $operand1; 70 71 /** 72 * @var int 73 */ 74 protected $operator; 75 76 /** 77 * @var mixed 78 */ 79 protected $operand2; 80 81 /** 82 * Constructs this Comparison instance 83 * 84 * @param PropertyValueInterface $operand1 85 * @param int $operator one of QueryInterface::OPERATOR_* 86 * @param mixed $operand2 87 */ 88 public function __construct(PropertyValueInterface $operand1, $operator, $operand2) 89 { 90 $this->operand1 = $operand1; 91 $this->operator = $operator; 92 $this->operand2 = $operand2; 93 } 94 95 /** 96 * Gets the first operand. 97 * 98 * @return PropertyValueInterface the operand; non-null 99 */ 100 public function getOperand1() 101 { 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 { 112 $operator = $this->operator; 113 114 if ($this->getOperand2() === null) { 115 if ($operator === QueryInterface::OPERATOR_EQUAL_TO) { 116 $operator = QueryInterface::OPERATOR_EQUAL_TO_NULL; 117 } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) { 118 $operator = QueryInterface::OPERATOR_NOT_EQUAL_TO_NULL; 119 } 120 } 121 122 return $operator; 123 } 124 125 /** 126 * Gets the second operand. 127 * 128 * @return mixed the operand; non-null 129 */ 130 public function getOperand2() 131 { 132 return $this->operand2; 133 } 134 135 /** 136 * Fills an array with the names of all bound variables in the constraints 137 * 138 * @param array $boundVariables 139 */ 140 public function collectBoundVariableNames(&$boundVariables) 141 { 142 } 143} 144