StoreScopeProvider.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Model;
  7. use Magento\Framework\Model\Entity\ScopeProviderInterface;
  8. use Magento\Store\Model\Store;
  9. use Magento\Framework\Model\Entity\ScopeFactory;
  10. /**
  11. * Class StoreScope
  12. */
  13. class StoreScopeProvider implements ScopeProviderInterface
  14. {
  15. /**
  16. * @var StoreManagerInterface
  17. */
  18. private $storeManager;
  19. /**
  20. * @var ScopeFactory
  21. */
  22. private $scopeFactory;
  23. /**
  24. * StoreScopeProvider constructor.
  25. *
  26. * @param StoreManagerInterface $storeManager
  27. * @param ScopeFactory $scopeFactory
  28. */
  29. public function __construct(
  30. StoreManagerInterface $storeManager,
  31. ScopeFactory $scopeFactory
  32. ) {
  33. $this->storeManager = $storeManager;
  34. $this->scopeFactory = $scopeFactory;
  35. }
  36. /**
  37. * @param string $entityType
  38. * @param array $entityData
  39. * @return \Magento\Framework\Model\Entity\ScopeInterface
  40. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  41. */
  42. public function getContext($entityType, $entityData = [])
  43. {
  44. if (isset($entityData[Store::STORE_ID])) {
  45. $value = $entityData[Store::STORE_ID];
  46. } else {
  47. $value = (int)$this->storeManager->getStore(true)->getId();
  48. }
  49. $identifier = Store::STORE_ID;
  50. $fallback = null;
  51. if ($value != Store::DEFAULT_STORE_ID) {
  52. $fallback = $this->scopeFactory->create($identifier, Store::DEFAULT_STORE_ID);
  53. }
  54. return $this->scopeFactory->create($identifier, $value, $fallback);
  55. }
  56. }