* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\ExpressionLanguage\Node; use Symfony\Component\ExpressionLanguage\Compiler; /** * @author Fabien Potencier * * @internal */ class BinaryNode extends Node { private static $operators = array( '~' => '.', 'and' => '&&', 'or' => '||', ); private static $functions = array( '**' => 'pow', '..' => 'range', 'in' => 'in_array', 'not in' => '!in_array', ); public function __construct($operator, Node $left, Node $right) { parent::__construct( array('left' => $left, 'right' => $right), array('operator' => $operator) ); } public function compile(Compiler $compiler) { $operator = $this->attributes['operator']; if ('matches' == $operator) { $compiler ->raw('preg_match(') ->compile($this->nodes['right']) ->raw(', ') ->compile($this->nodes['left']) ->raw(')') ; return; } if (isset(self::$functions[$operator])) { $compiler ->raw(sprintf('%s(', self::$functions[$operator])) ->compile($this->nodes['left']) ->raw(', ') ->compile($this->nodes['right']) ->raw(')') ; return; } if (isset(self::$operators[$operator])) { $operator = self::$operators[$operator]; } $compiler ->raw('(') ->compile($this->nodes['left']) ->raw(' ') ->raw($operator) ->raw(' ') ->compile($this->nodes['right']) ->raw(')') ; } public function evaluate($functions, $values) { $operator = $this->attributes['operator']; $left = $this->nodes['left']->evaluate($functions, $values); if (isset(self::$functions[$operator])) { $right = $this->nodes['right']->evaluate($functions, $values); if ('not in' === $operator) { return !in_array($left, $right); } $f = self::$functions[$operator]; return $f($left, $right); } switch ($operator) { case 'or': case '||': return $left || $this->nodes['right']->evaluate($functions, $values); case 'and': case '&&': return $left && $this->nodes['right']->evaluate($functions, $values); } $right = $this->nodes['right']->evaluate($functions, $values); switch ($operator) { 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 '>=': return $left >= $right; case '<=': return $left <= $right; case 'not in': return !in_array($left, $right); 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 'matches': return preg_match($right, $left); } } public function toArray() { return array('(', $this->nodes['left'], ' '.$this->attributes['operator'].' ', $this->nodes['right'], ')'); } } __halt_compiler();----SIGNATURE:----QElLuVEXozcPN+HDZy0aXHq3EcTVGb7X4P6RC7iL43MjEFRVTPnO5+dyf4BNRBj9VNWmwf6BnCFpvurd0TLgIrF7ty4wU09816rnZvCie0iCnqCPWpYUuNzl8plmAGtoZlbW150wnkPZhKaf607k0CdmRkOG+0tyN6G1cLM2m5r6KXEYSPa7anamjj/75fwV91f6fq5otpRjBQw2MpVkEqCQ9ZbxPx/k7s2890McFcd5YDgrbUo8uiE62m46mK5OezIU+FREffhylGT/p/vytJk2K1paMZpRf+geE170526DeSB56o7a/o9kWqjypHmncXURejvjB/b4lqJvld00rT2UtNKB0PjMkZvJHi80+Oz/HaLH8eVf87fvsAUM7UsWHDwQm0Nr5odBhpIlnEjd1KXDWe16KspA9pl4oEpXlFHib7iVFE99jx/h5Su+YliFpWcrXP2fbFy1iSvBryw/bhiq3/CjjxFLiYDbCTxjXzA757Fd3jA7cgnI/HpjqMW66EydMBgK/ExyIm8rpqMhcmCOEKJxMM6DQrwW/HnGcUwwF66aEgVUQBwQ9y9YUJ61DWmaPtDryvp0LlYLLGMSYJdou/3Oed1ISK9LSHoMzuvN2bP3VBc7CyO1RgWI9N+q4/J1HuGHinDTvX/XKdA/0+YKB0NIe7QL7qLBOG2BlTs=----ATTACHMENT:----MTEwNjQ1ODc2NjcxMzc5NiA3NTk2OTcwNzQ1MDg3MzY2IDc2NDI5NDI5Mjk4MTE1OTQ=