|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Maestriam\Samurai\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Illuminate\Console\Command; |
|
7
|
|
|
use Maestriam\Samurai\Exceptions\InvalidDirectiveNameException; |
|
8
|
|
|
use Maestriam\Samurai\Support\Samurai; |
|
9
|
|
|
|
|
10
|
|
|
class BaseCommand extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* O nome e a assinatura do método |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $signature; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* A descrição do comando |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $description; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Mensagem de sucesso ao executar o comando |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected string $successMessage; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Mensagem de erro ao executar o comando |
|
37
|
|
|
* |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected string $errorMessage; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Cria a instância de um novo comando via console |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct() |
|
48
|
|
|
{ |
|
49
|
|
|
parent::__construct(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Retorna a mensagem de erro |
|
54
|
|
|
* |
|
55
|
|
|
* @param mixed ...$params |
|
56
|
|
|
* @return integer |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function success(...$params) : int |
|
59
|
|
|
{ |
|
60
|
|
|
$success = vsprintf($this->successMessage, $params); |
|
61
|
|
|
|
|
62
|
|
|
$this->info($success); |
|
63
|
|
|
|
|
64
|
|
|
return 0; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Retorna a mensagem de erro ao usuário junto com seu código. |
|
69
|
|
|
* |
|
70
|
|
|
* @param Exception $e |
|
71
|
|
|
* @return integer |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function failure(Exception $e) : int |
|
74
|
|
|
{ |
|
75
|
|
|
$error = sprintf($this->errorMessage, $e->getMessage()); |
|
76
|
|
|
|
|
77
|
|
|
$this->error($error); |
|
78
|
|
|
|
|
79
|
|
|
return $e->getCode(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Retorna o nome do tema para execução. |
|
84
|
|
|
* Em caso de nulo, tenta recuperar o tema atual da aplicação. |
|
85
|
|
|
* |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function getThemeArgument() : string |
|
89
|
|
|
{ |
|
90
|
|
|
$console = (string) $this->argument('theme'); |
|
91
|
|
|
|
|
92
|
|
|
if (strlen($console)) { |
|
93
|
|
|
return $console; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return Samurai::base()->current()->package(); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Retorna o nome do nome da diretiva |
|
101
|
|
|
* |
|
102
|
|
|
* @return string |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function getDirectiveArgument() : string |
|
105
|
|
|
{ |
|
106
|
|
|
$name = (string) $this->argument('name'); |
|
107
|
|
|
|
|
108
|
|
|
if ($name) { |
|
109
|
|
|
return $name; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
throw new InvalidDirectiveNameException($name); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Limpa o cache da aplicação Laravel |
|
117
|
|
|
* |
|
118
|
|
|
* @return void |
|
119
|
|
|
*/ |
|
120
|
|
|
protected function clean() |
|
121
|
|
|
{ |
|
122
|
|
|
return Samurai::base()->clean(); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|