You are here

protected function AnnotationFileLoader::findClass in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/routing/Loader/AnnotationFileLoader.php \Symfony\Component\Routing\Loader\AnnotationFileLoader::findClass()

Returns the full class name for the first class in the file.

Parameters

string $file A PHP file path:

Return value

string|false Full class name if found, false otherwise

2 calls to AnnotationFileLoader::findClass()
AnnotationDirectoryLoader::load in vendor/symfony/routing/Loader/AnnotationDirectoryLoader.php
Loads from annotations from a directory.
AnnotationFileLoader::load in vendor/symfony/routing/Loader/AnnotationFileLoader.php
Loads from annotations from a file.

File

vendor/symfony/routing/Loader/AnnotationFileLoader.php, line 86

Class

AnnotationFileLoader
AnnotationFileLoader loads routing information from annotations set on a PHP class and its methods.

Namespace

Symfony\Component\Routing\Loader

Code

protected function findClass($file) {
  $class = false;
  $namespace = false;
  $tokens = token_get_all(file_get_contents($file));
  for ($i = 0, $count = count($tokens); $i < $count; ++$i) {
    $token = $tokens[$i];
    if (!is_array($token)) {
      continue;
    }
    if (true === $class && T_STRING === $token[0]) {
      return $namespace . '\\' . $token[1];
    }
    if (true === $namespace && T_STRING === $token[0]) {
      $namespace = '';
      do {
        $namespace .= $token[1];
        $token = $tokens[++$i];
      } while ($i < $count && is_array($token) && in_array($token[0], array(
        T_NS_SEPARATOR,
        T_STRING,
      )));
    }
    if (T_CLASS === $token[0]) {
      $class = true;
    }
    if (T_NAMESPACE === $token[0]) {
      $namespace = true;
    }
  }
  return false;
}