Esempio n. 1
0
 /**
  * Creates a negated version of any expression. For instance, passing a
  * VariableNode will result in !$var.
  *
  * @param \Pharborist\ExpressionNode $expr
  *  The expression to negate.
  *
  * @return static
  */
 public static function fromExpression(ExpressionNode $expr)
 {
     $not = new static();
     $not->addChild(Token::not(), 'operator');
     /** @var \Pharborist\Node $expr */
     $not->addChild($expr->remove(), 'operand');
     return $not;
 }
Esempio n. 2
0
 /**
  * @param ExpressionNode|NULL $node
  * @return $this
  */
 public function setValue($node)
 {
     if ($node === NULL) {
         if (isset($this->value)) {
             $this->value->previousUntil(Filter::isInstanceOf('\\Pharborist\\Variables\\VariableNode'))->remove();
             $this->value->remove();
         }
     } else {
         if (isset($this->value)) {
             /** @var Node $node */
             $this->value->replaceWith($node);
         } else {
             $this->append([Token::space(), Token::assign(), Token::space(), $node]);
         }
     }
     return $this;
 }