1
|
|
|
<?php namespace Comodojo\Installer\Actions; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Exception\InstallerException; |
4
|
|
|
use \Exception; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Comodojo Installer |
8
|
|
|
* |
9
|
|
|
* @package Comodojo Framework |
10
|
|
|
* @author Marco Giovinazzi <[email protected]> |
11
|
|
|
* @license GPL-3.0+ |
12
|
|
|
* |
13
|
|
|
* LICENSE: |
14
|
|
|
* |
15
|
|
|
* This program is free software: you can redistribute it and/or modify |
16
|
|
|
* it under the terms of the GNU Affero General Public License as |
17
|
|
|
* published by the Free Software Foundation, either version 3 of the |
18
|
|
|
* License, or (at your option) any later version. |
19
|
|
|
* |
20
|
|
|
* This program is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU Affero General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* You should have received a copy of the GNU Affero General Public License |
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
View Code Duplication |
class ExtenderPlugin extends AbstractAction { |
30
|
|
|
|
31
|
|
|
public function install($package_name, $package_extra) { |
32
|
|
|
|
33
|
|
|
$io = $this->getIO(); |
34
|
|
|
|
35
|
|
|
$io->write("<info>>>> Installing (extender) plugins from package ".$package_name."</info>"); |
36
|
|
|
|
37
|
|
|
$this->processPlugin($io, 'install', $package_name, $package_extra); |
38
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function update($package_name, $initial_extra, $target_extra) { |
42
|
|
|
|
43
|
|
|
$io = $this->getIO(); |
44
|
|
|
|
45
|
|
|
$io->write("<info>>>> Updating (extender) plugins from package ".$package_name."</info>"); |
46
|
|
|
|
47
|
|
|
$this->processPlugin($io, 'uninstall', $package_name, $initial_extra); |
48
|
|
|
|
49
|
|
|
$this->processPlugin($io, 'install', $package_name, $target_extra); |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function uninstall($package_name, $package_extra) { |
54
|
|
|
|
55
|
|
|
$io = $this->getIO(); |
56
|
|
|
|
57
|
|
|
$io->write("<info>>>> Removing (extender) plugins from package ".$package_name."</info>"); |
58
|
|
|
|
59
|
|
|
$this->processPlugin($io, 'uninstall', $package_name, $package_extra); |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private static function processPlugin($io, $action, $package_name, $package_extra) { |
64
|
|
|
|
65
|
|
|
foreach ($package_extra as $plugin => $configuration) { |
66
|
|
|
|
67
|
|
|
try { |
68
|
|
|
|
69
|
|
|
if ( !self::validatePlugin($configuration) ) throw new InstallerException('Skipping invalid plugin in '.$package_name); |
70
|
|
|
|
71
|
|
|
$plugin_name = $package_name.'-extender-'.$plugin; |
72
|
|
|
|
73
|
|
|
$event = $configuration["event"]; |
74
|
|
|
|
75
|
|
|
$class = $configuration["class"]; |
76
|
|
|
|
77
|
|
|
$method = empty($configuration["method"]) ? null : $configuration["method"]; |
78
|
|
|
|
79
|
|
|
switch ($action) { |
80
|
|
|
|
81
|
|
|
case 'install': |
82
|
|
|
|
83
|
|
|
$this->getPackageInstaller()->plugins()->add($package_name, 'extender', $plugin_name, $event, $class, $method); |
|
|
|
|
84
|
|
|
|
85
|
|
|
$io->write(" <info>+</info> enabled plugin ".$plugin_name." on event ".$event); |
86
|
|
|
|
87
|
|
|
break; |
88
|
|
|
|
89
|
|
|
case 'uninstall': |
90
|
|
|
|
91
|
|
|
$id = $this->getPackageInstaller()->plugins()->byName($plugin_name)->getId(); |
92
|
|
|
|
93
|
|
|
$this->getPackageInstaller()->plugins()->delete($id); |
94
|
|
|
|
95
|
|
|
$io->write(" <comment>-</comment> disabled plugin ".$plugin_name." on event ".$event); |
96
|
|
|
|
97
|
|
|
break; |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} catch (Exception $e) { |
102
|
|
|
|
103
|
|
|
$io->write('<error>Error processing plugin: '.$e->getMessage().'</error>'); |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
private static function validatePlugin($plugin) { |
112
|
|
|
|
113
|
|
|
return !( empty($plugin["class"]) || empty($plugin["event"]) ); |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.