|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of web-stack |
|
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\WebStack; |
|
13
|
|
|
|
|
14
|
|
|
use Composer\Autoload\ClassLoader; |
|
15
|
|
|
use Dotenv\Dotenv; |
|
16
|
|
|
use Psr\Container\ContainerExceptionInterface; |
|
17
|
|
|
use Psr\Container\NotFoundExceptionInterface; |
|
18
|
|
|
use Slick\Di\ContainerInterface; |
|
19
|
|
|
use Slick\Di\Definition\ObjectDefinition; |
|
20
|
|
|
use Slick\ModuleApi\Infrastructure\AbstractModule; |
|
21
|
|
|
use Slick\ModuleApi\Infrastructure\Console\ConsoleModuleInterface; |
|
22
|
|
|
use Slick\WebStack\UserInterface\Console\DescribeModuleCommand; |
|
23
|
|
|
use Slick\WebStack\UserInterface\Console\DisableModuleCommand; |
|
24
|
|
|
use Slick\WebStack\UserInterface\Console\EnableModuleCommand; |
|
25
|
|
|
use Slick\WebStack\UserInterface\Console\ListModuleCommand; |
|
26
|
|
|
use Symfony\Component\Console\Application; |
|
27
|
|
|
use function Slick\ModuleApi\importSettingsFile; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* ConsoleModule |
|
31
|
|
|
* |
|
32
|
|
|
* @package Slick\WebStack |
|
33
|
|
|
*/ |
|
34
|
|
|
final class ConsoleModule extends AbstractModule implements ConsoleModuleInterface |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
private const APP_ROOT_KEY = '@app.root'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @throws ContainerExceptionInterface |
|
41
|
|
|
* @throws NotFoundExceptionInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
public function configureConsole(Application $cli, ContainerInterface $container): void |
|
44
|
|
|
{ |
|
45
|
|
|
$cli->addCommands([ |
|
46
|
|
|
$container->get(EnableModuleCommand::class), |
|
47
|
|
|
$container->get(DisableModuleCommand::class), |
|
48
|
|
|
$container->get(DescribeModuleCommand::class), |
|
49
|
|
|
$container->get(ListModuleCommand::class), |
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @inheritDoc |
|
55
|
|
|
*/ |
|
56
|
|
|
public function services(): array |
|
57
|
|
|
{ |
|
58
|
|
|
$default = [ |
|
59
|
|
|
EnableModuleCommand::class => ObjectDefinition |
|
60
|
|
|
::create(EnableModuleCommand::class) |
|
61
|
|
|
->with(self::APP_ROOT_KEY) |
|
62
|
|
|
, |
|
63
|
|
|
DisableModuleCommand::class => ObjectDefinition |
|
64
|
|
|
::create(DisableModuleCommand::class) |
|
65
|
|
|
->with(self::APP_ROOT_KEY) |
|
66
|
|
|
, |
|
67
|
|
|
DescribeModuleCommand::class => ObjectDefinition |
|
68
|
|
|
::create(DescribeModuleCommand::class) |
|
69
|
|
|
->with(self::APP_ROOT_KEY) |
|
70
|
|
|
, |
|
71
|
|
|
ListModuleCommand::class => ObjectDefinition |
|
72
|
|
|
::create(ListModuleCommand::class) |
|
73
|
|
|
->with(self::APP_ROOT_KEY, '@'.ClassLoader::class) |
|
74
|
|
|
]; |
|
75
|
|
|
return importSettingsFile(dirname(__DIR__).'/config/logging.php', $default); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @inheritDoc |
|
80
|
|
|
*/ |
|
81
|
|
|
public function settings(Dotenv $dotenv): array |
|
82
|
|
|
{ |
|
83
|
|
|
$settingsFile = APP_ROOT .'/config/modules/console.php'; |
|
84
|
|
|
$defaultSettings = [ |
|
85
|
|
|
'console' => ['commands_dir' => '/src/UserInterface'], |
|
86
|
|
|
]; |
|
87
|
|
|
return importSettingsFile($settingsFile, $defaultSettings); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function name(): string |
|
91
|
|
|
{ |
|
92
|
|
|
return "console"; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function description(): string |
|
96
|
|
|
{ |
|
97
|
|
|
return "Provides streamlined command line tools for module management."; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|