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\Helper\CommandHelper; |
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
|
|
|
* Displays the header. |
33
|
|
|
* |
34
|
|
|
* @param StyleInterface $io The I/O. |
35
|
|
|
* @param string $header The header. |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
protected function displayHeader(StyleInterface $io, $header) { |
39
|
|
|
$io->newLine(); |
40
|
|
|
$io->text($header); |
41
|
|
|
$io->newLine(); |
42
|
|
|
} |
43
|
|
|
/** |
44
|
|
|
* Displays the title. |
45
|
|
|
* |
46
|
|
|
* @param StyleInterface $io The I/O. |
47
|
|
|
* @param string $title The title. |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
protected function displayTitle(StyleInterface $io, $title) { |
51
|
|
|
$io->title($title); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get a checkbox. |
56
|
|
|
* |
57
|
|
|
* @param bool $checked Checked ? |
58
|
|
|
* @return string Returns the checkbox. |
59
|
|
|
*/ |
60
|
|
|
protected function getCheckbox($checked) { |
61
|
|
|
return CommandHelper::getCheckbox($checked); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the kernel. |
66
|
|
|
* |
67
|
|
|
* @return KernelInterface|null Returns the kernel in case of success, null othrewise. |
68
|
|
|
*/ |
69
|
|
|
protected function getKernel() { |
70
|
|
|
if (false === ($this->getApplication() instanceof Application)) { |
71
|
|
|
return null; |
72
|
|
|
} |
73
|
|
|
return $this->getApplication()->getKernel(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Create a style. |
78
|
|
|
* |
79
|
|
|
* @param InputInterface $input The input. |
80
|
|
|
* @param OutputInterface $output The output. |
81
|
|
|
* @return StyleInterface Returns the style. |
82
|
|
|
*/ |
83
|
|
|
protected function newStyle(InputInterface $input, OutputInterface $output) { |
84
|
|
|
return CommandHelper::newSymfonyStyle($input, $output); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|