Proxy.php 3.2 KB

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