Skip to content

Commit 6860277

Browse files
committed
feat: add new CLI command for make custom UserModel
1 parent 5e6d517 commit 6860277

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CodeIgniter\Shield\Commands\Generators;
6+
7+
use CodeIgniter\CLI\BaseCommand;
8+
use CodeIgniter\CLI\GeneratorTrait;
9+
10+
/**
11+
* Generates a skeleton command file.
12+
*/
13+
class UserModelGenerator extends BaseCommand
14+
{
15+
use GeneratorTrait;
16+
17+
/**
18+
* The Command's Group
19+
*
20+
* @var string
21+
*/
22+
protected $group = 'Shield';
23+
24+
/**
25+
* The Command's Name
26+
*
27+
* @var string
28+
*/
29+
protected $name = 'shield:make';
30+
31+
/**
32+
* The Command's Description
33+
*
34+
* @var string
35+
*/
36+
protected $description = 'Generates a new UserModel file.';
37+
38+
/**
39+
* The Command's Usage
40+
*
41+
* @var string
42+
*/
43+
protected $usage = 'shield:make <name> [options]';
44+
45+
/**
46+
* The Command's Arguments
47+
*
48+
* @var array
49+
*/
50+
protected $arguments = [
51+
'name' => 'The model class name.',
52+
];
53+
54+
/**
55+
* The Command's Options
56+
*
57+
* @var array
58+
*/
59+
protected $options = [
60+
'--namespace' => 'Set root namespace. Default: "APP_NAMESPACE".',
61+
'--suffix' => 'Append the component title to the class name (e.g. User => UserModel).',
62+
'--force' => 'Force overwrite existing file.',
63+
];
64+
65+
/**
66+
* Actually execute a command.
67+
*/
68+
public function run(array $params): void
69+
{
70+
$this->component = 'Model';
71+
$this->directory = 'Models';
72+
$this->template = 'usermodel.tpl.php';
73+
74+
$this->classNameLang = 'CLI.generator.className.model';
75+
$this->execute($params);
76+
}
77+
78+
/**
79+
* Prepare options and do the necessary replacements.
80+
*/
81+
protected function prepare(string $class): string
82+
{
83+
return $this->parseTemplate($class);
84+
}
85+
}

0 commit comments

Comments
 (0)