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