Runtime.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\ObjectManager\Relations;
  7. class Runtime implements \Magento\Framework\ObjectManager\RelationsInterface
  8. {
  9. /**
  10. * @var \Magento\Framework\Code\Reader\ClassReaderInterface
  11. */
  12. protected $_classReader;
  13. /**
  14. * Default behavior
  15. *
  16. * @var array
  17. */
  18. protected $_default = [];
  19. /**
  20. * @param \Magento\Framework\Code\Reader\ClassReaderInterface $classReader
  21. */
  22. public function __construct(\Magento\Framework\Code\Reader\ClassReaderInterface $classReader = null)
  23. {
  24. $this->_classReader = $classReader ?: new \Magento\Framework\Code\Reader\ClassReader();
  25. }
  26. /**
  27. * Check whether requested type is available for read
  28. *
  29. * @param string $type
  30. * @return bool
  31. */
  32. public function has($type)
  33. {
  34. return class_exists($type) || interface_exists($type);
  35. }
  36. /**
  37. * Retrieve list of parents
  38. *
  39. * @param string $type
  40. * @return array
  41. */
  42. public function getParents($type)
  43. {
  44. if (!class_exists($type)) {
  45. return $this->_default;
  46. }
  47. return $this->_classReader->getParents($type) ?: $this->_default;
  48. }
  49. }