|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the core-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 WEBEWEB |
|
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 WBW\Bundle\CoreBundle\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
15
|
|
|
use Symfony\Component\Console\Command\Command; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Style\StyleInterface; |
|
19
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
|
20
|
|
|
use WBW\Bundle\CoreBundle\Console\ConsoleHelper; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Abstract command. |
|
24
|
|
|
* |
|
25
|
|
|
* @author webeweb <https://github.com/webeweb> |
|
26
|
|
|
* @package WBW\Bundle\CoreBundle\Command |
|
27
|
|
|
* @abstract |
|
28
|
|
|
*/ |
|
29
|
|
|
abstract class AbstractCommand extends Command { |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Display the header. |
|
33
|
|
|
* |
|
34
|
|
|
* @param StyleInterface $io The I/O. |
|
35
|
|
|
* @param string $header The header. |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
30 |
|
protected function displayHeader(StyleInterface $io, string $header): void { |
|
39
|
30 |
|
$io->text($header); |
|
40
|
30 |
|
$io->newLine(); |
|
41
|
30 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Display the title. |
|
45
|
|
|
* |
|
46
|
|
|
* @param StyleInterface $io The I/O. |
|
47
|
|
|
* @param string $title The title. |
|
48
|
|
|
* @return void |
|
49
|
|
|
*/ |
|
50
|
30 |
|
protected function displayTitle(StyleInterface $io, string $title): void { |
|
51
|
30 |
|
$io->title($title); |
|
52
|
30 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get a checkbox. |
|
56
|
|
|
* |
|
57
|
|
|
* @param bool $checked Checked ? |
|
58
|
|
|
* @return string Returns the checkbox. |
|
59
|
|
|
*/ |
|
60
|
70 |
|
protected function getCheckbox(bool $checked): string { |
|
61
|
70 |
|
return ConsoleHelper::getCheckbox($checked); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the kernel. |
|
66
|
|
|
* |
|
67
|
|
|
* @return KernelInterface|null Returns the kernel in case of success, null otherwise. |
|
68
|
|
|
*/ |
|
69
|
60 |
|
protected function getKernel(): ?KernelInterface { |
|
70
|
60 |
|
|
|
71
|
10 |
|
if (false === ($this->getApplication() instanceof Application)) { |
|
72
|
|
|
return null; |
|
73
|
50 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $this->getApplication()->getKernel(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Create a style. |
|
80
|
|
|
* |
|
81
|
|
|
* @param InputInterface $input The input. |
|
82
|
|
|
* @param OutputInterface $output The output. |
|
83
|
30 |
|
* @return StyleInterface Returns the style. |
|
84
|
30 |
|
*/ |
|
85
|
|
|
protected function newStyle(InputInterface $input, OutputInterface $output): StyleInterface { |
|
86
|
|
|
return ConsoleHelper::newSymfonyStyle($input, $output); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|