28 static protected $comparators = array(
'==',
'!=',
'%',
'>=',
'>',
'<=',
'<');
37 ^ # Start with first input symbol 39 COMPARATORS # We allow all comparators 40 |\s* # Arbitary spaces 41 |-? # Numbers, possibly with the "minus" symbol in front. 43 (?: # and optionally a dot, followed by some more digits 47 |\'[^\'\\\\]* # single quoted string literals with possibly escaped single quotes 49 \\\\. # escaped character 50 [^\'\\\\]* # unrolled loop following Jeffrey E.F. Friedl 52 |"[^"\\\\]* # double quoted string literals with possibly escaped double quotes 54 \\\\. # escaped character 55 [^"\\\\]* # unrolled loop following Jeffrey E.F. Friedl 101 throw new \TYPO3\CMS\Fluid\Core\Parser\Exception(
'A boolean expression has more than three parts.', 1244201848);
108 $this->leftSide = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
109 $this->rightSide = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
110 $this->comparator = NULL;
112 if ($childNode instanceof \
TYPO3\CMS\
Fluid\Core\Parser\SyntaxTree\
TextNode && !preg_match(str_replace(
'COMPARATORS', implode(
'|', self::$comparators), self::$booleanExpressionTextNodeCheckerRegularExpression), $childNode->getText())) {
114 $this->comparator = NULL;
119 if ($this->comparator !== NULL) {
121 $this->rightSide->addChildNode($childNode);
125 $explodedString = explode($this->comparator, $childNode->getText());
126 if (isset($explodedString[0]) && trim($explodedString[0]) !==
'') {
127 $value = trim($explodedString[0]);
128 if (is_numeric($value)) {
131 $this->leftSide->addChildNode(
new \
TYPO3\CMS\
Fluid\Core\Parser\SyntaxTree\
TextNode(preg_replace(
'/(^[\'"]|[\'"]$)/',
'', $value)));
134 if (isset($explodedString[1]) && trim($explodedString[1]) !==
'') {
135 $value = trim($explodedString[1]);
136 if (is_numeric($value)) {
139 $this->rightSide->addChildNode(
new \
TYPO3\CMS\
Fluid\Core\Parser\SyntaxTree\
TextNode(preg_replace(
'/(^[\'"]|[\'"]$)/',
'', $value)));
144 $this->leftSide->addChildNode($childNode);
148 if ($this->comparator === NULL) {
190 public function evaluate(\
TYPO3\CMS\
Fluid\Core\Rendering\RenderingContextInterface $renderingContext) {
191 if ($this->comparator !== NULL) {
192 return self::evaluateComparator($this->comparator, $this->leftSide->evaluate($renderingContext), $this->rightSide->evaluate($renderingContext));
194 $value = $this->syntaxTreeNode->evaluate($renderingContext);
195 return self::convertToBoolean($value);
222 if (is_object($evaluatedLeftSide) || is_object($evaluatedRightSide)) {
223 return ($evaluatedLeftSide === $evaluatedRightSide);
225 return ($evaluatedLeftSide == $evaluatedRightSide);
228 if (is_object($evaluatedLeftSide) || is_object($evaluatedRightSide)) {
229 return ($evaluatedLeftSide !== $evaluatedRightSide);
231 return ($evaluatedLeftSide != $evaluatedRightSide);
234 if (!self::isComparable($evaluatedLeftSide, $evaluatedRightSide)) {
237 return (
boolean) ((int)$evaluatedLeftSide % (
int)$evaluatedRightSide);
239 if (!self::isComparable($evaluatedLeftSide, $evaluatedRightSide)) {
242 return $evaluatedLeftSide > $evaluatedRightSide;
244 if (!self::isComparable($evaluatedLeftSide, $evaluatedRightSide)) {
247 return $evaluatedLeftSide >= $evaluatedRightSide;
249 if (!self::isComparable($evaluatedLeftSide, $evaluatedRightSide)) {
252 return $evaluatedLeftSide < $evaluatedRightSide;
254 if (!self::isComparable($evaluatedLeftSide, $evaluatedRightSide)) {
257 return $evaluatedLeftSide <= $evaluatedRightSide;
259 throw new \TYPO3\CMS\Fluid\Core\Parser\Exception(
'Comparator "' .
$comparator .
'" is not implemented.', 1244234398);
273 static protected function isComparable($evaluatedLeftSide, $evaluatedRightSide) {
274 if ((is_null($evaluatedLeftSide) || is_string($evaluatedLeftSide))
275 && is_string($evaluatedRightSide)) {
278 if (is_bool($evaluatedLeftSide) || is_null($evaluatedLeftSide)) {
281 if (is_object($evaluatedLeftSide) && is_object($evaluatedRightSide)) {
284 if ((is_string($evaluatedLeftSide) || is_resource($evaluatedLeftSide) || is_numeric($evaluatedLeftSide))
285 && (is_string($evaluatedRightSide) || is_resource($evaluatedRightSide) || is_numeric($evaluatedRightSide))) {
288 if (is_array($evaluatedLeftSide) && is_array($evaluatedRightSide)) {
302 if (strpos($string, $comparator) !== FALSE) {
318 if (is_bool($value)) {
322 if (is_integer($value) || is_float($value)) {
323 return !empty($value);
326 if (is_numeric($value)) {
327 return ($value != 0);
330 if (is_string($value)) {
331 return (!empty($value) && strtolower($value) !==
'false');
333 if (is_array($value) || (is_object($value) && $value instanceof \Countable)) {
334 return (
bool) count($value);
336 if (is_object($value)) {
getComparatorFromString($string)
evaluate(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
static convertToBoolean($value)
static evaluateComparator($comparator, $evaluatedLeftSide, $evaluatedRightSide)
static $booleanExpressionTextNodeCheckerRegularExpression
__construct(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode)
static isComparable($evaluatedLeftSide, $evaluatedRightSide)