Skip to content

Commit

Permalink
Optimizing calls to class_exists() by requiring loaders to return tru…
Browse files Browse the repository at this point in the history
…e when they found something
  • Loading branch information
beberlei committed Jul 2, 2011
1 parent 93acc53 commit fea0871
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 7 additions & 3 deletions lib/Doctrine/Common/Annotations/AnnotationRegistry.php
Expand Up @@ -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
*/
Expand All @@ -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;
}
}
5 changes: 1 addition & 4 deletions lib/Doctrine/Common/Annotations/DocParser.php
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit fea0871

Please sign in to comment.