DefinedClasses.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Code\Generator;
  7. use Magento\Framework\Autoload\AutoloaderRegistry;
  8. /**
  9. * DefinedClasses class detects if a class has been defined
  10. */
  11. class DefinedClasses
  12. {
  13. /**
  14. * Determine if a class can be loaded without using Code\Generator\Autoloader.
  15. *
  16. * @param string $className
  17. * @return bool
  18. */
  19. public function isClassLoadable($className)
  20. {
  21. return $this->isClassLoadableFromMemory($className) || $this->isClassLoadableFromDisk($className);
  22. }
  23. /**
  24. * Determine if a class exists in memory
  25. *
  26. * @param string $className
  27. * @return bool
  28. */
  29. public function isClassLoadableFromMemory($className)
  30. {
  31. return class_exists($className, false) || interface_exists($className, false);
  32. }
  33. /**
  34. * Determine if a class exists on disk
  35. *
  36. * @param string $className
  37. * @return bool
  38. * @deprecated 102.0.0
  39. */
  40. public function isClassLoadableFromDisc($className)
  41. {
  42. return $this->isClassLoadableFromDisk($className);
  43. }
  44. /**
  45. * Determine if a class exists on disk
  46. *
  47. * @param string $className
  48. * @return bool
  49. */
  50. public function isClassLoadableFromDisk($className)
  51. {
  52. try {
  53. return (bool)AutoloaderRegistry::getAutoloader()->findFile($className);
  54. } catch (\Exception $e) {
  55. // Couldn't get access to the autoloader so we need to allow class_exists to call autoloader chain
  56. return (class_exists($className) || interface_exists($className));
  57. }
  58. }
  59. }