1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Quantum\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Quantum\Environment\Exceptions\EnvException; |
6
|
|
|
use Symfony\Component\Console\Exception\ExceptionInterface; |
7
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
8
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
9
|
|
|
use Quantum\Environment\Environment; |
10
|
|
|
use Quantum\Console\QtCommand; |
11
|
|
|
|
12
|
|
|
class InstallToolkitCommand extends QtCommand |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Command name |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $name = 'install:toolkit'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Command description |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Installs toolkit'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Command arguments |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $args = [ |
31
|
|
|
['username', 'required', 'The username for basic auth'], |
32
|
|
|
['password', 'required', 'The password for basic auth'], |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Command help text |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $help = 'The command will install Toolkit and its assets into your project'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Command name to generate modules |
43
|
|
|
*/ |
44
|
|
|
const COMMAND_CREATE_MODULE = 'module:generate'; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Executes the command |
48
|
|
|
* @throws ExceptionInterface |
49
|
|
|
* @throws EnvException |
50
|
|
|
*/ |
51
|
|
|
public function exec() |
52
|
|
|
{ |
53
|
|
|
$name = $this->getArgument('username'); |
54
|
|
|
|
55
|
|
|
$password = $this->getArgument('password'); |
56
|
|
|
|
57
|
|
|
$env = Environment::getInstance(); |
58
|
|
|
|
59
|
|
|
$env->setMutable(true); |
60
|
|
|
|
61
|
|
|
$env->updateRow('BASIC_AUTH_NAME', $name); |
62
|
|
|
|
63
|
|
|
$env->updateRow('BASIC_AUTH_PWD', $password); |
64
|
|
|
|
65
|
|
|
$this->runExternalCommand(self::COMMAND_CREATE_MODULE, [ |
66
|
|
|
"module" => "Toolkit", |
67
|
|
|
"--yes" => true, |
68
|
|
|
"--template" => "Toolkit", |
69
|
|
|
"--with-assets" => true |
70
|
|
|
]); |
71
|
|
|
|
72
|
|
|
$this->info('Toolkit installed successfully'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Runs an external command |
77
|
|
|
* @param string $commandName |
78
|
|
|
* @param array $arguments |
79
|
|
|
* @throws ExceptionInterface |
80
|
|
|
*/ |
81
|
|
|
protected function runExternalCommand(string $commandName, array $arguments) |
82
|
|
|
{ |
83
|
|
|
$command = $this->getApplication()->find($commandName); |
84
|
|
|
$command->run(new ArrayInput($arguments), new NullOutput); |
85
|
|
|
} |
86
|
|
|
} |