Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StoreSwitcher.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
8 namespace Magento\Store\Model;
9 
12 
17 {
21  private $storeSwitchers;
22 
27  public function __construct(array $storeSwitchers)
28  {
29  foreach ($storeSwitchers as $switcherName => $switcherInstance) {
30  if (!$switcherInstance instanceof StoreSwitcherInterface) {
31  throw new \InvalidArgumentException(
32  "Store switcher '{$switcherName}' is expected to implement interface "
33  . StoreSwitcherInterface::class
34  );
35  }
36  }
37  $this->storeSwitchers = $storeSwitchers;
38  }
39 
48  public function switch(StoreInterface $fromStore, StoreInterface $targetStore, string $redirectUrl): string
49  {
50  $targetUrl = $redirectUrl;
51 
52  foreach ($this->storeSwitchers as $storeSwitcher) {
53  $targetUrl = $storeSwitcher->switch($fromStore, $targetStore, $targetUrl);
54  }
55 
56  return $targetUrl;
57  }
58 }
__construct(array $storeSwitchers)