Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
24 / 24
CRAP
100.00% covered (success)
100.00%
1 / 1
Plugin
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
24 / 24
27
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%
4 / 4
100.00% covered (success)
100.00%
1 / 1
4
 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            foreach ((is_array($data[0]) ? $data : [$data]) as $routeData) {
97                $collector->addRoute($routeData[1] ?? 'GET', $route, $routeData[0]);
98            }
99        }
100    }
101
102    public function getName(): string
103    {
104        return $this->name;
105    }
106
107    public function getPluginName(): string
108    {
109        return $this->pluginName;
110    }
111
112    public function getPath(): string
113    {
114        return $this->path;
115    }
116
117    public function getNamespace(): string
118    {
119        return $this->namespace;
120    }
121
122    public function getNamespacePath(): string
123    {
124        return $this->namespacePath;
125    }
126
127    public function getDescription(): ?string
128    {
129        return $this->description;
130    }
131
132    public function getVersion(): string
133    {
134        return $this->version;
135    }
136
137    public function getLicense(): string
138    {
139        return $this->license;
140    }
141
142    public function getHomepage(): ?string
143    {
144        return $this->homepage;
145    }
146
147    public function getAuthors(): array
148    {
149        return $this->authors;
150    }
151
152    public function getExtra(): array
153    {
154        return $this->extra;
155    }
156
157    public function getProviders(): array
158    {
159        return $this->providers;
160    }
161
162    public function getMiddleware(): array
163    {
164        return $this->middleware;
165    }
166
167    public function getEventHandlers(): array
168    {
169        return $this->eventHandlers;
170    }
171
172    public function getConfigOptions(): array
173    {
174        return $this->configOptions;
175    }
176
177    public function getRoutes(): array
178    {
179        return $this->routes;
180    }
181}