Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
41 / 41
100.00% covered (success)
100.00%
24 / 24
CRAP
100.00% covered (success)
100.00%
1 / 1
Plugin
100.00% covered (success)
100.00%
41 / 41
100.00% covered (success)
100.00%
24 / 24
25
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
1
 boot
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 install
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 uninstall
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 update
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 enable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 disable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 loadRoutes
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPluginName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPath
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNamespace
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNamespacePath
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDescription
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getVersion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLicense
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getHomepage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAuthors
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getExtra
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getProviders
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMiddleware
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEventHandlers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getConfigOptions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRoutes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Plugins;
6
7use FastRoute\RouteCollector;
8
9class Plugin
10{
11    /** Package name, including vendor */
12    protected string $name;
13    /** Plugin name to be displayed (dir name) */
14    protected string $pluginName;
15    protected string $path;
16    protected string $namespace;
17    protected string $namespacePath;
18    protected string $version;
19    protected ?string $description;
20    protected string $license;
21    protected ?string $homepage;
22    protected array $authors;
23    protected array $extra;
24    protected array $providers;
25    protected array $middleware;
26    protected array $eventHandlers;
27    protected array $configOptions;
28    protected array $routes;
29
30    public function __construct(array $pluginInfo)
31    {
32        $this->name = $pluginInfo['name'];
33        $this->pluginName = $pluginInfo['plugin_name'];
34        $this->path = $pluginInfo['path'];
35        $this->namespace = $pluginInfo['namespace'];
36        $this->namespacePath = $pluginInfo['namespace_path'];
37        $this->version = $pluginInfo['version'] ?? '0.0.0';
38        $this->description = $pluginInfo['description'] ?? null;
39        $this->license = implode(', ', (array) ($pluginInfo['license'] ?? 'proprietary'));
40        $this->homepage = $pluginInfo['homepage'] ?? null;
41        $this->authors = $pluginInfo['authors'] ?? [];
42        $this->extra = $pluginInfo['extra'] ?? [];
43        $this->providers = $this->extra['providers'] ?? [];
44        $this->middleware = $this->extra['middleware'] ?? [];
45        $this->eventHandlers = $this->extra['event_handlers'] ?? [];
46        $this->configOptions = $this->extra['config_options'] ?? [];
47        $this->routes = $this->extra['routes'] ?? [];
48    }
49
50    /**
51     * On every application boot
52     */
53    public function boot(): void
54    {
55    }
56
57    /**
58     * After plugin installation
59     */
60    public function install(): void
61    {
62    }
63
64    /**
65     * Before plugin uninstall
66     */
67    public function uninstall(): void
68    {
69    }
70
71    /**
72     * After plugin update
73     */
74    public function update(string $from): void
75    {
76    }
77
78    /**
79     * After plugin enable
80     */
81    public function enable(): void
82    {
83    }
84
85    /**
86     * Before plugin disable
87     */
88    public function disable(): void
89    {
90    }
91
92    public function loadRoutes(RouteCollector $collector): void
93    {
94        foreach ($this->getRoutes() as $route => $data) {
95            $data = (array) $data;
96            $collector->addRoute($data[1] ?? 'GET', $route, $data[0]);
97        }
98    }
99
100    public function getName(): string
101    {
102        return $this->name;
103    }
104
105    public function getPluginName(): string
106    {
107        return $this->pluginName;
108    }
109
110    public function getPath(): string
111    {
112        return $this->path;
113    }
114
115    public function getNamespace(): string
116    {
117        return $this->namespace;
118    }
119
120    public function getNamespacePath(): string
121    {
122        return $this->namespacePath;
123    }
124
125    public function getDescription(): ?string
126    {
127        return $this->description;
128    }
129
130    public function getVersion(): string
131    {
132        return $this->version;
133    }
134
135    public function getLicense(): string
136    {
137        return $this->license;
138    }
139
140    public function getHomepage(): ?string
141    {
142        return $this->homepage;
143    }
144
145    public function getAuthors(): array
146    {
147        return $this->authors;
148    }
149
150    public function getExtra(): array
151    {
152        return $this->extra;
153    }
154
155    public function getProviders(): array
156    {
157        return $this->providers;
158    }
159
160    public function getMiddleware(): array
161    {
162        return $this->middleware;
163    }
164
165    public function getEventHandlers(): array
166    {
167        return $this->eventHandlers;
168    }
169
170    public function getConfigOptions(): array
171    {
172        return $this->configOptions;
173    }
174
175    public function getRoutes(): array
176    {
177        return $this->routes;
178    }
179}