88namespace Magento \Framework \ObjectManager \Resetter ;
99
1010use Magento \Framework \App \ObjectManager ;
11- use Magento \Framework \Component \ComponentRegistrar ;
12- use Magento \Framework \Component \ComponentRegistrarInterface ;
1311use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
1412use Magento \Framework \ObjectManagerInterface ;
1513use WeakMap ;
1917 */
2018class Resetter implements ResetterInterface
2119{
22- public const RESET_PATH = 'reset.json ' ;
23- private const RESET_STATE_METHOD = '_resetState ' ;
20+ public const RESET_PATH = '/app/etc/reset.php ' ;
2421
2522 /** @var WeakMap instances to be reset after request */
2623 private WeakMap $ resetAfterWeakMap ;
@@ -31,6 +28,22 @@ class Resetter implements ResetterInterface
3128 /** @var WeakMapSorter|null Note: We use temporal coupling here because of chicken/egg during bootstrapping */
3229 private ?WeakMapSorter $ weakMapSorter = null ;
3330
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+
3447 /**
3548 * @var array
3649 */
@@ -39,36 +52,16 @@ class Resetter implements ResetterInterface
3952 /**
4053 * Constructor
4154 *
42- * @param ComponentRegistrarInterface $componentRegistrar
43- * @param array $classList
4455 * @return void
4556 * @phpcs:disable Magento2.Functions.DiscouragedFunction
4657 */
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 ()
6759 {
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 )) ;
7163 }
64+ $ this ->resetAfterWeakMap = new WeakMap ;
7265 }
7366
7467 /**
@@ -79,10 +72,7 @@ private function getPaths(): \Generator
7972 */
8073 public function addInstance (object $ instance ) : void
8174 {
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 )])) {
8676 $ this ->resetAfterWeakMap [$ instance ] = true ;
8777 }
8878 }
@@ -134,10 +124,6 @@ public function setObjectManager(ObjectManagerInterface $objectManager) : void
134124 */
135125 private function resetStateWithReflection (object $ instance )
136126 {
137- if (\method_exists ($ instance , self ::RESET_STATE_METHOD )) {
138- $ instance ->{self ::RESET_STATE_METHOD }();
139- return ;
140- }
141127 $ className = \get_class ($ instance );
142128 $ reflectionClass = $ this ->reflectionCache [$ className ]
143129 ?? $ this ->reflectionCache [$ className ] = new \ReflectionClass ($ className );
0 commit comments