8
8
namespace Magento \Framework \ObjectManager \Resetter ;
9
9
10
10
use Magento \Framework \App \ObjectManager ;
11
- use Magento \Framework \Component \ComponentRegistrar ;
12
- use Magento \Framework \Component \ComponentRegistrarInterface ;
13
11
use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
14
12
use Magento \Framework \ObjectManagerInterface ;
15
13
use WeakMap ;
19
17
*/
20
18
class Resetter implements ResetterInterface
21
19
{
22
- public const RESET_PATH = 'reset.json ' ;
23
- private const RESET_STATE_METHOD = '_resetState ' ;
20
+ public const RESET_PATH = '/app/etc/reset.php ' ;
24
21
25
22
/** @var WeakMap instances to be reset after request */
26
23
private WeakMap $ resetAfterWeakMap ;
@@ -31,6 +28,22 @@ class Resetter implements ResetterInterface
31
28
/** @var WeakMapSorter|null Note: We use temporal coupling here because of chicken/egg during bootstrapping */
32
29
private ?WeakMapSorter $ weakMapSorter = null ;
33
30
31
+ /**
32
+ * @var array
33
+ *
34
+ */
35
+ private array $ classList = [
36
+ //phpcs:disable Magento2.PHP.LiteralNamespaces
37
+ 'Magento\Framework\GraphQl\Query\Fields ' => true ,
38
+ 'Magento\Store\Model\Store ' => [
39
+ "_baseUrlCache " => [],
40
+ "_configCache " => null ,
41
+ "_configCacheBaseNodes " => [],
42
+ "_dirCache " => [],
43
+ "_urlCache " => []
44
+ ]
45
+ ];
46
+
34
47
/**
35
48
* @var array
36
49
*/
@@ -39,36 +52,16 @@ class Resetter implements ResetterInterface
39
52
/**
40
53
* Constructor
41
54
*
42
- * @param ComponentRegistrarInterface $componentRegistrar
43
- * @param array $classList
44
55
* @return void
45
56
* @phpcs:disable Magento2.Functions.DiscouragedFunction
46
57
*/
47
- public function __construct (
48
- private ComponentRegistrarInterface $ componentRegistrar ,
49
- private array $ classList = [],
50
- ) {
51
- foreach ($ this ->getPaths () as $ resetPath ) {
52
- if (!\file_exists ($ resetPath )) {
53
- continue ;
54
- }
55
- $ resetData = \json_decode (\file_get_contents ($ resetPath ), true );
56
- $ this ->classList = array_replace ($ this ->classList , $ resetData );
57
- }
58
- $ this ->resetAfterWeakMap = new WeakMap ;
59
- }
60
-
61
- /**
62
- * Get paths for reset json
63
- *
64
- * @return \Generator<string>
65
- */
66
- private function getPaths (): \Generator
58
+ public function __construct ()
67
59
{
68
- yield BP . ' /app/etc/ ' . self ::RESET_PATH ;
69
- foreach ( $ this -> componentRegistrar -> getPaths (ComponentRegistrar:: MODULE ) as $ modulePath ) {
70
- yield $ modulePath . ' /etc/ ' . self ::RESET_PATH ;
60
+ if ( \file_exists ( BP . self ::RESET_PATH )) {
61
+ // phpcs:ignore Magento2.Security.IncludeFile.FoundIncludeFile
62
+ $ this -> classList = array_replace ( $ this -> classList , ( require BP . self ::RESET_PATH )) ;
71
63
}
64
+ $ this ->resetAfterWeakMap = new WeakMap ;
72
65
}
73
66
74
67
/**
@@ -79,10 +72,7 @@ private function getPaths(): \Generator
79
72
*/
80
73
public function addInstance (object $ instance ) : void
81
74
{
82
- if ($ instance instanceof ResetAfterRequestInterface
83
- || \method_exists ($ instance , self ::RESET_STATE_METHOD )
84
- || isset ($ this ->classList [\get_class ($ instance )])
85
- ) {
75
+ if ($ instance instanceof ResetAfterRequestInterface || isset ($ this ->classList [\get_class ($ instance )])) {
86
76
$ this ->resetAfterWeakMap [$ instance ] = true ;
87
77
}
88
78
}
@@ -134,10 +124,6 @@ public function setObjectManager(ObjectManagerInterface $objectManager) : void
134
124
*/
135
125
private function resetStateWithReflection (object $ instance )
136
126
{
137
- if (\method_exists ($ instance , self ::RESET_STATE_METHOD )) {
138
- $ instance ->{self ::RESET_STATE_METHOD }();
139
- return ;
140
- }
141
127
$ className = \get_class ($ instance );
142
128
$ reflectionClass = $ this ->reflectionCache [$ className ]
143
129
?? $ this ->reflectionCache [$ className ] = new \ReflectionClass ($ className );
0 commit comments