AutoloaderRegistry.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 Magento\Framework\Autoload\AutoloaderInterface;
  8. /**
  9. * Registry to store a static member autoloader
  10. */
  11. class AutoloaderRegistry
  12. {
  13. /**
  14. * @var AutoloaderInterface
  15. */
  16. protected static $autoloader;
  17. /**
  18. * Registers the given autoloader as a static member
  19. *
  20. * @param AutoloaderInterface $newAutoloader
  21. * @return void
  22. */
  23. public static function registerAutoloader(AutoloaderInterface $newAutoloader)
  24. {
  25. self::$autoloader = $newAutoloader;
  26. }
  27. /**
  28. * Returns the registered autoloader
  29. *
  30. * @throws \Exception
  31. * @return AutoloaderInterface
  32. */
  33. public static function getAutoloader()
  34. {
  35. if (self::$autoloader !== null) {
  36. return self::$autoloader;
  37. } else {
  38. throw new \Exception('Autoloader is not registered, cannot be retrieved.');
  39. }
  40. }
  41. }