|
1
|
|
|
<?php |
|
2
|
|
|
namespace Yoanm\ComposerConfigManager\Infrastructure\Command; |
|
3
|
|
|
|
|
4
|
|
|
use Symfony\Component\Console\Command\Command; |
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
7
|
|
|
use Yoanm\ComposerConfigManager\Application\Loader\ConfigurationFileLoaderInterface; |
|
8
|
|
|
use Yoanm\ComposerConfigManager\Domain\Model\Configuration; |
|
9
|
|
|
use Yoanm\ComposerConfigManager\Domain\Model\ConfigurationFile; |
|
10
|
|
|
|
|
11
|
|
|
abstract class AbstractTemplatableCommand extends Command |
|
12
|
|
|
{ |
|
13
|
|
|
const OPTION_TEMPLATE = 'template'; |
|
14
|
|
|
|
|
15
|
|
|
/** @var ConfigurationFileLoaderInterface */ |
|
16
|
|
|
private $configurationFileLoader; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param ConfigurationFileLoaderInterface $configurationFileLoader |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct(ConfigurationFileLoaderInterface $configurationFileLoader) |
|
22
|
|
|
{ |
|
23
|
|
|
parent::__construct(); |
|
24
|
|
|
$this->configurationFileLoader = $configurationFileLoader; |
|
25
|
|
|
} |
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function configure() |
|
30
|
|
|
{ |
|
31
|
|
|
$this |
|
32
|
|
|
->addOption( |
|
33
|
|
|
self::OPTION_TEMPLATE, |
|
34
|
|
|
null, |
|
35
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
36
|
|
|
'Path of the json template file. Will be used as default values.' |
|
37
|
|
|
) |
|
38
|
|
|
; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return ConfigurationFileLoaderInterface |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getConfigurationFileLoader() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->configurationFileLoader; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param InputInterface $input |
|
51
|
|
|
* |
|
52
|
|
|
* @return ConfigurationFile[] |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function loadTemplateConfigurationFileList(InputInterface $input) |
|
55
|
|
|
{ |
|
56
|
|
|
$templatePathList = $input->getOption(self::OPTION_TEMPLATE); |
|
57
|
|
|
$templateConfigurationList = []; |
|
58
|
|
|
if (count($templatePathList)) { |
|
59
|
|
|
foreach ($templatePathList as $templatePath) { |
|
60
|
|
|
if (is_dir($templatePath)) { |
|
61
|
|
|
$templateConfigurationList[] = $this->configurationFileLoader->fromPath($templatePath); |
|
62
|
|
|
} elseif (is_file($templatePath)) { |
|
63
|
|
|
$templateConfigurationList[] = $this->configurationFileLoader->fromString( |
|
64
|
|
|
file_get_contents($templatePath) |
|
65
|
|
|
); |
|
66
|
|
|
} else { |
|
67
|
|
|
throw new \UnexpectedValueException('Template path is nor a file or a path !'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $templateConfigurationList; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|