|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Plugins\PluginExecutor |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Plugins; |
|
22
|
|
|
|
|
23
|
|
|
use League\Event\EmitterInterface; |
|
24
|
|
|
use TechDivision\Import\Utils\EventNames; |
|
25
|
|
|
use TechDivision\Import\Configuration\PluginConfigurationInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The plug-in executor instance. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
33
|
|
|
* @link https://github.com/techdivision/import |
|
34
|
|
|
* @link http://www.techdivision.com |
|
35
|
|
|
*/ |
|
36
|
|
|
class PluginExecutor implements PluginExecutorInterface |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The plug-in factory instance. |
|
41
|
|
|
* |
|
42
|
|
|
* @var \TechDivision\Import\Plugins\PluginFactoryInterface |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $pluginFactory; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The event emitter instance. |
|
48
|
|
|
* |
|
49
|
|
|
* @var \League\Event\EmitterInterface |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $emitter; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Initializes the plug-in executor with the application instance. |
|
55
|
|
|
* |
|
56
|
|
|
* @param \TechDivision\Import\Plugins\PluginFactoryInterface $pluginFactory The plug-in factory instance |
|
57
|
|
|
* @param \League\Event\EmitterInterface $emitter The event emitter instance |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __construct( |
|
60
|
|
|
PluginFactoryInterface $pluginFactory, |
|
61
|
|
|
EmitterInterface $emitter |
|
62
|
|
|
) { |
|
63
|
|
|
|
|
64
|
|
|
// initialize the subject factory and the event emitter |
|
65
|
|
|
$this->pluginFactory = $pluginFactory; |
|
66
|
|
|
$this->emitter = $emitter; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Return's the event emitter instance. |
|
71
|
|
|
* |
|
72
|
|
|
* @return \League\Event\EmitterInterface The event emitter instance |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function getEmitter() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->emitter; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Return's the plug-in factory instance. |
|
81
|
|
|
* |
|
82
|
|
|
* @return \TechDivision\Import\Plugins\PluginFactoryInterface The plug-in factory instance |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function getPluginFactory() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->pluginFactory; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Executes the plugin with the passed configuration. |
|
91
|
|
|
* |
|
92
|
|
|
* @param \TechDivision\Import\Configuration\PluginConfigurationInterface $plugin The message with the plugin information |
|
93
|
|
|
* |
|
94
|
|
|
* @return void |
|
95
|
|
|
*/ |
|
96
|
|
|
public function execute(PluginConfigurationInterface $plugin) |
|
97
|
|
|
{ |
|
98
|
|
|
|
|
99
|
|
|
// initialize the plugin |
|
100
|
|
|
$pluginInstance = $this->getPluginFactory()->createPlugin($plugin); |
|
101
|
|
|
|
|
102
|
|
|
try { |
|
103
|
|
|
// load the subject + plug-in ID to prepare the event names |
|
104
|
|
|
$pluginName = $plugin->getName(); |
|
105
|
|
|
|
|
106
|
|
|
// invoke the event that has to be fired before the plugin will be executed |
|
107
|
|
|
$this->getEmitter()->emit(EventNames::PLUGIN_PROCESS_START, $pluginInstance); |
|
|
|
|
|
|
108
|
|
|
$this->getEmitter()->emit(sprintf('%s.%s', $pluginName, EventNames::PLUGIN_PROCESS_START), $pluginInstance); |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
// initialize the counter |
|
111
|
|
|
$counter = 1; |
|
112
|
|
|
|
|
113
|
|
|
// process the plugin |
|
114
|
|
|
$pluginInstance->process(); |
|
115
|
|
|
|
|
116
|
|
|
// query whether or not, we've to export artefacts |
|
117
|
|
|
if ($pluginInstance instanceof ExportablePluginInterface) { |
|
118
|
|
|
try { |
|
119
|
|
|
// invoke the event that has to be fired before the subject's export method will be invoked |
|
120
|
|
|
$this->getEmitter()->emit(EventNames::PLUGIN_EXPORT_START, $pluginInstance); |
|
|
|
|
|
|
121
|
|
|
$this->getEmitter()->emit(sprintf('%s.%s', $pluginName, EventNames::PLUGIN_EXPORT_START), $pluginInstance); |
|
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
// export the plugin's artefacts if available |
|
124
|
|
|
$pluginInstance->export(date('Ymd-His'), str_pad($counter++, 2, 0, STR_PAD_LEFT)); |
|
125
|
|
|
|
|
126
|
|
|
// invoke the event that has to be fired after the subject's export method has been invoked |
|
127
|
|
|
$this->getEmitter()->emit(EventNames::PLUGIN_EXPORT_SUCCESS, $pluginInstance); |
|
|
|
|
|
|
128
|
|
|
$this->getEmitter()->emit(sprintf('%s.%s', $pluginName, EventNames::PLUGIN_EXPORT_SUCCESS), $pluginInstance); |
|
|
|
|
|
|
129
|
|
|
} catch (\Exception $e) { |
|
130
|
|
|
// invoke the event that has to be fired when the subject's export method throws an exception |
|
131
|
|
|
$this->getEmitter()->emit(EventNames::PLUGIN_EXPORT_FAILURE, $pluginInstance); |
|
|
|
|
|
|
132
|
|
|
$this->getEmitter()->emit(sprintf('%s.%s', $pluginName, EventNames::PLUGIN_EXPORT_FAILURE), $pluginInstance); |
|
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
// re-throw the exception |
|
135
|
|
|
throw $e; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
// invoke the event that has to be fired after the plugin has been executed |
|
140
|
|
|
$this->getEmitter()->emit(EventNames::PLUGIN_PROCESS_SUCCESS, $pluginInstance); |
|
|
|
|
|
|
141
|
|
|
$this->getEmitter()->emit(sprintf('%s.%s', $pluginName, EventNames::PLUGIN_PROCESS_SUCCESS), $pluginInstance); |
|
|
|
|
|
|
142
|
|
|
} catch (\Exception $e) { |
|
143
|
|
|
// invoke the event that has to be fired when the plugin throws an exception |
|
144
|
|
|
$this->getEmitter()->emit(EventNames::PLUGIN_PROCESS_FAILURE, $pluginInstance); |
|
|
|
|
|
|
145
|
|
|
$this->getEmitter()->emit(sprintf('%s.%s', $pluginName, EventNames::PLUGIN_PROCESS_FAILURE), $pluginInstance); |
|
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
// re-throw the exception |
|
148
|
|
|
throw $e; |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.