1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2011 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
+
6
7
declare (strict_types=1 );
7
8
8
9
namespace Magento \Store \App \Request ;
11
12
use Magento \Framework \App \Request \Http ;
12
13
use Magento \Framework \App \Request \PathInfo ;
13
14
use Magento \Framework \Exception \NoSuchEntityException ;
15
+ use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
14
16
use Magento \Store \Api \StoreRepositoryInterface ;
15
17
use Magento \Store \Model \Store ;
16
18
use Magento \Store \Model \StoreIsInactiveException ;
19
21
/**
20
22
* Gets the store from the path if valid
21
23
*/
22
- class StorePathInfoValidator
24
+ class StorePathInfoValidator implements ResetAfterRequestInterface
23
25
{
24
26
/**
25
27
* Store Config
@@ -43,6 +45,11 @@ class StorePathInfoValidator
43
45
*/
44
46
private $ storeCodeValidator ;
45
47
48
+ /**
49
+ * @var array
50
+ */
51
+ private array $ validatedStoreCodes = [];
52
+
46
53
/**
47
54
* @param ScopeConfigInterface $config
48
55
* @param StoreRepositoryInterface $storeRepository
@@ -79,17 +86,25 @@ public function getValidStoreCode(Http $request, string $pathInfo = '') : ?strin
79
86
$ pathInfo = $ this ->pathInfo ->getPathInfo ($ request ->getRequestUri (), $ request ->getBaseUrl ());
80
87
}
81
88
$ storeCode = $ this ->getStoreCode ($ pathInfo );
89
+
82
90
if (empty ($ storeCode ) || $ storeCode === Store::ADMIN_CODE || !$ this ->storeCodeValidator ->isValid ($ storeCode )) {
83
91
return null ;
84
92
}
85
93
94
+ if (array_key_exists ($ storeCode , $ this ->validatedStoreCodes )) {
95
+ return $ this ->validatedStoreCodes [$ storeCode ];
96
+ }
97
+
86
98
try {
87
99
$ this ->storeRepository ->getActiveStoreByCode ($ storeCode );
88
100
101
+ $ this ->validatedStoreCodes [$ storeCode ] = $ storeCode ;
89
102
return $ storeCode ;
90
103
} catch (NoSuchEntityException $ e ) {
104
+ $ this ->validatedStoreCodes [$ storeCode ] = null ;
91
105
return null ;
92
106
} catch (StoreIsInactiveException $ e ) {
107
+ $ this ->validatedStoreCodes [$ storeCode ] = null ;
93
108
return null ;
94
109
}
95
110
}
@@ -105,4 +120,12 @@ private function getStoreCode(string $pathInfo) : string
105
120
$ pathParts = explode ('/ ' , ltrim ($ pathInfo , '/ ' ), 2 );
106
121
return current ($ pathParts );
107
122
}
123
+
124
+ /**
125
+ * @inheritDoc
126
+ */
127
+ public function _resetState (): void
128
+ {
129
+ $ this ->validatedStoreCodes = [];
130
+ }
108
131
}
0 commit comments