12
12
use Magento \Framework \App \State ;
13
13
use Magento \Framework \App \Utility \ReflectionClassFactory ;
14
14
use Magento \Framework \Config \CacheInterface ;
15
+ use Magento \Framework \Exception \FileSystemException ;
15
16
use Magento \Framework \Module \Dir \Reader as ModuleReader ;
16
17
use Magento \Framework \Serialize \Serializer \Serialize ;
17
18
use Magento \Framework \Serialize \SerializerInterface ;
@@ -61,7 +62,7 @@ class ActionList
61
62
/**
62
63
* @var ReflectionClassFactory|null
63
64
*/
64
- private $ classReflectionFactory ;
65
+ private $ reflectionClassFactory ;
65
66
66
67
/**
67
68
* @param CacheInterface $cache
@@ -70,6 +71,10 @@ class ActionList
70
71
* @param string $cacheKey
71
72
* @param array $reservedWords
72
73
* @param SerializerInterface|null $serializer
74
+ * @param State|null $state
75
+ * @param DirectoryList|null $directoryList
76
+ * @param ReflectionClassFactory|null $reflectionClassFactory
77
+ * @throws FileSystemException
73
78
*/
74
79
public function __construct (
75
80
CacheInterface $ cache ,
@@ -78,16 +83,19 @@ public function __construct(
78
83
$ cacheKey = 'app_action_list ' ,
79
84
$ reservedWords = [],
80
85
SerializerInterface $ serializer = null ,
86
+ State $ state = null ,
87
+ DirectoryList $ directoryList = null ,
81
88
ReflectionClassFactory $ reflectionClassFactory = null
82
89
) {
83
90
$ this ->reservedWords = array_merge ($ reservedWords , $ this ->reservedWords );
84
91
$ this ->actionInterface = $ actionInterface ;
85
- $ objectManager = ObjectManager::getInstance ();
86
- $ this ->serializer = $ serializer ?: $ objectManager ->get (Serialize::class);
87
- $ state = $ objectManager ->get (State::class);
92
+ $ this ->serializer = $ serializer ?: ObjectManager::getInstance ()->get (Serialize::class);
93
+ $ state = $ state ?: ObjectManager::getInstance ()->get (State::class);
94
+ $ this ->reflectionClassFactory = $ reflectionClassFactory
95
+ ?: ObjectManager::getInstance ()->get (ReflectionClassFactory::class);
88
96
89
97
if ($ state ->getMode () === State::MODE_PRODUCTION ) {
90
- $ directoryList = $ objectManager ->get (DirectoryList::class);
98
+ $ directoryList = $ directoryList ?: ObjectManager:: getInstance () ->get (DirectoryList::class);
91
99
$ file = $ directoryList ->getPath (DirectoryList::GENERATED_METADATA )
92
100
. '/ ' . $ cacheKey . '. ' . 'php ' ;
93
101
@@ -105,8 +113,6 @@ public function __construct(
105
113
$ this ->actions = $ this ->serializer ->unserialize ($ data );
106
114
}
107
115
}
108
- $ this ->classReflectionFactory = $ reflectionClassFactory ?:
109
- ObjectManager::getInstance ()->get (ReflectionClassFactory::class);
110
116
}
111
117
112
118
/**
@@ -119,7 +125,7 @@ public function __construct(
119
125
* @return null|string
120
126
* @throws ReflectionException
121
127
*/
122
- public function get ($ module , $ area , $ namespace , $ action, $ reflectionClass = null )
128
+ public function get ($ module , $ area , $ namespace , $ action )
123
129
{
124
130
if ($ area ) {
125
131
$ area = '\\' . $ area ;
@@ -139,7 +145,7 @@ public function get($module, $area, $namespace, $action, $reflectionClass = null
139
145
)
140
146
);
141
147
try {
142
- if ($ this ->validateActionClass ($ fullPath, $ reflectionClass )) {
148
+ if ($ this ->validateActionClass ($ fullPath )) {
143
149
return $ this ->actions [$ fullPath ];
144
150
}
145
151
} catch (ReflectionException $ e ) {
@@ -153,19 +159,16 @@ public function get($module, $area, $namespace, $action, $reflectionClass = null
153
159
* Validate Action Class
154
160
*
155
161
* @param string $fullPath
156
- * @param ReflectionClass|null $reflectionClass
157
162
* @return bool
158
163
* @throws ReflectionException
159
164
*/
160
- private function validateActionClass (string $ fullPath, $ reflectionClass ): bool
165
+ private function validateActionClass (string $ fullPath ): bool
161
166
{
162
167
if (isset ($ this ->actions [$ fullPath ])) {
163
168
if (!is_subclass_of ($ this ->actions [$ fullPath ], $ this ->actionInterface )) {
164
169
return false ;
165
170
}
166
- if (!$ reflectionClass ) {
167
- $ reflectionClass = $ this ->classReflectionFactory ->create ($ this ->actions [$ fullPath ]);
168
- }
171
+ $ reflectionClass = $ this ->reflectionClassFactory ->create ($ this ->actions [$ fullPath ]);
169
172
if ($ reflectionClass ->isInstantiable ()) {
170
173
return true ;
171
174
}
0 commit comments