| @@ 15-64 (lines=50) @@ | ||
| 12 | * @package Samurai\Alias\Task |
|
| 13 | * @author Raphaël Lefebvre <[email protected]> |
|
| 14 | */ |
|
| 15 | class Removing extends Task |
|
| 16 | { |
|
| 17 | /** |
|
| 18 | * @param InputInterface $input |
|
| 19 | * @param OutputInterface $output |
|
| 20 | * @return bool |
|
| 21 | */ |
|
| 22 | public function execute(InputInterface $input, OutputInterface $output) |
|
| 23 | { |
|
| 24 | $aliasName = $input->getArgument('name'); |
|
| 25 | if(!$this->getService('alias_manager')->hasLocal($aliasName)){ |
|
| 26 | $output->writeln(sprintf('<error>Error: no alias "%s" found</error>', $aliasName)); |
|
| 27 | return ITask::BLOCKING_ERROR_CODE; |
|
| 28 | } |
|
| 29 | $alias = $this->getService('alias_manager')->get($aliasName); |
|
| 30 | if($this->confirmRemove($input, $output, $alias->getPackage())){ |
|
| 31 | $this->getService('alias_manager')->remove($aliasName); |
|
| 32 | } |
|
| 33 | 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 | private function confirmRemove(InputInterface $input, OutputInterface $output, $aliasPackage) |
|
| 43 | { |
|
| 44 | return $this->getService('helper_set')->get('question')->ask( |
|
| 45 | $input, |
|
| 46 | $output, |
|
| 47 | $this->buildQuestion($aliasPackage) |
|
| 48 | ); |
|
| 49 | } |
|
| 50 | ||
| 51 | /** |
|
| 52 | * @param string $aliasPackage |
|
| 53 | * @return ConfirmationQuestion |
|
| 54 | */ |
|
| 55 | private function buildQuestion($aliasPackage) |
|
| 56 | { |
|
| 57 | return new ConfirmationQuestion( |
|
| 58 | sprintf( |
|
| 59 | '<question>Do you want to remove the bootstrap "%s"</question>[y]', |
|
| 60 | $aliasPackage |
|
| 61 | ) |
|
| 62 | ); |
|
| 63 | } |
|
| 64 | } |
|
| 65 | ||
| @@ 15-66 (lines=52) @@ | ||
| 12 | * @package Samurai\module\Task |
|
| 13 | * @author Raphaël Lefebvre <[email protected]> |
|
| 14 | */ |
|
| 15 | class Removing extends Task |
|
| 16 | { |
|
| 17 | /** |
|
| 18 | * @param InputInterface $input |
|
| 19 | * @param OutputInterface $output |
|
| 20 | * @return bool |
|
| 21 | */ |
|
| 22 | public function execute(InputInterface $input, OutputInterface $output) |
|
| 23 | { |
|
| 24 | $moduleName = $input->getArgument('name'); |
|
| 25 | if(!$this->getService('module_manager')->has($moduleName)){ |
|
| 26 | $output->writeln(sprintf('<error>Error: no module "%s" found</error>', $moduleName)); |
|
| 27 | return ITask::BLOCKING_ERROR_CODE; |
|
| 28 | } |
|
| 29 | ||
| 30 | $module = $this->getService('module_manager')->get($moduleName); |
|
| 31 | if($this->confirmRemove($input, $output, $module->getPackage())){ |
|
| 32 | $this->getService('module_procedure')->setOutput($output); |
|
| 33 | $this->getService('module_procedure')->remove($module); |
|
| 34 | } |
|
| 35 | return ITask::NO_ERROR_CODE; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @param InputInterface $input |
|
| 40 | * @param OutputInterface $output |
|
| 41 | * @param string $modulePackage |
|
| 42 | * @return bool |
|
| 43 | */ |
|
| 44 | private function confirmRemove(InputInterface $input, OutputInterface $output, $modulePackage) |
|
| 45 | { |
|
| 46 | return $this->getService('helper_set')->get('question')->ask( |
|
| 47 | $input, |
|
| 48 | $output, |
|
| 49 | $this->buildQuestion($modulePackage) |
|
| 50 | ); |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * @param string $modulePackage |
|
| 55 | * @return ConfirmationQuestion |
|
| 56 | */ |
|
| 57 | private function buildQuestion($modulePackage) |
|
| 58 | { |
|
| 59 | return new ConfirmationQuestion( |
|
| 60 | sprintf( |
|
| 61 | '<question>Do you want to remove the module "%s"</question>[y]', |
|
| 62 | $modulePackage |
|
| 63 | ) |
|
| 64 | ); |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||