Exemplo 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;
 }
Exemplo n.º 2
0
 /**
  * Creates a new array lookup.
  *
  * @param \Pharborist\ExpressionNode $array
  *  The expression representing the array (usually a VariableNode).
  * @param \Pharborist\ExpressionNode $key
  *  The expression representing the key (usually a string).
  *
  * @return static
  */
 public static function create(ExpressionNode $array, ExpressionNode $key)
 {
     $node = new static();
     /** @var Node $array */
     $node->addChild($array, 'array');
     $node->addChild(Token::openBracket());
     /** @var Node $key */
     $node->addChild($key, 'key');
     $node->addChild(Token::closeBracket());
     return $node;
 }
Exemplo n.º 3
0
 /**
  * @param string|NameNode $name
  *
  * @return static
  */
 public static function create($name)
 {
     if (is_string($name)) {
         $name = NameNode::create($name);
     }
     /** @var ConstantNode $node */
     $node = new static();
     $node->addChild($name, 'constantName');
     return $node;
 }
Exemplo n.º 4
0
 public static function __callStatic($name, $children)
 {
     $finder = new static($name);
     foreach ($children as $child) {
         if ($child instanceof Finder) {
             $finder->addChild($child);
         } else {
             $finder->setCondition($child);
         }
     }
     return $finder;
 }
Exemplo n.º 5
0
 /**
  * Construct the chain from a configuration array/object
  * @param array|Config $config
  * @return static
  */
 public static function factory($config, Route $base = null)
 {
     $chain = new static($base);
     $spec = Config::cast($config);
     //
     foreach ($spec as $name => $node) {
         $prio = $node->value('priority', 0);
         $children = (array) $node->value('children');
         $route = static::element($node);
         if ($children) {
             $route = static::factory($children, $route);
         }
         $chain->addChild($name, $route, $prio);
     }
     return $chain;
 }
Exemplo n.º 6
0
 /**
  * Creates a method call on an object with an empty argument list.
  *
  * @param Node $object
  *  The expression that is an object.
  * @param string $method_name
  *  The name of the called method.
  *
  * @return static
  */
 public static function create(Node $object, $method_name)
 {
     /** @var ObjectMethodCallNode $node */
     $node = new static();
     $node->addChild($object, 'object');
     $node->addChild(Token::objectOperator(), 'operator');
     $node->addChild(Token::identifier($method_name), 'methodName');
     $node->addChild(Token::openParen(), 'openParen');
     $node->addChild(new CommaListNode(), 'arguments');
     $node->addChild(Token::closeParen(), 'closeParen');
     return $node;
 }
Exemplo n.º 7
0
 /**
  * Creates a method call on a class with an empty argument list.
  *
  * @param Node|string $class_name
  *  The class node which is typically NameNode of class.
  * @param string $method_name
  *  The name of the called method.
  *
  * @return static
  */
 public static function create($class_name, $method_name)
 {
     if (is_string($class_name)) {
         $class_name = NameNode::create($class_name);
     }
     /** @var ClassMethodCallNode $node */
     $node = new static();
     $node->addChild($class_name, 'className');
     $node->addChild(Token::doubleColon());
     $node->addChild(Token::identifier($method_name), 'methodName');
     $node->addChild(Token::openParen(), 'openParen');
     $node->addChild(new CommaListNode(), 'arguments');
     $node->addChild(Token::closeParen(), 'closeParen');
     return $node;
 }