5
5
*/
6
6
namespace Magento \Framework \Interception ;
7
7
8
+ use Magento \Framework \App \ObjectManager ;
9
+
8
10
/**
9
11
* Interceptor trait that contains the common logic for all interceptor classes.
10
12
*
11
13
* A trait is used because our interceptor classes need to extend the class that they are intercepting.
14
+ *
15
+ * Any class using this trait is required to implement \Magento\Framework\Interception\InterceptorInterface
16
+ *
17
+ * @see \Magento\Framework\Interception\InterceptorInterface
12
18
*/
13
19
trait Interceptor
14
20
{
@@ -47,7 +53,7 @@ trait Interceptor
47
53
*/
48
54
public function ___init ()
49
55
{
50
- $ this ->pluginLocator = \ Magento \ Framework \ App \ ObjectManager::getInstance ();
56
+ $ this ->pluginLocator = ObjectManager::getInstance ();
51
57
$ this ->pluginList = $ this ->pluginLocator ->get ('Magento\Framework\Interception\PluginListInterface ' );
52
58
$ this ->chain = $ this ->pluginLocator ->get ('Magento\Framework\Interception\ChainInterface ' );
53
59
$ this ->subjectType = get_parent_class ($ this );
@@ -107,9 +113,9 @@ protected function ___callPlugins($method, array $arguments, array $pluginInfo)
107
113
{
108
114
$ capMethod = ucfirst ($ method );
109
115
$ result = null ;
110
- if (isset ($ pluginInfo [\ Magento \ Framework \ Interception \ DefinitionInterface::LISTENER_BEFORE ])) {
116
+ if (isset ($ pluginInfo [DefinitionInterface::LISTENER_BEFORE ])) {
111
117
// Call 'before' listeners
112
- foreach ($ pluginInfo [\ Magento \ Framework \ Interception \ DefinitionInterface::LISTENER_BEFORE ] as $ code ) {
118
+ foreach ($ pluginInfo [DefinitionInterface::LISTENER_BEFORE ] as $ code ) {
113
119
$ beforeResult = call_user_func_array (
114
120
[$ this ->pluginList ->getPlugin ($ this ->subjectType , $ code ), 'before ' . $ capMethod ],
115
121
array_merge ([$ this ], $ arguments )
@@ -119,12 +125,13 @@ protected function ___callPlugins($method, array $arguments, array $pluginInfo)
119
125
}
120
126
}
121
127
}
122
- if (isset ($ pluginInfo [\ Magento \ Framework \ Interception \ DefinitionInterface::LISTENER_AROUND ])) {
128
+ if (isset ($ pluginInfo [DefinitionInterface::LISTENER_AROUND ])) {
123
129
// Call 'around' listener
124
130
$ chain = $ this ->chain ;
125
131
$ type = $ this ->subjectType ;
132
+ /** @var \Magento\Framework\Interception\InterceptorInterface $subject */
126
133
$ subject = $ this ;
127
- $ code = $ pluginInfo [\ Magento \ Framework \ Interception \ DefinitionInterface::LISTENER_AROUND ];
134
+ $ code = $ pluginInfo [DefinitionInterface::LISTENER_AROUND ];
128
135
$ next = function () use ($ chain , $ type , $ method , $ subject , $ code ) {
129
136
return $ chain ->invokeNext ($ type , $ method , $ subject , func_get_args (), $ code );
130
137
};
@@ -136,9 +143,9 @@ protected function ___callPlugins($method, array $arguments, array $pluginInfo)
136
143
// Call original method
137
144
$ result = call_user_func_array (['parent ' , $ method ], $ arguments );
138
145
}
139
- if (isset ($ pluginInfo [\ Magento \ Framework \ Interception \ DefinitionInterface::LISTENER_AFTER ])) {
146
+ if (isset ($ pluginInfo [DefinitionInterface::LISTENER_AFTER ])) {
140
147
// Call 'after' listeners
141
- foreach ($ pluginInfo [\ Magento \ Framework \ Interception \ DefinitionInterface::LISTENER_AFTER ] as $ code ) {
148
+ foreach ($ pluginInfo [DefinitionInterface::LISTENER_AFTER ] as $ code ) {
142
149
$ result = $ this ->pluginList ->getPlugin ($ this ->subjectType , $ code )
143
150
->{'after ' . $ capMethod }($ this , $ result );
144
151
}
0 commit comments