Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StoresData.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
8 namespace Magento\Store\Model;
9 
14 {
18  const CACHE_TAG = 'store_relations';
19 
23  private $cache;
24 
28  private $readerList;
29 
33  private $serializer;
34 
40  public function __construct(
41  \Magento\Framework\Cache\FrontendInterface $cache,
42  \Magento\Store\Model\StoreResolver\ReaderList $readerList,
43  \Magento\Framework\Serialize\SerializerInterface $serializer
44  ) {
45  $this->cache = $cache;
46  $this->readerList = $readerList;
47  $this->serializer = $serializer;
48  }
49 
57  public function getStoresData(string $runMode, string $scopeCode = null) : array
58  {
59  $cacheKey = 'resolved_stores_' . md5($runMode . $scopeCode);
60  $cacheData = $this->cache->load($cacheKey);
61  if ($cacheData) {
62  $storesData = $this->serializer->unserialize($cacheData);
63  } else {
64  $reader = $this->readerList->getReader($runMode);
65  $storesData = [$reader->getAllowedStoreIds($scopeCode), $reader->getDefaultStoreId($scopeCode)];
66  $this->cache->save(
67  $this->serializer->serialize($storesData),
68  $cacheKey,
69  [
72  ]
73  );
74  }
75  return $storesData;
76  }
77 }
getStoresData(string $runMode, string $scopeCode=null)
Definition: StoresData.php:57
__construct(\Magento\Framework\Cache\FrontendInterface $cache, \Magento\Store\Model\StoreResolver\ReaderList $readerList, \Magento\Framework\Serialize\SerializerInterface $serializer)
Definition: StoresData.php:40