Drupal investigation

DebugUniversalClassLoader.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\ClassLoader;
  11. @trigger_error('The '.__NAMESPACE__.'\DebugUniversalClassLoader class is deprecated since version 2.4 and will be removed in 3.0. Use the Symfony\Component\Debug\DebugClassLoader class instead.', E_USER_DEPRECATED);
  12. /**
  13. * Checks that the class is actually declared in the included file.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. *
  17. * @deprecated since version 2.4, to be removed in 3.0.
  18. * Use the {@link \Symfony\Component\Debug\DebugClassLoader} class instead.
  19. */
  20. class DebugUniversalClassLoader extends UniversalClassLoader
  21. {
  22. /**
  23. * Replaces all regular UniversalClassLoader instances by a DebugUniversalClassLoader ones.
  24. */
  25. public static function enable()
  26. {
  27. if (!is_array($functions = spl_autoload_functions())) {
  28. return;
  29. }
  30. foreach ($functions as $function) {
  31. spl_autoload_unregister($function);
  32. }
  33. foreach ($functions as $function) {
  34. if (is_array($function) && $function[0] instanceof UniversalClassLoader) {
  35. $loader = new static();
  36. $loader->registerNamespaceFallbacks($function[0]->getNamespaceFallbacks());
  37. $loader->registerPrefixFallbacks($function[0]->getPrefixFallbacks());
  38. $loader->registerNamespaces($function[0]->getNamespaces());
  39. $loader->registerPrefixes($function[0]->getPrefixes());
  40. $loader->useIncludePath($function[0]->getUseIncludePath());
  41. $function[0] = $loader;
  42. }
  43. spl_autoload_register($function);
  44. }
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function loadClass($class)
  50. {
  51. if ($file = $this->findFile($class)) {
  52. require $file;
  53. if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
  54. throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
  55. }
  56. }
  57. }
  58. }