Proxy.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Application area list
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\App\AreaList;
  9. class Proxy extends \Magento\Framework\App\AreaList implements
  10. \Magento\Framework\ObjectManager\NoninterceptableInterface
  11. {
  12. /**
  13. * Object Manager instance
  14. *
  15. * @var \Magento\Framework\ObjectManagerInterface
  16. */
  17. protected $_objectManager = null;
  18. /**
  19. * Proxied instance name
  20. *
  21. * @var string
  22. */
  23. protected $_instanceName = null;
  24. /**
  25. * Proxied instance
  26. *
  27. * @var \Magento\Framework\Locale\Resolver
  28. */
  29. protected $_subject = null;
  30. /**
  31. * Instance shareability flag
  32. *
  33. * @var bool
  34. */
  35. protected $_isShared = null;
  36. /**
  37. * Proxy constructor
  38. *
  39. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  40. * @param string $instanceName
  41. * @param bool $shared
  42. */
  43. public function __construct(
  44. \Magento\Framework\ObjectManagerInterface $objectManager,
  45. $instanceName = \Magento\Framework\App\AreaList::class,
  46. $shared = true
  47. ) {
  48. $this->_objectManager = $objectManager;
  49. $this->_instanceName = $instanceName;
  50. $this->_isShared = $shared;
  51. }
  52. /**
  53. * @return array
  54. */
  55. public function __sleep()
  56. {
  57. return ['_subject', '_isShared'];
  58. }
  59. /**
  60. * Retrieve ObjectManager from global scope
  61. *
  62. * @return void
  63. */
  64. public function __wakeup()
  65. {
  66. $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  67. }
  68. /**
  69. * Clone proxied instance
  70. *
  71. * @return void
  72. */
  73. public function __clone()
  74. {
  75. $this->_subject = clone $this->_getSubject();
  76. }
  77. /**
  78. * Get proxied instance
  79. *
  80. * @return \Magento\Framework\Locale\Resolver
  81. */
  82. protected function _getSubject()
  83. {
  84. if (!$this->_subject) {
  85. $this->_subject = true === $this->_isShared
  86. ? $this->_objectManager->get($this->_instanceName)
  87. : $this->_objectManager->create($this->_instanceName);
  88. }
  89. return $this->_subject;
  90. }
  91. /**
  92. * Retrieve area code by front name
  93. *
  94. * @param string $frontName
  95. * @return null|string
  96. */
  97. public function getCodeByFrontName($frontName)
  98. {
  99. return $this->_getSubject()->getCodeByFrontName($frontName);
  100. }
  101. /**
  102. * Retrieve area front name by code
  103. *
  104. * @param string $areaCode
  105. * @return string
  106. */
  107. public function getFrontName($areaCode)
  108. {
  109. return $this->_getSubject()->getFrontName($areaCode);
  110. }
  111. /**
  112. * Retrieve area codes
  113. *
  114. * @return string[]
  115. */
  116. public function getCodes()
  117. {
  118. return $this->_getSubject()->getCodes();
  119. }
  120. /**
  121. * Retrieve default area router id
  122. *
  123. * @param string $areaCode
  124. * @return string
  125. */
  126. public function getDefaultRouter($areaCode)
  127. {
  128. return $this->_getSubject()->getDefaultRouter($areaCode);
  129. }
  130. /**
  131. * Retrieve application area
  132. *
  133. * @param string $code
  134. * @return \Magento\Framework\App\Area
  135. */
  136. public function getArea($code)
  137. {
  138. return $this->_getSubject()->getArea($code);
  139. }
  140. }