Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function __invoke(array $data)
 {
     if (!isset($this->ast)) {
         $tokens = ExpressionParser::lex($this->expr, $this->vars);
         $this->ast = ExpressionParser::parseExpression($tokens);
     }
     return $this->ast->__invoke($data);
 }
Ejemplo n.º 2
0
Archivo: Infix.php Proyecto: jivoo/data
 /**
  * {@inheritdoc}
  */
 public function __invoke(array $data)
 {
     $left = $this->left->__invoke($data);
     if ($this->operator == 'is' and $this->right === null) {
         return $left === null;
     }
     $right = $this->right->__invoke($data);
     // "like" | "in" | "!=" | "<>" | ">=" | "<=" | "!<" | "!>" | "=" | "<" | ">"
     switch ($this->operator) {
         case 'like':
             // TODO: character groups? [abc] [^abc]
             $pattern = preg_split('/(?=^|[^\\\\])(?:\\\\\\\\)*([%_])/', $right, -1, PREG_SPLIT_DELIM_CAPTURE);
             $regex = '';
             foreach ($pattern as $substr) {
                 if ($substr == '%') {
                     $regex .= '.*';
                 } elseif ($substr == '_') {
                     $regex .= '.';
                 } else {
                     $regex .= preg_quote($substr, '/');
                 }
             }
             return preg_match('/^' . $regex . '$/i', $left) === 1;
         case 'in':
             return in_array($left, $right);
         case '!=':
             return $left != $right;
         case '<>':
             return $left != $right;
             // ??
         // ??
         case '>=':
             return $left >= $right;
         case '<=':
             return $left <= $right;
         case '!<':
             return !($left < $right);
         case '!>':
             return !($left > $right);
         case '=':
             return $left == $right;
         case '<':
             return $left < $right;
         case '>':
             return $left > $right;
         case 'and':
             return $left and $right;
         case 'or':
             return $left or $right;
         default:
             trigger_error('undefined operator: ' . $this->operator, E_USER_ERROR);
     }
 }