/**
  * 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());
     }
 }
Esempio n. 2
0
 /**
  * Given an array of Reflections, try to find the identifier.
  *
  * @param Reflection[] $reflections
  * @param Identifier $identifier
  * @return Reflection
  */
 private function findInArray($reflections, Identifier $identifier)
 {
     foreach ($reflections as $reflection) {
         if ($reflection->getName() === $identifier->getName()) {
             return $reflection;
         }
     }
     throw IdentifierNotFound::fromIdentifier($identifier);
 }
 /**
  * @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);
 }
 /**
  * @param Identifier $identifier
  *
  * @return null|string
  */
 private function getInternalReflectionClassName(Identifier $identifier)
 {
     if (!$identifier->isClass()) {
         return null;
     }
     $name = $identifier->getName();
     if (!(class_exists($name, false) || interface_exists($name, false) || trait_exists($name, false))) {
         return null;
         // not an available internal class
     }
     $reflection = new \ReflectionClass($name);
     return $reflection->getFileName() ? $reflection->getName() : null;
 }
 /**
  * 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());
 }
 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 testIsTypesForFunction()
 {
     $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION));
     $this->assertFalse($identifier->isClass());
     $this->assertTrue($identifier->isFunction());
 }
Esempio n. 9
0
 /**
  * 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;
 }
Esempio n. 10
0
 public function testGetType()
 {
     $identifierType = new IdentifierType(IdentifierType::IDENTIFIER_CLASS);
     $identifier = new Identifier('Foo', $identifierType);
     $this->assertSame($identifierType, $identifier->getType());
 }