| @@ 24-72 (lines=49) @@ | ||
| 21 | * @author Pavel Machekhin |
|
| 22 | * @created 2013-03-28 14:03 |
|
| 23 | */ |
|
| 24 | class InstallCommand extends AbstractCommand |
|
| 25 | { |
|
| 26 | /** |
|
| 27 | * Command configuration |
|
| 28 | */ |
|
| 29 | protected function configure() |
|
| 30 | { |
|
| 31 | $this |
|
| 32 | // the name of the command (the part after "bin/bluzman") |
|
| 33 | ->setName('module:install') |
|
| 34 | // the short description shown while running "php bin/bluzman list" |
|
| 35 | ->setDescription('Install new module') |
|
| 36 | // the full command description shown when running the command with |
|
| 37 | // the "--help" option |
|
| 38 | ->setHelp('Install module, for retrieve list run command <info>bluzman module:list</info>') |
|
| 39 | ; |
|
| 40 | ||
| 41 | $module = new InputArgument( |
|
| 42 | 'module', |
|
| 43 | InputArgument::REQUIRED, |
|
| 44 | 'Module name is required' |
|
| 45 | ); |
|
| 46 | ||
| 47 | $this->getDefinition()->addArgument($module); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @param InputInterface $input |
|
| 52 | * @param OutputInterface $output |
|
| 53 | * @return int|null|void |
|
| 54 | */ |
|
| 55 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 56 | { |
|
| 57 | // Composer\Factory::getHomeDir() method |
|
| 58 | // needs COMPOSER_HOME environment variable set |
|
| 59 | // putenv('COMPOSER_HOME=' . PATH_VENDOR . '/bin/composer'); |
|
| 60 | ||
| 61 | $arguments = [ |
|
| 62 | 'command' => 'require', |
|
| 63 | 'packages' => ['bluzphp/module-'. $input->getArgument('module')] |
|
| 64 | ]; |
|
| 65 | ||
| 66 | // call `composer install` command programmatically |
|
| 67 | $composerInput = new ArrayInput($arguments); |
|
| 68 | $application = new ComposerApplication(); |
|
| 69 | $application->setAutoExit(false); // prevent `$application->run` method from exiting the script |
|
| 70 | $application->run($composerInput); |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||
| @@ 24-72 (lines=49) @@ | ||
| 21 | * @author Pavel Machekhin |
|
| 22 | * @created 2013-03-28 14:03 |
|
| 23 | */ |
|
| 24 | class RemoveCommand extends AbstractCommand |
|
| 25 | { |
|
| 26 | /** |
|
| 27 | * Command configuration |
|
| 28 | */ |
|
| 29 | protected function configure() |
|
| 30 | { |
|
| 31 | $this |
|
| 32 | // the name of the command (the part after "bin/bluzman") |
|
| 33 | ->setName('module:remove') |
|
| 34 | // the short description shown while running "php bin/bluzman list" |
|
| 35 | ->setDescription('Remove installed module') |
|
| 36 | // the full command description shown when running the command with |
|
| 37 | // the "--help" option |
|
| 38 | ->setHelp('Remove module, for retrieve list of modules run command <info>bluzman module:list</info>') |
|
| 39 | ; |
|
| 40 | ||
| 41 | $module = new InputArgument( |
|
| 42 | 'module', |
|
| 43 | InputArgument::REQUIRED, |
|
| 44 | 'Module name is required' |
|
| 45 | ); |
|
| 46 | ||
| 47 | $this->getDefinition()->addArgument($module); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @param InputInterface $input |
|
| 52 | * @param OutputInterface $output |
|
| 53 | * @return int|null|void |
|
| 54 | */ |
|
| 55 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 56 | { |
|
| 57 | // Composer\Factory::getHomeDir() method |
|
| 58 | // needs COMPOSER_HOME environment variable set |
|
| 59 | // putenv('COMPOSER_HOME=' . PATH_VENDOR . '/bin/composer'); |
|
| 60 | ||
| 61 | $arguments = [ |
|
| 62 | 'command' => 'remove', |
|
| 63 | 'packages' => ['bluzphp/module-'. $input->getArgument('module')] |
|
| 64 | ]; |
|
| 65 | ||
| 66 | // call `composer install` command programmatically |
|
| 67 | $composerInput = new ArrayInput($arguments); |
|
| 68 | $application = new ComposerApplication(); |
|
| 69 | $application->setAutoExit(false); // prevent `$application->run` method from exiting the script |
|
| 70 | $application->run($composerInput); |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||