Skip to content

Commit 67312b1

Browse files
authored
Prevent recursion over plugin and improve readability
1 parent 994cb7f commit 67312b1

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

Plugin/App/Request/StorePathInfoValidator.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,39 @@
2222

2323
class StorePathInfoValidator
2424
{
25+
private int $stack = 0;
26+
2527
public function __construct(
2628
private Config $config,
2729
private StoreRepositoryInterface $storeRepository
2830
) {}
2931

3032
public function beforeGetValidStoreCode(Subject $subject, Http $request, string $pathInfo = ''): array
3133
{
32-
if ($this->config->isBaseUrlResolverEnabled()) {
33-
$originalPathInfo = $pathInfo;
34-
$uri = strtok($request->getUriString(), '?') . '/';
35-
if ($uri !== false) {
36-
if ($pathInfo === '') {
37-
$pathInfo = parse_url($uri, PHP_URL_PATH);
38-
if ($pathInfo === false) {
39-
return [$request, $originalPathInfo];
40-
}
41-
$pathInfo = strtok($pathInfo, '/');
34+
if (++$this->stack === 1 && $this->config->isBaseUrlResolverEnabled()) {
35+
$storeCode = $this->resolveStoreCode($pathInfo);
36+
$pathInfo = $storeCode === '' ? $pathInfo : $storeCode;
37+
}
38+
$this->stack--;
39+
40+
return [$request, $pathInfo];
41+
}
42+
43+
private function resolveStoreCode(string $pathInfo): string
44+
{
45+
$uri = strtok($request->getUriString(), '?') . '/';
46+
if ($uri !== false) {
47+
if ($pathInfo === '') {
48+
$pathInfo = parse_url($uri, PHP_URL_PATH);
49+
if ($pathInfo === false) {
50+
return '';
4251
}
43-
$pathInfo = $pathInfo === false ? $this->resolveByWebUrl($uri) : $this->resolveByLinkUrl($uri);
44-
$pathInfo = $pathInfo === '' ? $originalPathInfo : $pathInfo;
52+
$pathInfo = strtok($pathInfo, '/');
4553
}
54+
$pathInfo = $pathInfo === false ? $this->resolveByWebUrl($uri) : $this->resolveByLinkUrl($uri);
4655
}
4756

48-
return [$request, $pathInfo];
57+
return $pathInfo;
4958
}
5059

5160
private function resolveByLinkUrl(string $uri): string

0 commit comments

Comments
 (0)