final class AnnotationRegistry

AnnotationRegistry

Hierarchy

Expanded class hierarchy of AnnotationRegistry

3 files declare their use of AnnotationRegistry
AnnotatedClassDiscovery.php in drupal/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php
Definition of Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery.
AnnotationDriver.php in drupal/core/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/AnnotationDriver.php
DocParserTest.php in drupal/core/vendor/doctrine/common/tests/Doctrine/Tests/Common/Annotations/DocParserTest.php

File

drupal/core/vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationRegistry.php, line 25

Namespace

Doctrine\Common\Annotations
View source
final class AnnotationRegistry {

  /**
   * A map of namespaces to use for autoloading purposes based on a PSR-0 convention.
   *
   * Contains the namespace as key and an array of directories as value. If the value is NULL
   * the include path is used for checking for the corresponding file.
   *
   * This autoloading mechanism does not utilize the PHP autoloading but implements autoloading on its own.
   *
   * @var array
   */
  private static $autoloadNamespaces = array();

  /**
   * A map of autoloader callables.
   *
   * @var array
   */
  private static $loaders = array();
  public static function reset() {
    self::$autoloadNamespaces = array();
    self::$loaders = array();
  }

  /**
   * Register file
   *
   * @param string $file
   */
  public static function registerFile($file) {
    require_once $file;
  }

  /**
   * Add a namespace with one or many directories to look for files or null for the include path.
   *
   * Loading of this namespaces will be done with a PSR-0 namespace loading algorithm.
   *
   * @param string $namespace
   * @param string|array|null $dirs
   */
  public static function registerAutoloadNamespace($namespace, $dirs = null) {
    self::$autoloadNamespaces[$namespace] = $dirs;
  }

  /**
   * Register multiple namespaces
   *
   * Loading of this namespaces will be done with a PSR-0 namespace loading algorithm.
   *
   * @param array $namespaces
   */
  public static function registerAutoloadNamespaces(array $namespaces) {
    self::$autoloadNamespaces = array_merge(self::$autoloadNamespaces, $namespaces);
  }

  /**
   * Register an autoloading callable for annotations, much like spl_autoload_register().
   *
   * NOTE: These class loaders HAVE to be silent when a class was not found!
   * IMPORTANT: Loaders have to return true if they loaded a class that could contain the searched annotation class.
   *
   * @param callable $callable
   *
   * @throws \InvalidArgumentException
   */
  public static function registerLoader($callable) {
    if (!is_callable($callable)) {
      throw new \InvalidArgumentException("A callable is expected in AnnotationRegistry::registerLoader().");
    }
    self::$loaders[] = $callable;
  }

  /**
   * Autoload an annotation class silently.
   *
   * @param string $class
   * @return boolean
   */
  public static function loadAnnotationClass($class) {
    foreach (self::$autoloadNamespaces as $namespace => $dirs) {
      if (strpos($class, $namespace) === 0) {
        $file = str_replace("\\", DIRECTORY_SEPARATOR, $class) . ".php";
        if ($dirs === null) {
          if ($path = stream_resolve_include_path($file)) {
            require $path;
            return true;
          }
        }
        else {
          foreach ((array) $dirs as $dir) {
            if (file_exists($dir . DIRECTORY_SEPARATOR . $file)) {
              require $dir . DIRECTORY_SEPARATOR . $file;
              return true;
            }
          }
        }
      }
    }
    foreach (self::$loaders as $loader) {
      if (call_user_func($loader, $class) === true) {
        return true;
      }
    }
    return false;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AnnotationRegistry::$autoloadNamespaces private static property A map of namespaces to use for autoloading purposes based on a PSR-0 convention.
AnnotationRegistry::$loaders private static property A map of autoloader callables.
AnnotationRegistry::loadAnnotationClass public static function Autoload an annotation class silently.
AnnotationRegistry::registerAutoloadNamespace public static function Add a namespace with one or many directories to look for files or null for the include path.
AnnotationRegistry::registerAutoloadNamespaces public static function Register multiple namespaces
AnnotationRegistry::registerFile public static function Register file
AnnotationRegistry::registerLoader public static function Register an autoloading callable for annotations, much like spl_autoload_register().
AnnotationRegistry::reset public static function