protected function 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 drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php
Loads from annotations from a directory.
AnnotationFileLoader::load in drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
Loads from annotations from a file.

File

drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Loader/AnnotationFileLoader.php, line 85

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;
}