Permalink
Browse files

Optimizing calls to class_exists() by requiring loaders to return tru…

…e when they found something
  • Loading branch information...
1 parent 93acc53 commit fea0871984324bf2e1b53868d0aba0491799db2a @beberlei beberlei committed Jul 2, 2011
@@ -80,6 +80,7 @@ static public function registerAutoloadNamespaces(array $namespaces)
* Register an autoloading callabale 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 callabale $callabale
*/
@@ -105,21 +106,24 @@ static public function loadAnnotationClass($class)
if ($dirs === null) {
if (ClassLoader::fileExistsInIncludePath($file)) {
require $file;
- return;
+ return true;
}
} else {
foreach((array)$dirs AS $dir) {
if (file_exists($dir . DIRECTORY_SEPARATOR . $file)) {
require $dir . DIRECTORY_SEPARATOR . $file;
- return;
+ return true;
}
}
}
}
}
foreach (self::$loaders AS $loader) {
- call_user_func($loader, $class);
+ if (call_user_func($loader, $class) === true) {
+ return true;
+ }
}
+ return false;
}
}
@@ -263,12 +263,9 @@ private function classExists($fqcn)
if (class_exists($fqcn, false)) {
return $this->classExists[$fqcn] = true;
}
-
- // class was not found, lets try to "autoload" it silently
- AnnotationRegistry::loadAnnotationClass($fqcn);
// final check, does this class exist?
- return $this->classExists[$fqcn] = class_exists($fqcn, false);
+ return $this->classExists[$fqcn] = AnnotationRegistry::loadAnnotationClass($fqcn);
}
/**

0 comments on commit fea0871

Please sign in to comment.