123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- namespace Doctrine\Common\Annotations;
- final class AnnotationRegistry
- {
-
- static private $autoloadNamespaces = array();
-
- static private $loaders = array();
-
- static public function reset()
- {
- self::$autoloadNamespaces = array();
- self::$loaders = array();
- }
-
- static public function registerFile($file)
- {
- require_once $file;
- }
-
- static public function registerAutoloadNamespace($namespace, $dirs = null)
- {
- self::$autoloadNamespaces[$namespace] = $dirs;
- }
-
- static public function registerAutoloadNamespaces(array $namespaces)
- {
- self::$autoloadNamespaces = array_merge(self::$autoloadNamespaces, $namespaces);
- }
-
- static public function registerLoader($callable)
- {
- if (!is_callable($callable)) {
- throw new \InvalidArgumentException("A callable is expected in AnnotationRegistry::registerLoader().");
- }
- self::$loaders[] = $callable;
- }
-
- static public 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 (is_file($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;
- }
- }
|