1
1
<?php
2
-
2
+ /**
3
+ * Copyright © 2015 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
3
6
namespace Magento \Framework \Interception ;
4
7
8
+ /**
9
+ * Interceptor trait that contains the common logic for all interceptor classes.
10
+ *
11
+ * A trait is used because our interceptor classes need to extend the class that they are intercepting.
12
+ */
5
13
trait Interceptor
6
14
{
7
15
/**
@@ -32,7 +40,11 @@ trait Interceptor
32
40
*/
33
41
protected $ subjectType = null ;
34
42
35
-
43
+ /**
44
+ * Initialize the Interceptor
45
+ *
46
+ * @return void
47
+ */
36
48
public function ___init ()
37
49
{
38
50
$ this ->pluginLocator = \Magento \Framework \App \ObjectManager::getInstance ();
@@ -44,28 +56,53 @@ public function ___init()
44
56
}
45
57
}
46
58
59
+ /**
60
+ * Calls parent class method
61
+ *
62
+ * @param string $method
63
+ * @param array $arguments
64
+ * @return mixed
65
+ */
47
66
public function ___callParent ($ method , array $ arguments )
48
67
{
49
- return call_user_func_array (array ( 'parent ' , $ method) , $ arguments );
68
+ return call_user_func_array ([ 'parent ' , $ method] , $ arguments );
50
69
}
51
70
71
+ /**
72
+ * Calls parent class sleep if defined, otherwise provides own implementation
73
+ *
74
+ * @return array
75
+ */
52
76
public function __sleep ()
53
77
{
54
78
if (method_exists (get_parent_class ($ this ), '__sleep ' )) {
55
- return array_diff (parent ::__sleep (), array ( 'pluginLocator ' , 'pluginList ' , 'chain ' , 'subjectType ' ) );
79
+ return array_diff (parent ::__sleep (), [ 'pluginLocator ' , 'pluginList ' , 'chain ' , 'subjectType ' ] );
56
80
} else {
57
81
return array_keys (get_class_vars (get_parent_class ($ this )));
58
82
}
59
83
}
60
84
85
+ /**
86
+ * Causes Interceptor to be initialized
87
+ *
88
+ * @return void
89
+ */
61
90
public function __wakeup ()
62
91
{
63
- if (method_exists (get_parent_class (\ $ this ), '__wakeup ' )) {
92
+ if (method_exists (get_parent_class ($ this ), '__wakeup ' )) {
64
93
parent ::__wakeup ();
65
94
}
66
95
$ this ->___init ();
67
96
}
68
97
98
+ /**
99
+ * Calls plugins for a given method.
100
+ *
101
+ * @param string $method
102
+ * @param array $arguments
103
+ * @param array $pluginInfo
104
+ * @return mixed|null
105
+ */
69
106
protected function ___callPlugins ($ method , array $ arguments , array $ pluginInfo )
70
107
{
71
108
$ capMethod = ucfirst ($ method );
@@ -74,7 +111,8 @@ protected function ___callPlugins($method, array $arguments, array $pluginInfo)
74
111
// Call 'before' listeners
75
112
foreach ($ pluginInfo [\Magento \Framework \Interception \DefinitionInterface::LISTENER_BEFORE ] as $ code ) {
76
113
$ beforeResult = call_user_func_array (
77
- array ($ this ->pluginList ->getPlugin ($ this ->subjectType , $ code ), 'before ' . $ capMethod ), array_merge (array ($ this ), $ arguments )
114
+ [$ this ->pluginList ->getPlugin ($ this ->subjectType , $ code ), 'before ' . $ capMethod ],
115
+ array_merge ([$ this ], $ arguments )
78
116
);
79
117
if ($ beforeResult ) {
80
118
$ arguments = $ beforeResult ;
@@ -91,12 +129,12 @@ protected function ___callPlugins($method, array $arguments, array $pluginInfo)
91
129
return $ chain ->invokeNext ($ type , $ method , $ subject , func_get_args (), $ code );
92
130
};
93
131
$ result = call_user_func_array (
94
- array ( $ this ->pluginList ->getPlugin ($ this ->subjectType , $ code ), 'around ' . $ capMethod) ,
95
- array_merge (array ( $ this , $ next) , $ arguments )
132
+ [ $ this ->pluginList ->getPlugin ($ this ->subjectType , $ code ), 'around ' . $ capMethod] ,
133
+ array_merge ([ $ this , $ next] , $ arguments )
96
134
);
97
135
} else {
98
136
// Call original method
99
- $ result = call_user_func_array (array ( 'parent ' , $ method) , $ arguments );
137
+ $ result = call_user_func_array ([ 'parent ' , $ method] , $ arguments );
100
138
}
101
139
if (isset ($ pluginInfo [\Magento \Framework \Interception \DefinitionInterface::LISTENER_AFTER ])) {
102
140
// Call 'after' listeners
0 commit comments