-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8992f22
commit b9bb103
Showing
5 changed files
with
91 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\StorePathUrl\App\Request; | ||
|
||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\App\Router\Base; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Store\Api\StoreRepositoryInterface; | ||
use Magento\Store\App\Request\PathInfoProcessor as AppPathInfoProcessor; | ||
use Magento\Store\App\Request\StorePathInfoValidator; | ||
use Opengento\StorePathUrl\Service\PathResolver; | ||
|
||
use function str_starts_with; | ||
use function strlen; | ||
use function substr; | ||
|
||
class PathInfoProcessor extends AppPathInfoProcessor | ||
{ | ||
public function __construct( | ||
private StorePathInfoValidator $storePathInfoValidator, | ||
private PathResolver $pathResolver, | ||
private StoreRepositoryInterface $storeRepository | ||
) {} | ||
|
||
public function process(RequestInterface $request, $pathInfo): string | ||
{ | ||
$storeCode = $this->storePathInfoValidator->getValidStoreCode($request, $pathInfo); | ||
if (!empty($storeCode)) { | ||
try { | ||
$path = $this->pathResolver->resolve($this->storeRepository->getActiveStoreByCode($storeCode)); | ||
} catch (LocalizedException) { | ||
return $pathInfo; | ||
} | ||
if (!$request->isDirectAccessFrontendName($path)) { | ||
$pathInfo = substr($pathInfo, strlen($path) + (int)str_starts_with($pathInfo, '/')) ?: '/'; | ||
} else { | ||
//no route in case we're trying to access a store that has the same code as a direct access | ||
$request->setActionName(Base::NO_ROUTE); | ||
} | ||
} | ||
|
||
return $pathInfo; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\StorePathUrl\Plugin\App\Request; | ||
|
||
use Magento\Framework\App\Request\Http; | ||
use Magento\Store\Api\StoreRepositoryInterface; | ||
use Magento\Store\App\Request\StorePathInfoValidator as Subject; | ||
use Magento\Store\Model\Store; | ||
use Opengento\StorePathUrl\Model\Config; | ||
|
||
class StorePathInfoValidator | ||
{ | ||
public function __construct( | ||
private Config $config, | ||
private StoreRepositoryInterface $storeRepository | ||
) {} | ||
|
||
public function beforeGetValidStoreCode(Subject $subject, Http $request, string $pathInfo = ''): array | ||
{ | ||
if ($this->config->isEnabled()) { | ||
$uri = $request->getUriString(); | ||
/** @var Store $store */ | ||
foreach ($this->storeRepository->getList() as $store) { | ||
if ($store->getId() && str_starts_with($uri, $store->getBaseUrl())) { | ||
$pathInfo = $store->getCode(); | ||
} | ||
} | ||
} | ||
|
||
return [$request, $pathInfo]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters