/** * 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; } } }
/** * Check if name is in namespace * * @param Name $namespace * @return bool */ public function inNamespace(Name $namespace) { return !!preg_match('/^' . preg_quote($namespace->keyize()) . '/', $this->getNamespace()->keyize()); }