|
1
|
|
|
<?php |
|
2
|
|
|
namespace Samurai\Alias\Task; |
|
3
|
|
|
|
|
4
|
|
|
use Samurai\Task\ITask; |
|
5
|
|
|
use Samurai\Task\Task; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class Removing |
|
12
|
|
|
* @package Samurai\Alias\Task |
|
13
|
|
|
* @author Raphaël Lefebvre <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
View Code Duplication |
class Removing extends Task |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param InputInterface $input |
|
19
|
|
|
* @param OutputInterface $output |
|
20
|
|
|
* @return bool |
|
21
|
|
|
*/ |
|
22
|
5 |
|
public function execute(InputInterface $input, OutputInterface $output) |
|
23
|
|
|
{ |
|
24
|
5 |
|
$aliasName = $input->getArgument('name'); |
|
25
|
5 |
|
if(!$this->getService('alias_manager')->hasLocal($aliasName)){ |
|
26
|
1 |
|
$output->writeln(sprintf('<error>Error: no alias "%s" found</error>', $aliasName)); |
|
27
|
1 |
|
return ITask::BLOCKING_ERROR_CODE; |
|
28
|
|
|
} |
|
29
|
4 |
|
$alias = $this->getService('alias_manager')->get($aliasName); |
|
30
|
4 |
|
if($this->confirmRemove($input, $output, $alias->getPackage())){ |
|
31
|
2 |
|
$this->getService('alias_manager')->remove($aliasName); |
|
32
|
2 |
|
} |
|
33
|
4 |
|
return ITask::NO_ERROR_CODE; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param InputInterface $input |
|
38
|
|
|
* @param OutputInterface $output |
|
39
|
|
|
* @param string $aliasPackage |
|
40
|
|
|
* @return bool |
|
41
|
|
|
*/ |
|
42
|
4 |
|
private function confirmRemove(InputInterface $input, OutputInterface $output, $aliasPackage) |
|
43
|
|
|
{ |
|
44
|
4 |
|
return $this->getService('helper_set')->get('question')->ask( |
|
45
|
4 |
|
$input, |
|
46
|
4 |
|
$output, |
|
47
|
4 |
|
$this->buildQuestion($aliasPackage) |
|
48
|
4 |
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param string $aliasPackage |
|
53
|
|
|
* @return ConfirmationQuestion |
|
54
|
|
|
*/ |
|
55
|
4 |
|
private function buildQuestion($aliasPackage) |
|
56
|
|
|
{ |
|
57
|
4 |
|
return new ConfirmationQuestion( |
|
58
|
4 |
|
sprintf( |
|
59
|
4 |
|
'<question>Do you want to remove the bootstrap "%s"</question>[y]', |
|
60
|
|
|
$aliasPackage |
|
61
|
4 |
|
) |
|
62
|
4 |
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|