Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
WebsiteDimensionProvider.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 use Magento\Store\Model\ResourceModel\Website\CollectionFactory as WebsiteCollectionFactory;
15 
17 {
22  const DIMENSION_NAME = 'ws';
23 
27  private $collectionFactory;
28 
32  private $websitesDataIterator;
33 
37  private $dimensionFactory;
38 
43  public function __construct(WebsiteCollectionFactory $collectionFactory, DimensionFactory $dimensionFactory)
44  {
45  $this->dimensionFactory = $dimensionFactory;
46  $this->collectionFactory = $collectionFactory;
47  }
48 
52  public function getIterator(): \Traversable
53  {
54  foreach ($this->getWebsites() as $website) {
55  yield $this->dimensionFactory->create(self::DIMENSION_NAME, (string)$website);
56  }
57  }
58 
62  private function getWebsites(): array
63  {
64  if ($this->websitesDataIterator === null) {
65  $websites = $this->collectionFactory->create()
66  ->addFieldToFilter('code', ['neq' => Store::ADMIN_CODE])
67  ->getAllIds();
68  $this->websitesDataIterator = is_array($websites) ? $websites : [];
69  }
70 
71  return $this->websitesDataIterator;
72  }
73 }
__construct(WebsiteCollectionFactory $collectionFactory, DimensionFactory $dimensionFactory)