ConfigLoader.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * ObjectManager configuration loader
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\App\ObjectManager;
  9. use Magento\Framework\ObjectManager\ConfigLoaderInterface;
  10. use Magento\Framework\Serialize\Serializer\Serialize;
  11. use Magento\Framework\Serialize\SerializerInterface;
  12. class ConfigLoader implements ConfigLoaderInterface
  13. {
  14. /**
  15. * Config reader
  16. *
  17. * @var \Magento\Framework\ObjectManager\Config\Reader\Dom
  18. */
  19. protected $_reader;
  20. /**
  21. * Config reader factory
  22. *
  23. * @var \Magento\Framework\ObjectManager\Config\Reader\DomFactory
  24. */
  25. protected $_readerFactory;
  26. /**
  27. * Cache
  28. *
  29. * @var \Magento\Framework\Config\CacheInterface
  30. */
  31. protected $_cache;
  32. /**
  33. * @var SerializerInterface
  34. */
  35. private $serializer;
  36. /**
  37. * @param \Magento\Framework\Config\CacheInterface $cache
  38. * @param \Magento\Framework\ObjectManager\Config\Reader\DomFactory $readerFactory
  39. */
  40. public function __construct(
  41. \Magento\Framework\Config\CacheInterface $cache,
  42. \Magento\Framework\ObjectManager\Config\Reader\DomFactory $readerFactory
  43. ) {
  44. $this->_cache = $cache;
  45. $this->_readerFactory = $readerFactory;
  46. }
  47. /**
  48. * Get reader instance
  49. *
  50. * @return \Magento\Framework\ObjectManager\Config\Reader\Dom
  51. */
  52. protected function _getReader()
  53. {
  54. if (empty($this->_reader)) {
  55. $this->_reader = $this->_readerFactory->create();
  56. }
  57. return $this->_reader;
  58. }
  59. /**
  60. * {inheritdoc}
  61. */
  62. public function load($area)
  63. {
  64. $cacheId = $area . '::DiConfig';
  65. $data = $this->_cache->load($cacheId);
  66. if (!$data) {
  67. $data = $this->_getReader()->read($area);
  68. $this->_cache->save($this->getSerializer()->serialize($data), $cacheId);
  69. } else {
  70. $data = $this->getSerializer()->unserialize($data);
  71. }
  72. return $data;
  73. }
  74. /**
  75. * Get serializer
  76. *
  77. * @return SerializerInterface
  78. * @deprecated 101.0.0
  79. */
  80. private function getSerializer()
  81. {
  82. if (null === $this->serializer) {
  83. $this->serializer = \Magento\Framework\App\ObjectManager::getInstance()->get(Serialize::class);
  84. }
  85. return $this->serializer;
  86. }
  87. }