/** * Attempts to locate the specified identifier * * @param Identifier $identifier * @return string */ private function locateIdentifier(Identifier $identifier) { if ($identifier->isClass()) { return $this->locateClassByName($identifier->getName()); } if ($identifier->isFunction()) { return $this->locateFunctionByName($identifier->getName()); } throw new Exception\UnloadableIdentifierType('AutoloadSourceLocator cannot locate ' . $identifier->getType()->getName()); }
/** * @param Identifier $identifier * @return LocatedSource|null */ public function __invoke(Identifier $identifier) { if ($identifier->getType()->getName() !== IdentifierType::IDENTIFIER_CLASS) { return null; } $filename = $this->classLoader->findFile($identifier->getName()); if (!$filename) { return null; } return new LocatedSource(file_get_contents($filename), $filename); }
/** * @param Identifier $identifier * @return LocatedSource */ public function __invoke(Identifier $identifier) { if ($identifier->getType()->getName() !== IdentifierType::IDENTIFIER_CLASS) { throw new \LogicException(__CLASS__ . ' can only be used to locate classes'); } $filename = $this->classLoader->findFile($identifier->getName()); if (!$filename) { throw new \UnexpectedValueException(sprintf('Could not locate file to load "%s"', $identifier->getName())); } return new LocatedSource(file_get_contents($filename), $filename); }
public static function fromIdentifier(Identifier $identifier) { return new self(sprintf('%s "%s" could not be found in the located source', $identifier->getType()->getName(), $identifier->getName()), $identifier); }
public function testGetType() { $identifierType = new IdentifierType(IdentifierType::IDENTIFIER_CLASS); $identifier = new Identifier('Foo', $identifierType); $this->assertSame($identifierType, $identifier->getType()); }
/** * Process and reflect all the matching identifiers found inside a namespace node. * * @param Node\Stmt\Namespace_ $namespace * @param Identifier $identifier * @param LocatedSource $locatedSource * @return Reflection[] */ private function reflectFromNamespace(Node\Stmt\Namespace_ $namespace, Identifier $identifier, LocatedSource $locatedSource) { $reflections = []; foreach ($namespace->stmts as $node) { $reflection = $this->reflectNode($node, $locatedSource, $namespace); if (null !== $reflection && $identifier->getType()->isMatchingReflector($reflection)) { $reflections[] = $reflection; } } return $reflections; }