|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2018 Justin Kuenzel (jukusoft.com) |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Project: JuKuCMS |
|
22
|
|
|
* License: Apache 2.0 license |
|
23
|
|
|
* User: Justin |
|
24
|
|
|
* Date: 09.04.2018 |
|
25
|
|
|
* Time: 10:50 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
class EventInstaller extends PluginInstaller_Plugin { |
|
29
|
|
|
|
|
30
|
|
|
public function install(Plugin $plugin, array $install_json): bool { |
|
31
|
|
|
//add events if absent |
|
32
|
|
|
return $this->addEvents($plugin, $install_json); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function uninstall(Plugin $plugin, array $install_json): bool { |
|
36
|
|
|
//check, if events are specified |
|
37
|
|
|
if (isset($install_json['events']) && is_array($install_json['events'])) { |
|
38
|
|
|
//remove all events from this plugin |
|
39
|
|
|
Events::removePluginEvents($plugin->getName()); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function upgrade(Plugin $plugin, array $install_json): bool { |
|
44
|
|
|
//add events if absent |
|
45
|
|
|
return $this->addEvents($plugin, $install_json); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function addEvents (Plugin $plugin, array $install_json) : bool { |
|
49
|
|
|
//check, if events are specified |
|
50
|
|
|
if (isset($install_json['events']) && is_array($install_json['events'])) { |
|
51
|
|
|
//create events |
|
52
|
|
|
foreach ($install_json['events'] as $event) { |
|
53
|
|
|
if (!is_array($event)) { |
|
54
|
|
|
throw new IllegalStateException("Invalide install.json, key 'events' has to contains arrays!"); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$event_name = $event['event']; |
|
58
|
|
|
|
|
59
|
|
|
//get type |
|
60
|
|
|
$type = strtolower($event['type']); |
|
61
|
|
|
|
|
62
|
|
|
switch ($type) { |
|
63
|
|
|
case "file": |
|
64
|
|
|
throw new Exception("UnuspportedOperationException: event type 'file' is not supported yet."); |
|
65
|
|
|
break; |
|
66
|
|
|
case "function": |
|
67
|
|
|
throw new Exception("UnuspportedOperationException: event type 'function' is not supported yet."); |
|
68
|
|
|
break; |
|
69
|
|
|
case "class_static_method": |
|
70
|
|
|
Events::addEventClass($event_name, $event['class'], $event['method'], $plugin->getName()); |
|
71
|
|
|
break; |
|
72
|
|
|
default: |
|
73
|
|
|
throw new IllegalArgumentException("Unknown event type: " . $type . " (event: " . $event_name . ") in install.json of plugin '" . $plugin->getName() . "'!"); |
|
74
|
|
|
break; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return true; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
?> |
|
|
|
|
|
|
85
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: