Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PathInfoProcessor.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 {
18  private $storePathInfoValidator;
19 
23  private $config;
24 
29  public function __construct(
30  \Magento\Store\App\Request\StorePathInfoValidator $storePathInfoValidator,
31  \Magento\Framework\App\Config\ReinitableConfigInterface $config
32  ) {
33  $this->storePathInfoValidator = $storePathInfoValidator;
34  $this->config = $config;
35  }
36 
46  public function process(\Magento\Framework\App\RequestInterface $request, $pathInfo) : string
47  {
48  //can store code be used in url
49  if ((bool)$this->config->getValue(\Magento\Store\Model\Store::XML_PATH_STORE_IN_URL)) {
50  $storeCode = $this->storePathInfoValidator->getValidStoreCode($request, $pathInfo);
51  if (!empty($storeCode)) {
52  if (!$request->isDirectAccessFrontendName($storeCode)) {
53  $pathInfo = $this->trimStoreCodeFromPathInfo($pathInfo, $storeCode);
54  } else {
55  //no route in case we're trying to access a store that has the same code as a direct access
56  $request->setActionName(\Magento\Framework\App\Router\Base::NO_ROUTE);
57  }
58  }
59  }
60  return $pathInfo;
61  }
62 
70  private function trimStoreCodeFromPathInfo(string $pathInfo, string $storeCode) : ?string
71  {
72  if (substr($pathInfo, 0, strlen('/' . $storeCode)) == '/'. $storeCode) {
73  $pathInfo = substr($pathInfo, strlen($storeCode)+1);
74  }
75  return empty($pathInfo) ? '/' : $pathInfo;
76  }
77 }
$config
Definition: fraud_order.php:17
$storeCode
Definition: indexer.php:15
__construct(\Magento\Store\App\Request\StorePathInfoValidator $storePathInfoValidator, \Magento\Framework\App\Config\ReinitableConfigInterface $config)
process(\Magento\Framework\App\RequestInterface $request, $pathInfo)