コード例 #1
0
ファイル: Reader.php プロジェクト: bonroyage/classtools
 /**
  * Find class, interface and trait definitions in statemnts
  *
  * @param  array $stmts
  * @param  Name  $namespace
  * @return void
  */
 private function findDefinitions(array $stmts, Name $namespace)
 {
     $useStmts = [];
     foreach ($stmts as $stmt) {
         // Restart if namespace statement is found
         if ($stmt instanceof Namespace_) {
             $this->findDefinitions($stmt->stmts, new Name((string) $stmt->name));
             // Save use statement
         } elseif ($stmt instanceof Use_) {
             $useStmts[] = $stmt;
             // Save classes, interfaces and traits
         } elseif ($stmt instanceof Class_ or $stmt instanceof Interface_ or $stmt instanceof Trait_) {
             $defName = new Name("{$namespace}\\{$stmt->name}");
             $this->names[$defName->keyize()] = $defName->normalize();
             $this->defs[$defName->keyize()] = new Namespace_($namespace->createNode(), $useStmts);
             $this->defs[$defName->keyize()]->stmts[] = $stmt;
         }
     }
 }
コード例 #2
0
 /**
  * Resolve unexisting names by searching specified namespaces
  *
  * @param  Node $node
  * @return \PhpParser\Node\Name|null
  * @throws RuntimeException If name can not be resolved
  */
 public function leaveNode(Node $node)
 {
     if ($node instanceof FullyQualified) {
         $name = new Name((string) $node);
         $whitelisted = $this->isWhitelisted($name);
         if (!$name->isDefined(!$whitelisted)) {
             /** @var Name $namespace */
             foreach ($this->search as $namespace) {
                 $newName = new Name("{$namespace}\\{$node->getLast()}");
                 if ($newName->isDefined()) {
                     return $newName->createNode();
                 }
             }
             if (!$whitelisted) {
                 throw new RuntimeException("Unable to resolve class <{$node}>.");
             }
         }
     }
 }