14
14
*/
15
15
class PluginList extends Interception \PluginList \PluginList
16
16
{
17
+ /**#@+
18
+ * Constants for the plugin types
19
+ */
20
+ const PLUGIN_TYPE_BEFORE = 'before ' ;
21
+ const PLUGIN_TYPE_AROUND = 'around ' ;
22
+ const PLUGIN_TYPE_AFTER = 'after ' ;
23
+ /**#@-*/
24
+
17
25
/**
18
26
* @var array
19
27
*/
20
28
private $ pluginList = [
21
- 'before ' => [],
22
- 'around ' => [],
23
- 'after ' => []
29
+ self ::PLUGIN_TYPE_BEFORE => [],
30
+ self ::PLUGIN_TYPE_AROUND => [],
31
+ self ::PLUGIN_TYPE_AFTER => []
32
+ ];
33
+
34
+ /**
35
+ * Mapping of plugin type codes to plugin types
36
+ * @var array
37
+ */
38
+ private $ pluginTypeMapping = [
39
+ DefinitionInterface::LISTENER_AROUND => self ::PLUGIN_TYPE_AROUND ,
40
+ DefinitionInterface::LISTENER_BEFORE => self ::PLUGIN_TYPE_BEFORE ,
41
+ DefinitionInterface::LISTENER_AFTER => self ::PLUGIN_TYPE_AFTER
24
42
];
25
43
26
44
/**
@@ -75,7 +93,6 @@ private function getPlugins($type)
75
93
return $ this ->_inherited [$ type ];
76
94
}
77
95
78
-
79
96
/**
80
97
* Return the list of plugins for the class
81
98
*
@@ -92,28 +109,35 @@ public function getPluginsListByClass($className)
92
109
93
110
foreach ($ this ->_inherited [$ className ] as $ pluginKey => $ plugin ) {
94
111
foreach ($ this ->_definitions ->getMethodList ($ plugin ['instance ' ]) as $ pluginMethod => $ methodTypes ) {
95
- if ($ methodTypes & DefinitionInterface::LISTENER_AROUND ) {
96
- if (!array_key_exists ($ plugin ['instance ' ], $ this ->pluginList ['around ' ])) {
97
- $ this ->pluginList ['around ' ][$ plugin ['instance ' ]] = [];
98
- }
99
- $ this ->pluginList ['around ' ][$ plugin ['instance ' ]][] = $ pluginMethod ;
100
- }
101
- if ($ methodTypes & DefinitionInterface::LISTENER_BEFORE ) {
102
- if (!array_key_exists ($ plugin ['instance ' ], $ this ->pluginList ['before ' ])) {
103
- $ this ->pluginList ['before ' ][$ plugin ['instance ' ]] = [];
104
- }
105
- $ this ->pluginList ['before ' ][$ plugin ['instance ' ]][] = $ pluginMethod ;
106
-
107
- }
108
- if ($ methodTypes & DefinitionInterface::LISTENER_AFTER ) {
109
- if (!array_key_exists ($ plugin ['instance ' ], $ this ->pluginList ['after ' ])) {
110
- $ this ->pluginList ['after ' ][$ plugin ['instance ' ]] = [];
111
- }
112
- $ this ->pluginList ['after ' ][$ plugin ['instance ' ]][] = $ pluginMethod ;
113
- }
112
+ $ this ->addPluginToList ($ plugin ['instance ' ], $ pluginMethod , $ methodTypes ,
113
+ DefinitionInterface::LISTENER_AROUND
114
+ );
115
+ $ this ->addPluginToList ($ plugin ['instance ' ], $ pluginMethod , $ methodTypes ,
116
+ DefinitionInterface::LISTENER_BEFORE
117
+ );
118
+ $ this ->addPluginToList ($ plugin ['instance ' ], $ pluginMethod , $ methodTypes ,
119
+ DefinitionInterface::LISTENER_AFTER
120
+ );
114
121
}
115
122
}
116
123
return $ this ->pluginList ;
117
124
}
118
- }
119
125
126
+ /**
127
+ * Add plugin to the appropriate type bucket
128
+ *
129
+ * @param string $pluginInstance
130
+ * @param string $pluginMethod
131
+ * @param int $methodTypes
132
+ * @param int $typeCode
133
+ */
134
+ private function addPluginToList ($ pluginInstance , $ pluginMethod , $ methodTypes , $ typeCode )
135
+ {
136
+ if ($ methodTypes & $ typeCode ) {
137
+ if (!array_key_exists ($ pluginInstance , $ this ->pluginList [$ this ->pluginTypeMapping [$ typeCode ]])) {
138
+ $ this ->pluginList [$ this ->pluginTypeMapping [$ typeCode ]][$ pluginInstance ] = [];
139
+ }
140
+ $ this ->pluginList [$ this ->pluginTypeMapping [$ typeCode ]][$ pluginInstance ][] = $ pluginMethod ;
141
+ }
142
+ }
143
+ }
0 commit comments