1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of DivineNii opensource projects. |
7
|
|
|
* |
8
|
|
|
* PHP version 7.4 and above required |
9
|
|
|
* |
10
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
11
|
|
|
* @copyright 2019 DivineNii (https://divinenii.com/) |
12
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
15
|
|
|
* file that was distributed with this source code. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace Rade; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* A module extension feature (A.K.A plugin). |
22
|
|
|
* |
23
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class Module implements \JsonSerializable, \IteratorAggregate |
26
|
|
|
{ |
27
|
|
|
private array $moduleConfig; |
28
|
|
|
private string $directory; |
29
|
|
|
|
30
|
|
|
public function __construct(string $directory, array $moduleConfig) |
31
|
|
|
{ |
32
|
|
|
$this->directory = $directory; |
33
|
|
|
$this->moduleConfig = $moduleConfig; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Checks if module is enabled or not. |
38
|
|
|
*/ |
39
|
|
|
public function isEnabled(): bool |
40
|
|
|
{ |
41
|
|
|
return $this->moduleConfig['enabled'] ?? false; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* If the module has an author. |
46
|
|
|
*/ |
47
|
|
|
public function getAuthor(): ?string |
48
|
|
|
{ |
49
|
|
|
return $this->moduleConfig['author'] ?? null; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@see Rade\Traits\HelperTrait::loadExtensions()}. |
54
|
|
|
*/ |
55
|
|
|
public function getExtensions(): array |
56
|
|
|
{ |
57
|
|
|
return $this->moduleConfig['extensions'] ?? []; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Gets the module's directory. |
62
|
|
|
*/ |
63
|
|
|
public function getDirectory(): string |
64
|
|
|
{ |
65
|
|
|
return $this->directory; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
* |
71
|
|
|
* @return mixed |
72
|
|
|
*/ |
73
|
|
|
public function jsonSerialize() |
74
|
|
|
{ |
75
|
|
|
return $this->moduleConfig; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function getIterator(): \Traversable |
82
|
|
|
{ |
83
|
|
|
return new \ArrayIterator($this->moduleConfig); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|