StoreDimensionProvider.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Store\Model;
  8. use Magento\Framework\Indexer\DimensionFactory;
  9. use Magento\Framework\Indexer\DimensionProviderInterface;
  10. /**
  11. * Provide a list of stores as Dimension
  12. */
  13. class StoreDimensionProvider implements DimensionProviderInterface
  14. {
  15. /**
  16. * Hold the name of Store dimension. Uses for retrieve dimension value.
  17. * Used "scope" name for support current indexer implementation
  18. */
  19. const DIMENSION_NAME = 'scope';
  20. /**
  21. * @var StoreManagerInterface
  22. */
  23. private $storeManager;
  24. /**
  25. * @var DimensionFactory
  26. */
  27. private $dimensionFactory;
  28. /**
  29. * @param StoreManagerInterface $storeManager
  30. * @param DimensionFactory $dimensionFactory
  31. */
  32. public function __construct(StoreManagerInterface $storeManager, DimensionFactory $dimensionFactory)
  33. {
  34. $this->storeManager = $storeManager;
  35. $this->dimensionFactory = $dimensionFactory;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function getIterator(): \Traversable
  41. {
  42. foreach (array_keys($this->storeManager->getStores()) as $storeId) {
  43. yield [self::DIMENSION_NAME => $this->dimensionFactory->create(self::DIMENSION_NAME, (string)$storeId)];
  44. }
  45. }
  46. }