Proxy.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Mview\Config\Data;
  7. /**
  8. * Proxy class for \Magento\Framework\Mview\Config\Data
  9. */
  10. class Proxy extends \Magento\Framework\Mview\Config\Data implements
  11. \Magento\Framework\ObjectManager\NoninterceptableInterface
  12. {
  13. /**
  14. * Object Manager instance
  15. *
  16. * @var \Magento\Framework\ObjectManagerInterface
  17. */
  18. protected $objectManager;
  19. /**
  20. * Proxied instance name
  21. *
  22. * @var string
  23. */
  24. protected $instanceName;
  25. /**
  26. * Proxied instance
  27. *
  28. * @var \Magento\Framework\Mview\Config\Data
  29. */
  30. protected $subject;
  31. /**
  32. * Instance shareability flag
  33. *
  34. * @var bool
  35. */
  36. protected $isShared = null;
  37. /**
  38. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  39. * @param string $instanceName
  40. * @param bool $shared
  41. */
  42. public function __construct(
  43. \Magento\Framework\ObjectManagerInterface $objectManager,
  44. $instanceName = \Magento\Framework\Mview\Config\Data::class,
  45. $shared = true
  46. ) {
  47. $this->objectManager = $objectManager;
  48. $this->instanceName = $instanceName;
  49. $this->isShared = $shared;
  50. }
  51. /**
  52. * @return array
  53. */
  54. public function __sleep()
  55. {
  56. return ['subject', 'isShared'];
  57. }
  58. /**
  59. * Retrieve ObjectManager from global scope
  60. *
  61. * @return void
  62. */
  63. public function __wakeup()
  64. {
  65. $this->objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  66. }
  67. /**
  68. * Clone proxied instance
  69. *
  70. * @return void
  71. */
  72. public function __clone()
  73. {
  74. $this->subject = clone $this->_getSubject();
  75. }
  76. /**
  77. * Get proxied instance
  78. *
  79. * @return \Magento\Framework\Mview\Config\Data
  80. */
  81. protected function _getSubject()
  82. {
  83. if (!$this->subject) {
  84. $this->subject = true === $this->isShared ? $this->objectManager->get(
  85. $this->instanceName
  86. ) : $this->objectManager->create(
  87. $this->instanceName
  88. );
  89. }
  90. return $this->subject;
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. public function merge(array $config)
  96. {
  97. $this->_getSubject()->merge($config);
  98. }
  99. /**
  100. * {@inheritdoc}
  101. */
  102. public function get($path = null, $default = null)
  103. {
  104. return $this->_getSubject()->get($path, $default);
  105. }
  106. }