コード例 #1
0
 /**
  * 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());
 }
コード例 #2
0
 /**
  * @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);
 }
コード例 #3
0
 /**
  * @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);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 public function testGetType()
 {
     $identifierType = new IdentifierType(IdentifierType::IDENTIFIER_CLASS);
     $identifier = new Identifier('Foo', $identifierType);
     $this->assertSame($identifierType, $identifier->getType());
 }
コード例 #6
0
ファイル: Generic.php プロジェクト: stof/BetterReflection
 /**
  * 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;
 }