Compiled.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\ObjectManager\Environment;
  7. use Magento\Framework\App\EnvironmentInterface;
  8. use Magento\Framework\App\Interception\Cache\CompiledConfig;
  9. use Magento\Framework\ObjectManager\FactoryInterface;
  10. use Magento\Framework\App\Area;
  11. use Magento\Framework\Interception\ObjectManager\ConfigInterface;
  12. use Magento\Framework\App\ObjectManager;
  13. /**
  14. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  15. */
  16. class Compiled extends AbstractEnvironment implements EnvironmentInterface
  17. {
  18. /**#@+
  19. * Mode name
  20. */
  21. const MODE = 'compiled';
  22. /**#@- */
  23. /**#@- */
  24. protected $mode = self::MODE;
  25. /**
  26. * @var string
  27. */
  28. protected $configPreference = \Magento\Framework\ObjectManager\Factory\Compiled::class;
  29. /**
  30. * @var \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled
  31. */
  32. private $configLoader;
  33. /**
  34. * Creates factory
  35. *
  36. * @param array $arguments
  37. * @param string $factoryClass
  38. *
  39. * @return FactoryInterface
  40. */
  41. protected function createFactory($arguments, $factoryClass)
  42. {
  43. return new $factoryClass(
  44. $this->getDiConfig(),
  45. $arguments['shared_instances'],
  46. $arguments
  47. );
  48. }
  49. /**
  50. * Returns initialized compiled config
  51. *
  52. * @return \Magento\Framework\Interception\ObjectManager\ConfigInterface
  53. */
  54. public function getDiConfig()
  55. {
  56. if (!$this->config) {
  57. $this->config = new \Magento\Framework\Interception\ObjectManager\Config\Compiled(
  58. $this->getConfigData()
  59. );
  60. }
  61. return $this->config;
  62. }
  63. /**
  64. * Returns config data as array
  65. *
  66. * @return array
  67. */
  68. protected function getConfigData()
  69. {
  70. return $this->getObjectManagerConfigLoader()->load(Area::AREA_GLOBAL);
  71. }
  72. /**
  73. * Returns new instance of compiled config loader
  74. *
  75. * @return \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled
  76. */
  77. public function getObjectManagerConfigLoader()
  78. {
  79. if ($this->configLoader) {
  80. return $this->configLoader;
  81. }
  82. $this->configLoader = new \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled();
  83. return $this->configLoader;
  84. }
  85. /**
  86. * {inheritdoc}
  87. */
  88. public function configureObjectManager(ConfigInterface $diConfig, &$sharedInstances)
  89. {
  90. $objectManager = ObjectManager::getInstance();
  91. $objectManager->configure(
  92. $objectManager
  93. ->get(\Magento\Framework\ObjectManager\ConfigLoaderInterface::class)
  94. ->load(Area::AREA_GLOBAL)
  95. );
  96. $objectManager->get(\Magento\Framework\Config\ScopeInterface::class)
  97. ->setCurrentScope('global');
  98. $diConfig->setInterceptionConfig(
  99. $objectManager->get(\Magento\Framework\Interception\Config\Config::class)
  100. );
  101. $sharedInstances[\Magento\Framework\Interception\PluginList\PluginList::class] = $objectManager->create(
  102. \Magento\Framework\Interception\PluginListInterface::class,
  103. ['cache' => $objectManager->get(\Magento\Framework\App\Interception\Cache\CompiledConfig::class)]
  104. );
  105. $objectManager
  106. ->get(\Magento\Framework\App\Cache\Manager::class)
  107. ->setEnabled([CompiledConfig::TYPE_IDENTIFIER], true);
  108. }
  109. }