|
1
|
|
|
<?php |
|
2
|
|
|
namespace Samurai\Project\Question; |
|
3
|
|
|
|
|
4
|
|
|
use Samurai\alias\Alias; |
|
5
|
|
|
use Samurai\Task\ITask; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class BootstrapQuestion |
|
12
|
|
|
* @package Samurai\Project\Question |
|
13
|
|
|
* @author Raphaël Lefebvre <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class BootstrapQuestion extends Question |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param InputInterface $input |
|
19
|
|
|
* @param OutputInterface $output |
|
20
|
|
|
* @return int |
|
21
|
|
|
*/ |
|
22
|
5 |
|
public function execute(InputInterface $input, OutputInterface $output) |
|
23
|
|
|
{ |
|
24
|
5 |
|
if($input->getArgument('bootstrap')){ |
|
25
|
3 |
|
$this->setFromArgs($input); |
|
26
|
3 |
|
}else{ |
|
27
|
2 |
|
$this->setFromAlias($this->askForAlias($input, $output)); |
|
28
|
|
|
} |
|
29
|
5 |
|
return $this->getProject()->getBootstrap()->getPackage() ? ITask::NO_ERROR_CODE : ITask::BLOCKING_ERROR_CODE; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param InputInterface $input |
|
34
|
|
|
* @param OutputInterface $output |
|
35
|
|
|
* @return Alias |
|
36
|
|
|
*/ |
|
37
|
2 |
|
private function askForAlias(InputInterface $input, OutputInterface $output) |
|
38
|
|
|
{ |
|
39
|
2 |
|
return $this->ask( |
|
40
|
2 |
|
$input, |
|
41
|
2 |
|
$output, |
|
42
|
2 |
|
new ChoiceQuestion( |
|
43
|
2 |
|
'<question>Choose a bootstrap:</question>', |
|
44
|
2 |
|
$this->getService('alias_manager')->getAll() |
|
45
|
2 |
|
) |
|
46
|
2 |
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param Alias $alias |
|
51
|
|
|
*/ |
|
52
|
5 |
|
private function setFromAlias(Alias $alias) |
|
53
|
|
|
{ |
|
54
|
5 |
|
$this->getProject()->setBootstrap($alias); |
|
55
|
5 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param InputInterface $input |
|
59
|
|
|
*/ |
|
60
|
3 |
|
private function setFromArgs(InputInterface $input) |
|
61
|
|
|
{ |
|
62
|
3 |
|
if ($this->getService('alias_manager')->has($input->getArgument('bootstrap'))) { |
|
63
|
|
|
$this->setFromAlias($this->getService('alias_manager')->get($input->getArgument('bootstrap'))); |
|
64
|
|
|
} else { |
|
65
|
3 |
|
$alias = new Alias(); |
|
66
|
3 |
|
$alias->setPackage($input->getArgument('bootstrap')); |
|
67
|
3 |
|
$alias->setVersion($input->getArgument('version')); |
|
68
|
3 |
|
$alias->setSource($input->getArgument('source')); |
|
69
|
3 |
|
$this->setFromAlias($alias); |
|
70
|
|
|
} |
|
71
|
3 |
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|