1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of module-api |
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\ModuleApi\Infrastructure; |
13
|
|
|
|
14
|
|
|
use Dotenv\Dotenv; |
15
|
|
|
use Slick\Di\ContainerInterface; |
16
|
|
|
use Symfony\Component\Console\Application; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* AbstractModule |
20
|
|
|
* |
21
|
|
|
* @package Slick\ModuleApi\Infrastructure |
22
|
|
|
*/ |
23
|
|
|
abstract class AbstractModule implements FrontController\WebModuleInterface, Console\ConsoleModuleInterface |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritDoc |
28
|
|
|
*/ |
29
|
|
|
public function services(): array |
30
|
|
|
{ |
31
|
|
|
return []; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritDoc |
36
|
|
|
*/ |
37
|
|
|
public function settings(Dotenv $dotenv): array |
38
|
|
|
{ |
39
|
|
|
return []; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritDoc |
44
|
|
|
*/ |
45
|
|
|
public function name(): string |
46
|
|
|
{ |
47
|
|
|
$parts = explode('\\', get_called_class()); |
48
|
|
|
$last = array_pop($parts); |
49
|
|
|
return $this->camelToSnake(str_replace('Module', '', $last)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritDoc |
54
|
|
|
*/ |
55
|
|
|
public function description(): ?string |
56
|
|
|
{ |
57
|
|
|
return null; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function configureConsole(Application $cli, ContainerInterface $container): void |
61
|
|
|
{ |
62
|
|
|
// do nothing: no need to do anything |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function middlewareHandlers(): array |
66
|
|
|
{ |
67
|
|
|
return []; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @inheritDoc |
72
|
|
|
*/ |
73
|
|
|
public function onEnable(array $context = []): void |
74
|
|
|
{ |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @inheritDoc |
80
|
|
|
*/ |
81
|
|
|
public function onDisable(array $context = []): void |
82
|
|
|
{ |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Convert a camel case string to snake case. |
88
|
|
|
* |
89
|
|
|
* @param string $camelCase The camel case string to convert. |
90
|
|
|
* @param string $glue The glue character to use. Default is '_'. |
91
|
|
|
* @return string Returns the snake case string. |
92
|
|
|
*/ |
93
|
|
|
private function camelToSnake(string $camelCase, string $glue = '_'): string |
94
|
|
|
{ |
95
|
|
|
$result = ''; |
96
|
|
|
|
97
|
|
|
for ($i = 0; $i < strlen($camelCase); $i++) { |
98
|
|
|
$char = $camelCase[$i]; |
99
|
|
|
$result .= (ctype_upper($char)) ? $glue . strtolower($char) : $char; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return ltrim($result, $glue); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|