1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Magallanes package. |
||
5 | * |
||
6 | * (c) Andrés Montañez <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Mage\Command; |
||
13 | |||
14 | use Mage\MageApplication; |
||
15 | use Mage\Utils; |
||
16 | use Mage\Runtime\Runtime; |
||
17 | use Psr\Log\LogLevel; |
||
18 | use Symfony\Component\Console\Command\Command; |
||
19 | |||
20 | /** |
||
21 | * Abstract base class for Magallanes Commands |
||
22 | * |
||
23 | * @author Andrés Montañez <[email protected]> |
||
24 | */ |
||
25 | abstract class AbstractCommand extends Command |
||
26 | { |
||
27 | protected int $statusCode = 0; |
||
28 | protected Runtime $runtime; |
||
29 | |||
30 | /** |
||
31 | * Set the Runtime configuration |
||
32 | */ |
||
33 | 63 | public function setRuntime(Runtime $runtime): self |
|
34 | { |
||
35 | 63 | $this->runtime = $runtime; |
|
36 | 63 | return $this; |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * Logs a message |
||
41 | */ |
||
42 | 46 | public function log(string $message, string $level = LogLevel::DEBUG): void |
|
43 | { |
||
44 | 46 | $this->runtime->log($message, $level); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Get the Human friendly Stage name |
||
49 | */ |
||
50 | 40 | protected function getStageName(): string |
|
51 | { |
||
52 | 40 | $utils = new Utils(); |
|
53 | 40 | return $utils->getStageName($this->runtime->getStage()); |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Requires the configuration to be loaded |
||
58 | */ |
||
59 | 57 | protected function requireConfig(): void |
|
60 | { |
||
61 | 57 | $app = $this->getApplication(); |
|
62 | 57 | if ($app instanceof MageApplication) { |
|
63 | 57 | $app->configure(); |
|
64 | } |
||
65 | } |
||
66 | } |
||
67 |