Skip to content

Commit fd9321c

Browse files
committed
magento-hackathon/Imagine2017#11: Create new CLI command: Collect Dependency Injection Info for the Interfaces and Classes
- fixed issue with the empty constructor parameters list - fixed static test
1 parent 3b4f21f commit fd9321c

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
lines changed

app/code/Magento/Developer/Model/Di/Information.php

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public function getParameters($className)
8787
$this->getConstructorParameters($this->getVirtualTypeBase($className)) :
8888
$this->getConstructorParameters($this->getPreference($className));
8989

90+
if (!$originalParameters) {
91+
return $result;
92+
}
93+
9094
foreach ($originalParameters as $parameter) {
9195
$paramArray = [$parameter[0], $parameter[1], is_array($parameter[3]) ? "<empty array>" : $parameter[3]];
9296
if (isset($diConfiguration[$parameter[0]])) {

app/code/Magento/Developer/Model/Di/PluginList.php

+48-24
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,31 @@
1414
*/
1515
class PluginList extends Interception\PluginList\PluginList
1616
{
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+
1725
/**
1826
* @var array
1927
*/
2028
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
2442
];
2543

2644
/**
@@ -75,7 +93,6 @@ private function getPlugins($type)
7593
return $this->_inherited[$type];
7694
}
7795

78-
7996
/**
8097
* Return the list of plugins for the class
8198
*
@@ -92,28 +109,35 @@ public function getPluginsListByClass($className)
92109

93110
foreach ($this->_inherited[$className] as $pluginKey => $plugin) {
94111
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+
);
114121
}
115122
}
116123
return $this->pluginList;
117124
}
118-
}
119125

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

Comments
 (0)