-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateModule.php
More file actions
49 lines (38 loc) · 1.23 KB
/
Copy pathCreateModule.php
File metadata and controls
49 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Console\Commands;
use Shift\Console\CommandInterface;
use Shift\Console\Generator\GeneratesFiles;
use Shift\Console\Generator\NameFormatter;
class CreateModule implements CommandInterface
{
use GeneratesFiles;
public function execute(mixed ...$args): void
{
$rawName = $args[0] ?? null;
if (!is_string($rawName) || $rawName === '') {
$this->cli->error($this->getHelp());
return;
}
$module = NameFormatter::moduleName($rawName);
$slug = NameFormatter::slug($rawName);
$path = $this->modulePath($module);
foreach (['Commands', 'Controllers', 'Services'] as $directory) {
$this->files->ensureDirectory($path . '/' . $directory);
}
$this->writeAndReport($path . '/Module.php', $this->renderStub('module', [
'module' => $module,
'slug' => $slug,
]));
$this->writeAndReport($path . '/config.php', $this->renderStub('config', [
'slug' => $slug,
]));
}
public function getHelp(): string
{
return 'Usage: ./shift create:module {name}';
}
public function getDescription(): string
{
return 'Create a new Shift module.';
}
}