ClassFinder.php 958 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Drupal\Component\ClassFinder;
  3. use Doctrine\Common\Reflection\ClassFinderInterface;
  4. /**
  5. * A Utility class that uses active autoloaders to find a file for a class.
  6. */
  7. class ClassFinder implements ClassFinderInterface {
  8. /**
  9. * {@inheritdoc}
  10. */
  11. public function findFile($class) {
  12. $loaders = spl_autoload_functions();
  13. foreach ($loaders as $loader) {
  14. if (is_array($loader) && isset($loader[0]) && is_object($loader[0]) && method_exists($loader[0], 'findFile')) {
  15. $file = call_user_func_array([$loader[0], 'findFile'], [$class]);
  16. // Different implementations return different empty values. For example,
  17. // \Composer\Autoload\ClassLoader::findFile() returns FALSE whilst
  18. // \Doctrine\Common\Reflection\ClassFinderInterface::findFile()
  19. // documents that a NULL should be returned.
  20. if (!empty($file)) {
  21. return $file;
  22. }
  23. }
  24. }
  25. return NULL;
  26. }
  27. }