From b9bb10337c982512e126253bc73905f8f1e67c31 Mon Sep 17 00:00:00 2001 From: Thomas Klein Date: Mon, 18 Mar 2024 21:00:06 +0100 Subject: [PATCH] Fix memory leak --- App/Request/PathInfoProcessor.php | 48 +++++++++++++++++++ Plugin/App/Request/PathInfo.php | 30 ------------ Plugin/App/Request/StorePathInfoValidator.php | 36 ++++++++++++++ Service/StorePathFixer.php | 35 -------------- etc/di.xml | 9 +++- 5 files changed, 91 insertions(+), 67 deletions(-) create mode 100644 App/Request/PathInfoProcessor.php delete mode 100644 Plugin/App/Request/PathInfo.php create mode 100644 Plugin/App/Request/StorePathInfoValidator.php delete mode 100644 Service/StorePathFixer.php diff --git a/App/Request/PathInfoProcessor.php b/App/Request/PathInfoProcessor.php new file mode 100644 index 0000000..4af1aca --- /dev/null +++ b/App/Request/PathInfoProcessor.php @@ -0,0 +1,48 @@ +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; + } +} diff --git a/Plugin/App/Request/PathInfo.php b/Plugin/App/Request/PathInfo.php deleted file mode 100644 index 7867313..0000000 --- a/Plugin/App/Request/PathInfo.php +++ /dev/null @@ -1,30 +0,0 @@ -config->isEnabled()) { - $requestUri = $this->storePathFixer->fix($baseUrl ? $requestUri : $this->request->getUriString(), $requestUri); - } - - return [$requestUri, $baseUrl]; - } -} diff --git a/Plugin/App/Request/StorePathInfoValidator.php b/Plugin/App/Request/StorePathInfoValidator.php new file mode 100644 index 0000000..3779c32 --- /dev/null +++ b/Plugin/App/Request/StorePathInfoValidator.php @@ -0,0 +1,36 @@ +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]; + } +} diff --git a/Service/StorePathFixer.php b/Service/StorePathFixer.php deleted file mode 100644 index fa19757..0000000 --- a/Service/StorePathFixer.php +++ /dev/null @@ -1,35 +0,0 @@ -storeRepository->getList() as $store) { - if ($store->getId() && str_starts_with($baseUrl, $store->getBaseUrl())) { - return $this->uriUtils->replacePathCode($requestUri, $store); - } - } - - return $requestUri; - } -} diff --git a/etc/di.xml b/etc/di.xml index a0a91a3..743d26d 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -15,10 +15,15 @@ + + + Opengento\StorePathUrl\App\Request\PathInfoProcessor + + - - + +