|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Blitz PHP framework. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2022 Dimitri Sitchet Tomkeu <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view |
|
9
|
|
|
* the LICENSE file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace BlitzPHP\Cli\Commands\Generators; |
|
13
|
|
|
|
|
14
|
|
|
use BlitzPHP\Cli\Console\Command as ConsoleCommand; |
|
15
|
|
|
use BlitzPHP\Cli\Traits\GeneratorTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Generates a skeleton command file. |
|
19
|
|
|
*/ |
|
20
|
|
|
class Command extends ConsoleCommand |
|
21
|
|
|
{ |
|
22
|
|
|
use GeneratorTrait; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string Groupe |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $group = 'Generateurs'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var string Nom |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $name = 'make:command'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string Description |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $description = 'Génère une nouvelle commande klinge.'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $service = 'Service de génération de code'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var array Arguments */ |
|
46
|
|
|
protected $arguments = [ |
|
47
|
|
|
'name' => 'Le nom de la classe de commande.', |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var array Options |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $options = [ |
|
54
|
|
|
'--command' => 'Le nom de la commande. Par défaut: "command:name"', |
|
55
|
|
|
'--type' => ['Le type de commande. Options [basic, generator]. Par défault: "basic".', 'basic'], |
|
56
|
|
|
'--group' => 'Le groupe de la commande. Par défaut: [basic -> "{APP_NAME}", generator -> "{APP_NAME}:Generateurs"].', |
|
57
|
|
|
'--namespace' => ['Définissez l\'espace de noms racine. Par défaut: "APP_NAMESPACE".', APP_NAMESPACE], |
|
58
|
|
|
'--suffix' => 'Ajouter le titre du composant au nom de la classe (par exemple, User => UserCommand).', |
|
59
|
|
|
'--force' => "Forcer l'écrasement du fichier existant.", |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritDoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
public function execute(array $params) |
|
66
|
|
|
{ |
|
67
|
2 |
|
$this->component = 'Command'; |
|
68
|
2 |
|
$this->directory = 'Commands'; |
|
69
|
2 |
|
$this->template = 'command.tpl.php'; |
|
70
|
|
|
|
|
71
|
2 |
|
$this->classNameLang = 'CLI.generator.className.command'; |
|
72
|
2 |
|
$this->generateClass($params); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Préparez les options et effectuez les remplacements nécessaires. |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function prepare(string $class): string |
|
79
|
|
|
{ |
|
80
|
2 |
|
$command = $this->option('command'); |
|
81
|
2 |
|
$group = $this->option('group'); |
|
82
|
2 |
|
$type = $this->option('type'); |
|
83
|
|
|
|
|
84
|
2 |
|
$command = is_string($command) ? $command : 'command:name'; |
|
85
|
2 |
|
$type = is_string($type) ? $type : 'basic'; |
|
86
|
|
|
|
|
87
|
|
|
if (! in_array($type, ['basic', 'generator'], true)) { |
|
88
|
|
|
// @codeCoverageIgnoreStart |
|
89
|
|
|
$type = $this->choice(lang('CLI.generator.commandType'), ['basic', 'generator'], 'basic'); |
|
90
|
|
|
$this->eol(); |
|
91
|
|
|
// @codeCoverageIgnoreEnd |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if (! is_string($group)) { |
|
95
|
2 |
|
$group = $type === 'generator' ? config('app.name', 'App') . ':Generateurs' : config('app.name', 'App'); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $this->parseTemplate( |
|
99
|
|
|
$class, |
|
100
|
|
|
['{group}', '{command}'], |
|
101
|
|
|
[$group, $command], |
|
102
|
|
|
['type' => $type] |
|
103
|
2 |
|
); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|