1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of template |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Slick\Template; |
13
|
|
|
|
14
|
|
|
use Dotenv\Dotenv; |
15
|
|
|
use Slick\ModuleApi\Infrastructure\AbstractModule; |
16
|
|
|
use Slick\ModuleApi\Infrastructure\FrontController\WebModuleInterface; |
17
|
|
|
use function Slick\ModuleApi\importSettingsFile; |
18
|
|
|
use function Slick\ModuleApi\mergeArrays; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* TemplateModule |
22
|
|
|
* |
23
|
|
|
* @package Slick\Template |
24
|
|
|
*/ |
25
|
|
|
final class TemplateModule extends AbstractModule implements WebModuleInterface |
26
|
|
|
{ |
27
|
|
|
public function services(): array |
28
|
|
|
{ |
29
|
|
|
$servicesFile = dirname(__DIR__) . '/config/services.php'; |
30
|
|
|
return importSettingsFile($servicesFile); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the merged settings from default and user configurations. |
35
|
|
|
* |
36
|
|
|
* @param Dotenv $dotenv The Dotenv instance. |
37
|
|
|
* @return array<string, mixed> The merged settings array. |
38
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
39
|
|
|
*/ |
40
|
|
|
public function settings(Dotenv $dotenv): array |
41
|
|
|
{ |
42
|
|
|
$defaultSettings = importSettingsFile(dirname(__DIR__) . '/config/settings.php'); |
43
|
|
|
$userSettings = ['template' => importSettingsFile(APP_ROOT . '/config/modules/template.php')]; |
44
|
|
|
$userSettings['template']['paths'] = array_merge( |
45
|
|
|
$userSettings['template']['paths'], |
46
|
|
|
$defaultSettings['template']['paths'] |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
return mergeArrays($defaultSettings, $userSettings); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function description(): ?string |
53
|
|
|
{ |
54
|
|
|
return "Allows integration and usage of a template engine of your choice."; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Handles the "onEnable" event. |
59
|
|
|
* |
60
|
|
|
* @param array<string, mixed> $context An optional array of context data. |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
64
|
|
|
*/ |
65
|
|
|
public function onEnable(array $context = []): void |
66
|
|
|
{ |
67
|
|
|
$path = APP_ROOT . '/templates'; |
68
|
|
|
if (file_exists($path)) { |
69
|
|
|
return; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
mkdir($path, 0755, true); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|