ClassLoaderWrapper.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Autoload;
  7. use Composer\Autoload\ClassLoader;
  8. /**
  9. * Wrapper designed to insulate the autoloader class provided by Composer
  10. */
  11. class ClassLoaderWrapper implements AutoloaderInterface
  12. {
  13. /**
  14. * Using the autoloader class provided by Composer
  15. *
  16. * @var ClassLoader
  17. */
  18. protected $autoloader;
  19. /**
  20. * @param ClassLoader $autoloader
  21. */
  22. public function __construct(ClassLoader $autoloader)
  23. {
  24. $this->autoloader = $autoloader;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function addPsr4($nsPrefix, $paths, $prepend = false)
  30. {
  31. $this->autoloader->addPsr4($nsPrefix, $paths, $prepend);
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function addPsr0($nsPrefix, $paths, $prepend = false)
  37. {
  38. $this->autoloader->add($nsPrefix, $paths, $prepend);
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function setPsr0($nsPrefix, $paths)
  44. {
  45. $this->autoloader->set($nsPrefix, $paths);
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function setPsr4($nsPrefix, $paths)
  51. {
  52. $this->autoloader->setPsr4($nsPrefix, $paths);
  53. }
  54. /**
  55. * {@inheritdoc}
  56. * @codeCoverageIgnore
  57. */
  58. public function loadClass($className)
  59. {
  60. return $this->autoloader->loadClass($className) === true;
  61. }
  62. /**
  63. * {@inheritdoc}
  64. * @codeCoverageIgnore
  65. */
  66. public function findFile($className)
  67. {
  68. /**
  69. * Composer remembers that files don't exist even after they are generated. This clears the entry for
  70. * $className so we can check the filesystem again for class existence.
  71. */
  72. if ($className[0] === '\\') {
  73. $className = substr($className, 1);
  74. }
  75. $this->autoloader->addClassMap([$className => null]);
  76. return $this->autoloader->findFile($className);
  77. }
  78. }