/**
  * {@inheritdoc}
  */
 public function get($id)
 {
     $all = new NodeCollection([]);
     $files = $this->getQuery(['file'])->distinct(TRUE)->condition('id', $id)->execute()->fetchCol();
     array_walk($files, function ($file) use($all, $id) {
         $all->add($this->target->open($file)->find(Filter::isFunctionCall($id)));
     });
     return $all;
 }
Exemplo n.º 2
0
 /**
  * Implements \ArrayAccess::offsetGet().
  *
  * @param integer $offset
  *
  * @return ParameterNode
  */
 public function offsetGet($offset)
 {
     if (is_string($offset)) {
         // To deal with php allowing function test($a, $a) loop in reverse.
         foreach (array_reverse($this->nodes) as $node) {
             if ($node instanceof ParameterNode) {
                 if ($node->getName() === $offset) {
                     return $node;
                 }
             }
         }
         return NULL;
     }
     return parent::offsetGet($offset);
 }
Exemplo n.º 3
0
 /**
  * Get the values of the array.
  *
  * @param boolean $recursive
  *   (optional) TRUE to get values of array elements that are also arrays.
  *
  * @return NodeCollection
  */
 public function getValues($recursive = TRUE)
 {
     $values = new NodeCollection();
     foreach ($this->elements->getItems() as $element) {
         if ($element instanceof ArrayPairNode) {
             $value = $element->getValue();
             if ($recursive && $value instanceof ArrayNode) {
                 $values->add($value->getValues($recursive));
             } else {
                 $values->add($value);
             }
         } else {
             $values->add($element);
         }
     }
     return $values;
 }
Exemplo n.º 4
0
 /**
  * Finds every rewritable expression in the function body.
  *
  * @param \Pharborist\Functions\ParameterNode $parameter
  *  The parameter on which the rewrite is based.
  *
  * @return \Pharborist\NodeCollection
  */
 protected function getExpressions(ParameterNode $parameter)
 {
     $filter = Filter::isInstanceOf('\\Pharborist\\ArrayLookupNode', '\\Pharborist\\Objects\\ObjectPropertyNode');
     $expressions = new NodeCollection();
     $parameter->getFunction()->find(Filter::isInstanceOf('\\Pharborist\\Variables\\VariableNode'))->filter(function (VariableNode $variable) use($parameter) {
         return $variable->getName() == $parameter->getName();
     })->each(function (VariableNode $variable) use($filter, $expressions) {
         $root = $variable->furthest($filter);
         if ($root) {
             $expressions->add($root);
         }
     });
     return $expressions;
 }
 public function testIndex()
 {
     $first = Token::identifier('hello');
     $second = Token::identifier('world');
     $not_found = Token::identifier('notfound');
     $collection = new NodeCollection([$first, $second], FALSE);
     $this->assertEquals(0, $collection->indexOf(Filter::is($first)));
     $this->assertEquals(1, $collection->indexOf(Filter::is($second)));
     $this->assertEquals(-1, $collection->indexOf(Filter::is($not_found)));
 }