コード例 #1
0
 /**
  * {@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;
 }
コード例 #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);
 }
コード例 #3
0
ファイル: ArrayNode.php プロジェクト: kidaa30/redcat
 /**
  * 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;
 }
コード例 #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;
 }
コード例 #5
0
 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)));
 }