@@ -31,49 +31,7 @@ protected function _getDefaultResultClassName($modelClassName)
31
31
*/
32
32
protected function _getClassProperties ()
33
33
{
34
- return [
35
- [
36
- 'name ' => 'pluginLocator ' ,
37
- 'visibility ' => 'protected ' ,
38
- 'docblock ' => [
39
- 'shortDescription ' => 'Object Manager instance ' ,
40
- 'tags ' => [[
41
- 'name ' => 'var ' ,
42
- 'description ' => '\Magento\Framework\ObjectManagerInterface ' ,
43
- ]],
44
- ],
45
- ],
46
- [
47
- 'name ' => 'pluginList ' ,
48
- 'visibility ' => 'protected ' ,
49
- 'docblock ' => [
50
- 'shortDescription ' => 'List of plugins ' ,
51
- 'tags ' => [[
52
- 'name ' => 'var ' ,
53
- 'description ' => '\Magento\Framework\Interception\PluginListInterface ' ,
54
- ]],
55
- ]
56
- ],
57
- [
58
- 'name ' => 'chain ' ,
59
- 'visibility ' => 'protected ' ,
60
- 'docblock ' => [
61
- 'shortDescription ' => 'Invocation chain ' ,
62
- 'tags ' => [[
63
- 'name ' => 'var ' ,
64
- 'description ' => '\Magento\Framework\Interception\ChainInterface ' ,
65
- ]],
66
- ]
67
- ],
68
- [
69
- 'name ' => 'subjectType ' ,
70
- 'visibility ' => 'protected ' ,
71
- 'docblock ' => [
72
- 'shortDescription ' => 'Subject type name ' ,
73
- 'tags ' => [['name ' => 'var ' , 'description ' => 'string ' ]],
74
- ]
75
- ]
76
- ];
34
+ return [];
77
35
}
78
36
79
37
/**
@@ -113,92 +71,6 @@ protected function _getClassMethods()
113
71
{
114
72
$ methods = [$ this ->_getDefaultConstructorDefinition ()];
115
73
116
- $ methods [] = [
117
- 'name ' => '___init ' ,
118
- 'body ' => "\$this->pluginLocator = \\Magento \\Framework \\App \\ObjectManager::getInstance(); \n" .
119
- "\$this->pluginList = \$this->pluginLocator->get('Magento \\Framework \\Interception \\PluginListInterface'); \n" .
120
- "\$this->chain = \$this->pluginLocator->get('Magento \\Framework \\Interception \\ChainInterface'); \n" .
121
- "\$this->subjectType = get_parent_class( \$this); \n" .
122
- "if (method_exists( \$this->subjectType, '___init')) { \n" .
123
- " parent::___init(); \n" .
124
- "} \n" ,
125
- ];
126
-
127
- $ methods [] = [
128
- 'name ' => '___callParent ' ,
129
- 'parameters ' => [
130
- ['name ' => 'method ' , 'type ' => 'string ' ],
131
- ['name ' => 'arguments ' , 'type ' => 'array ' ],
132
- ],
133
- 'body ' => 'return call_user_func_array(array( \'parent \', $method), $arguments); ' ,
134
- ];
135
-
136
- $ methods [] = [
137
- 'name ' => '__sleep ' ,
138
- 'body ' => "if (method_exists(get_parent_class( \$this), '__sleep')) { \n" .
139
- " return array_diff(parent::__sleep(), array('pluginLocator', 'pluginList', 'chain', 'subjectType')); " .
140
- "\n} else { \n" .
141
- " return array_keys(get_class_vars(get_parent_class( \$this))); \n" .
142
- "} \n" ,
143
- ];
144
-
145
- $ methods [] = [
146
- 'name ' => '__wakeup ' ,
147
- 'body ' => "if (method_exists(get_parent_class( \$this), '__wakeup')) { \n"
148
- . " parent::__wakeup(); \n"
149
- . "} \n"
150
- . "\$this->___init(); \n" ,
151
- ];
152
-
153
- $ methods [] = [
154
- 'name ' => '___callPlugins ' ,
155
- 'visibility ' => 'protected ' ,
156
- 'parameters ' => [
157
- ['name ' => 'method ' , 'type ' => 'string ' ],
158
- ['name ' => 'arguments ' , 'type ' => 'array ' ],
159
- ['name ' => 'pluginInfo ' , 'type ' => 'array ' ],
160
- ],
161
- 'body ' => "\$capMethod = ucfirst( \$method); \n" .
162
- "\$result = null; \n" .
163
- "if (isset( \$pluginInfo[ \\Magento \\Framework \\Interception \\DefinitionInterface::LISTENER_BEFORE])) { \n" .
164
- " // Call 'before' listeners \n" .
165
- " foreach ( \$pluginInfo[ \\Magento \\Framework \\Interception \\DefinitionInterface::LISTENER_BEFORE] as \$code) { \n" .
166
- " \$beforeResult = call_user_func_array( \n" .
167
- " array( \$this->pluginList->getPlugin( \$this->subjectType, \$code), 'before' " .
168
- ". \$capMethod), array_merge(array( \$this), \$arguments) \n" .
169
- " ); \n" .
170
- " if ( \$beforeResult) { \n" .
171
- " \$arguments = \$beforeResult; \n" .
172
- " } \n" .
173
- " } \n" .
174
- "} \n" .
175
- "if (isset( \$pluginInfo[ \\Magento \\Framework \\Interception \\DefinitionInterface::LISTENER_AROUND])) { \n" .
176
- " // Call 'around' listener \n" .
177
- " \$chain = \$this->chain; \n" .
178
- " \$type = \$this->subjectType; \n" .
179
- " \$subject = \$this; \n" .
180
- " \$code = \$pluginInfo[ \\Magento \\Framework \\Interception \\DefinitionInterface::LISTENER_AROUND]; \n" .
181
- " \$next = function () use ( \$chain, \$type, \$method, \$subject, \$code) { \n" .
182
- " return \$chain->invokeNext( \$type, \$method, \$subject, func_get_args(), \$code); \n" .
183
- " }; \n" .
184
- " \$result = call_user_func_array( \n" .
185
- " array( \$this->pluginList->getPlugin( \$this->subjectType, \$code), 'around' . \$capMethod), \n" .
186
- " array_merge(array( \$this, \$next), \$arguments) \n" .
187
- " ); \n" .
188
- "} else { \n" .
189
- " // Call original method \n" .
190
- " \$result = call_user_func_array(array('parent', \$method), \$arguments); \n" .
191
- "} \n" .
192
- "if (isset( \$pluginInfo[ \\Magento \\Framework \\Interception \\DefinitionInterface::LISTENER_AFTER])) { \n" .
193
- " // Call 'after' listeners \n" .
194
- " foreach ( \$pluginInfo[ \\Magento \\Framework \\Interception \\DefinitionInterface::LISTENER_AFTER] as \$code) { \n" .
195
- " \$result = \$this->pluginList->getPlugin( \$this->subjectType, \$code) \n" .
196
- " ->{'after' . \$capMethod}( \$this, \$result); \n" .
197
- " } \n" .
198
- "} \n" .
199
- "return \$result; \n" ,
200
- ];
201
-
202
74
$ reflectionClass = new \ReflectionClass ($ this ->getSourceClassName ());
203
75
$ publicMethods = $ reflectionClass ->getMethods (\ReflectionMethod::IS_PUBLIC );
204
76
foreach ($ publicMethods as $ method ) {
@@ -288,6 +160,10 @@ protected function _generateCode()
288
160
} else {
289
161
$ this ->_classGenerator ->setExtendedClass ($ typeName );
290
162
}
163
+ $ this ->_classGenerator ->addTrait ('\Magento\Framework\Interception\Interceptor ' );
164
+ $ interfaces = $ this ->_classGenerator ->getImplementedInterfaces ();
165
+ $ interfaces [] = '\Magento\Framework\Interception\InterceptorInterface ' ;
166
+ $ this ->_classGenerator ->setImplementedInterfaces ($ interfaces );
291
167
return parent ::_generateCode ();
292
168
}
293
169
0 commit comments