コード例 #1
0
ファイル: TernaryExpressionNode.php プロジェクト: typo3/fluid
 /**
  * @param mixed $candidate
  * @param RenderingContextInterface $renderingContext
  * @return mixed
  */
 public static function getTemplateVariableOrValueItself($candidate, RenderingContextInterface $renderingContext)
 {
     $suspect = parent::getTemplateVariableOrValueItself($candidate, $renderingContext);
     if ($suspect === $candidate) {
         return $renderingContext->getTemplateParser()->unquoteString($suspect);
     }
     return $suspect;
 }
コード例 #2
0
 /**
  * @param RenderingContextInterface $renderingContext
  * @param string $expression
  * @param array $matches
  * @return mixed
  */
 public static function evaluateExpression(RenderingContextInterface $renderingContext, $expression, array $matches)
 {
     $parts = preg_split('/([\\?:])/s', $expression);
     $parts = array_map(array(__CLASS__, 'trimPart'), $parts);
     list($check, $then, $else) = $parts;
     $checkResult = Parser\SyntaxTree\BooleanNode::convertToBoolean(parent::getTemplateVariableOrValueItself($check, $renderingContext));
     if ($checkResult) {
         return parent::getTemplateVariableOrValueItself($then, $renderingContext);
     } else {
         return parent::getTemplateVariableOrValueItself($else, $renderingContext);
     }
 }
コード例 #3
0
 /**
  * @param RenderingContextInterface $renderingContext
  * @param string $expression
  * @param array $matches
  * @return integer|float
  */
 public static function evaluateExpression(RenderingContextInterface $renderingContext, $expression, array $matches)
 {
     // Split the expression on all recognized operators
     $matches = array();
     preg_match_all('/([+\\-*\\^\\/\\%]|[a-z0-9\\.]+)/s', $expression, $matches);
     $matches[0] = array_map('trim', $matches[0]);
     // Like the BooleanNode, we dumb down the processing logic to not apply
     // any special precedence on the priority of operators. We simply process
     // them in order.
     $variables = $renderingContext->getVariableProvider()->getAll();
     $result = array_shift($matches[0]);
     $result = parent::getTemplateVariableOrValueItself($result, $renderingContext);
     $operator = NULL;
     $operators = array('*', '^', '-', '+', '/', '%');
     foreach ($matches[0] as $part) {
         if (in_array($part, $operators)) {
             $operator = $part;
         } else {
             $part = parent::getTemplateVariableOrValueItself($part, $renderingContext);
             $result = self::evaluateOperation($result, $operator, $part);
         }
     }
     return $result;
 }