|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Command\Installer; |
|
4
|
|
|
|
|
5
|
|
|
use App\Command\Helper\CommandsRunner; |
|
6
|
|
|
use App\Command\Helper\DirectoryChecker; |
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
class InstallAssetsCommand extends Command |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var DirectoryChecker |
|
15
|
|
|
*/ |
|
16
|
|
|
private $directoryChecker; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var CommandsRunner |
|
19
|
|
|
*/ |
|
20
|
|
|
private $commandsRunner; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $publicDir; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $environment; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct( |
|
31
|
|
|
DirectoryChecker $directoryChecker, |
|
32
|
|
|
CommandsRunner $commandsRunner, |
|
33
|
|
|
string $publicDir, |
|
34
|
|
|
string $environment |
|
35
|
|
|
) { |
|
36
|
|
|
$this->directoryChecker = $directoryChecker; |
|
37
|
|
|
$this->commandsRunner = $commandsRunner; |
|
38
|
|
|
$this->publicDir = $publicDir; |
|
39
|
|
|
$this->environment = $environment; |
|
40
|
|
|
|
|
41
|
|
|
parent::__construct(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function configure() |
|
48
|
|
|
{ |
|
49
|
|
|
$this |
|
50
|
|
|
->setName('app:install:assets') |
|
51
|
|
|
->setDescription('Installs all AppName assets.') |
|
52
|
|
|
->setHelp(<<<EOT |
|
53
|
|
|
The <info>%command.name%</info> command downloads and installs all AppName media assets. |
|
54
|
|
|
EOT |
|
55
|
|
|
) |
|
56
|
|
|
; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
* |
|
62
|
|
|
* @throws \Exception |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
65
|
|
|
{ |
|
66
|
|
|
$output->writeln(sprintf('Installing AppName assets for environment <info>%s</info>.', $this->environment)); |
|
67
|
|
|
|
|
68
|
|
|
try { |
|
69
|
|
|
$this->directoryChecker->ensureDirectoryExistsAndIsWritable($this->publicDir.'/assets/', $output, $this->getName()); |
|
70
|
|
|
$this->directoryChecker->ensureDirectoryExistsAndIsWritable($this->publicDir.'/bundles/', $output, $this->getName()); |
|
71
|
|
|
} catch (\RuntimeException $exception) { |
|
72
|
|
|
return 1; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$commands = [ |
|
76
|
|
|
'assets:install', |
|
77
|
|
|
]; |
|
78
|
|
|
|
|
79
|
|
|
$this->commandsRunner->run($commands, $input, $output, $this->getApplication()); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: