1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Del\Booty; |
4
|
|
|
|
5
|
|
|
use Composer\Autoload\ClassLoader; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
class BootyCommand extends Command |
11
|
|
|
{ |
12
|
|
|
/** @var array */ |
13
|
|
|
private $packages; |
14
|
|
|
|
15
|
|
|
/** @var AssetManager $booty */ |
16
|
|
|
private $booty; |
17
|
|
|
|
18
|
|
|
/** @var ClassLoader $composer */ |
19
|
|
|
private $composer; |
20
|
|
|
|
21
|
|
|
/** @var string $destination */ |
22
|
|
|
private $destination = 'public/'; |
23
|
|
|
|
24
|
1 |
|
public function __construct(string $name = null, array $packages, ClassLoader $composer) |
25
|
|
|
{ |
26
|
1 |
|
parent::__construct($name); |
27
|
1 |
|
$this->packages = $packages; |
28
|
1 |
|
$this->booty = new AssetManager(); |
29
|
1 |
|
$this->composer = $composer; |
30
|
|
|
} |
31
|
|
|
|
32
|
1 |
|
protected function configure() |
33
|
|
|
{ |
34
|
1 |
|
parent::configure(); |
35
|
1 |
|
$this->setName('deploy'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param InputInterface $input |
40
|
|
|
* @param OutputInterface $output |
41
|
|
|
* @return int|void|null |
42
|
|
|
*/ |
43
|
1 |
|
public function execute(InputInterface $input, OutputInterface $output) |
44
|
|
|
{ |
45
|
1 |
|
$this->booty->setDestinationFolder($this->destination); |
46
|
|
|
|
47
|
1 |
|
foreach ($this->packages as $packageName) { |
48
|
|
|
|
49
|
1 |
|
$packageName = strpos($packageName, '\\') === 0 ? $packageName : '\\' . $packageName; |
50
|
1 |
|
$package = new $packageName(); |
51
|
|
|
|
52
|
1 |
|
if ($package instanceof AssetRegistrationInterface) { |
53
|
1 |
|
$output->writeln('Adding assets from ' . $packageName . '..'); |
54
|
1 |
|
$paths = $package->getAssetFolders(); |
55
|
1 |
|
$this->handleAssetFolders($paths); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
$output->writeln('Deploying assets to ' . $this->destination); |
60
|
1 |
|
$this->booty->deployAssets(); |
61
|
|
|
|
62
|
1 |
|
return 0; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param array $paths |
67
|
|
|
*/ |
68
|
1 |
|
private function handleAssetFolders(array $paths): void |
69
|
|
|
{ |
70
|
1 |
|
foreach ($paths as $key => $path) { |
71
|
1 |
|
$this->booty->addAssetsFolder($key, $path); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|