1 | <?php |
||
2 | /** |
||
3 | * Plugins Management |
||
4 | * @author Joe Huss <[email protected]> |
||
5 | * @copyright 2019 |
||
6 | * @package MyAdmin |
||
7 | * @category Plugins |
||
8 | */ |
||
9 | |||
10 | namespace MyAdmin\Plugins\Command; |
||
11 | |||
12 | use Symfony\Component\Console\Input\InputInterface; |
||
13 | use Symfony\Component\Console\Output\OutputInterface; |
||
14 | use Composer\Command\BaseCommand; |
||
15 | |||
16 | /** |
||
17 | * Class Command |
||
18 | * |
||
19 | * @package MyAdmin\Plugins\Command |
||
20 | */ |
||
21 | class Command extends BaseCommand |
||
22 | { |
||
23 | protected function configure() |
||
24 | { |
||
25 | $this |
||
26 | // the name of the command (the part after "bin/console") |
||
27 | ->setName('myadmin') |
||
28 | // the short description shown while running "php bin/console list" |
||
29 | ->setDescription('Creates a new user.') |
||
30 | // the full command description shown when running the command with the "--help" option |
||
31 | ->setHelp('This command allows you to create a user...'); |
||
32 | //->addArgument('username', InputArgument::REQUIRED, 'The username of the user.'); |
||
33 | } |
||
34 | |||
35 | /** (optional) |
||
36 | * This method is executed before the interact() and the execute() methods. |
||
37 | * Its main purpose is to initialize variables used in the rest of the command methods. |
||
38 | * |
||
39 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
40 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
41 | */ |
||
42 | protected function initialize(InputInterface $input, OutputInterface $output) |
||
43 | { |
||
44 | } |
||
45 | |||
46 | /** (optional) |
||
47 | * This method is executed after initialize() and before execute(). |
||
48 | * Its purpose is to check if some of the options/arguments are missing and interactively |
||
49 | * ask the user for those values. This is the last place where you can ask for missing |
||
50 | * options/arguments. After this command, missing options/arguments will result in an error. |
||
51 | * |
||
52 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
53 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
54 | */ |
||
55 | protected function interact(InputInterface $input, OutputInterface $output) |
||
56 | { |
||
57 | } |
||
58 | |||
59 | /** (required) |
||
60 | * This method is executed after interact() and initialize(). |
||
61 | * It contains the logic you want the command to execute. |
||
62 | * |
||
63 | * @param InputInterface $input |
||
64 | * @param OutputInterface $output |
||
65 | */ |
||
66 | protected function execute(InputInterface $input, OutputInterface $output) |
||
67 | { |
||
68 | $output->writeln([ // outputs multiple lines to the console (adding "\n" at the end of each line) |
||
69 | 'User Creator', |
||
70 | '============', |
||
71 | '' |
||
72 | ]); |
||
73 | /* |
||
74 | $output->writeln('Username: '.$input->getArgument('username')); // retrieve the argument value using getArgument() |
||
75 | */ |
||
76 | $output->write('You are about to '); // outputs a message without adding a "\n" at the end of the line |
||
77 | $output->write('create a user.'); |
||
78 | |||
79 | /** Coloring |
||
80 | * @link http://symfony.com/doc/current/console/coloring.html |
||
81 | */ |
||
82 | $output->writeln('<info>foo</info>'); // green text |
||
83 | $output->writeln('<comment>foo</comment>'); // yellow text |
||
84 | $output->writeln('<question>foo</question>'); // black text on a cyan background |
||
85 | $output->writeln('<error>foo</error>'); // white text on a red background |
||
86 | |||
87 | /** Formatting |
||
88 | * @link http://symfony.com/doc/current/components/console/helpers/formatterhelper.html |
||
89 | */ |
||
90 | $formatter = $this->getHelper('formatter'); |
||
91 | // Section - [SomeSection] Here is some message related to that section |
||
92 | $formattedLine = $formatter->formatSection('SomeSection', 'Here is some message related to that section'); |
||
93 | $output->writeln($formattedLine); |
||
94 | // Error Block |
||
95 | $errorMessages = ['Error!', 'Something went wrong']; |
||
96 | $formattedBlock = $formatter->formatBlock($errorMessages, 'error'); |
||
97 | $output->writeln($formattedBlock); |
||
98 | // Truncated Messages |
||
99 | $message = 'This is a very long message, which should be truncated'; |
||
100 | $truncatedMessage = $formatter->truncate($message, 7); // This is... |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
101 | $truncatedMessage = $formatter->truncate($message, 7, '!!'); // result: This is!! |
||
102 | $output->writeln($truncatedMessage); |
||
103 | |||
104 | /** Table |
||
105 | * @link http://symfony.com/doc/current/components/console/helpers/table.html |
||
106 | */ |
||
107 | |||
108 | /** Style |
||
109 | * @link http://symfony.com/doc/current/console/style.html |
||
110 | */ |
||
111 | |||
112 | /** Process Helper |
||
113 | * @link http://symfony.com/doc/current/components/console/helpers/processhelper.html |
||
114 | */ |
||
115 | /** Progress Bar |
||
116 | * @link http://symfony.com/doc/current/components/console/helpers/progressbar.html |
||
117 | */ |
||
118 | /** Question Helper |
||
119 | * @link http://symfony.com/doc/current/components/console/helpers/questionhelper.html |
||
120 | */ |
||
121 | } |
||
122 | } |
||
123 |