Index: branches/5.3.x/core/install/cache/class_structure.php =================================================================== diff -u -N -r16252 -r16282 --- branches/5.3.x/core/install/cache/class_structure.php (.../class_structure.php) (revision 16252) +++ branches/5.3.x/core/install/cache/class_structure.php (.../class_structure.php) (revision 16282) @@ -90,6 +90,7 @@ 'InPortal\\Core\\kernel\\Console\\Command\\RunScheduledTaskCommand' => '/core/kernel/Console/Command/RunScheduledTaskCommand.php', 'InPortal\\Core\\kernel\\Console\\ConsoleApplication' => '/core/kernel/Console/ConsoleApplication.php', 'InPortal\\Core\\kernel\\Console\\ConsoleCommandProvider' => '/core/kernel/Console/ConsoleCommandProvider.php', + 'InPortal\\Core\\kernel\\Console\\ConsoleIO' => '/core/kernel/Console/ConsoleIO.php', 'InPortal\\Core\\kernel\\Console\\IConsoleCommandProvider' => '/core/kernel/Console/IConsoleCommandProvider.php', 'InPortal\\Core\\kernel\\utility\\ClassDiscovery\\ClassDetector' => '/core/kernel/utility/ClassDiscovery/ClassDetector.php', 'InPortal\\Core\\kernel\\utility\\ClassDiscovery\\ClassMapBuilder' => '/core/kernel/utility/ClassDiscovery/ClassMapBuilder.php', @@ -904,6 +905,10 @@ 1 => 'InPortal\\Core\\kernel\\Console\\IConsoleCommandProvider', ), ), + 'InPortal\\Core\\kernel\\Console\\ConsoleIO' => array( + 'type' => 1, + 'modifiers' => 0, + ), 'InPortal\\Core\\kernel\\Console\\IConsoleCommandProvider' => array( 'type' => 2, ), Index: branches/5.3.x/core/kernel/Console/Command/ResetCacheCommand.php =================================================================== diff -u -N -r16252 -r16282 --- branches/5.3.x/core/kernel/Console/Command/ResetCacheCommand.php (.../ResetCacheCommand.php) (revision 16252) +++ branches/5.3.x/core/kernel/Console/Command/ResetCacheCommand.php (.../ResetCacheCommand.php) (revision 16282) @@ -1,6 +1,6 @@ optionMap as $option_name => $option_data ) { - if ( !$input->getOption($option_name) ) { + if ( !$this->io->getOption($option_name) ) { continue; } $success_count++; - $output->write('- ' . $option_data['description'] . ' ... '); + $this->io->write('- ' . $option_data['description'] . ' ... '); $event = new \kEvent($option_data['event']); $this->Application->HandleEvent($event); if ( $event->getRedirectParam('action_completed') ) { - $output->writeln('OK'); + $this->io->writeln('OK'); } else { $error_count++; - $output->writeln('FAILED'); + $this->io->writeln('FAILED'); } } Index: branches/5.3.x/core/kernel/Console/Command/AbstractCommand.php =================================================================== diff -u -N -r16252 -r16282 --- branches/5.3.x/core/kernel/Console/Command/AbstractCommand.php (.../AbstractCommand.php) (revision 16252) +++ branches/5.3.x/core/kernel/Console/Command/AbstractCommand.php (.../AbstractCommand.php) (revision 16282) @@ -1,6 +1,6 @@ getDefinition()->getArgumentRequiredCount() ) { throw new \RuntimeException('Not enough arguments.'); } + + // Don't use factory because of "classmap:rebuild" command. + $this->io = new ConsoleIO($input, $output, $this->getHelperSet()); } } Index: branches/5.3.x/core/kernel/Console/ConsoleIO.php =================================================================== diff -u -N --- branches/5.3.x/core/kernel/Console/ConsoleIO.php (revision 0) +++ branches/5.3.x/core/kernel/Console/ConsoleIO.php (revision 16282) @@ -0,0 +1,230 @@ +_input = $input; + $this->_output = $output; + $this->_helperSet = $helper_set; + } + + /** + * Gets argument by name. + * + * @param string $name The name of the argument. + * + * @return mixed + */ + public function getArgument($name) + { + return $this->_input->getArgument($name); + } + + /** + * Gets an option by name. + * + * @param string $name The name of the option. + * + * @return mixed + */ + public function getOption($name) + { + return $this->_input->getOption($name); + } + + /** + * Is this input means interactive? + * + * @return boolean + */ + public function isInteractive() + { + return $this->_input->isInteractive(); + } + + /** + * Gets the decorated flag. + * + * @return boolean true if the output will decorate messages, false otherwise + */ + public function isDecorated() + { + return $this->_output->isDecorated(); + } + + /** + * Determines if verbose output is being requested. + * + * @return boolean + */ + public function isVerbose() + { + return $this->_output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE; + } + + /** + * Determines if very verbose output is being requested. + * + * @return boolean + */ + public function isVeryVerbose() + { + return $this->_output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE; + } + + /** + * Determines if debug output is being requested. + * + * @return boolean + */ + public function isDebug() + { + return $this->_output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG; + } + + /** + * Writes a message to the output. + * + * @param string|array $messages The message as an array of lines or a single string. + * @param boolean $newline Whether to add a newline. + * @param integer $type The type of output (one of the OUTPUT constants). + * + * @return void + */ + public function write($messages, $newline = false, $type = OutputInterface::OUTPUT_NORMAL) + { + $this->_output->write($messages, $newline, $type); + } + + /** + * Writes a message to the output and adds a newline at the end. + * + * @param string|array $messages The message as an array of lines of a single string. + * @param integer $type The type of output (one of the OUTPUT constants). + * + * @return void + */ + public function writeln($messages, $type = OutputInterface::OUTPUT_NORMAL) + { + $this->_output->writeln($messages, $type); + } + + /** + * Asks a confirmation to the user. + * The question will be asked until the user answers by nothing, yes, or no. + * + * @param string|array $question The question to ask. + * @param boolean $default The default answer if the user enters nothing. + * + * @return boolean true if the user has confirmed, false otherwise + */ + public function askConfirmation($question, $default = true) + { + /** @var QuestionHelper $helper */ + $helper = $this->_helperSet->get('question'); + $confirmation_question = new ConfirmationQuestion( + '' . $question . ' [' . ($default ? 'y' : 'n') . ']? ', + $default + ); + + return $helper->ask($this->_input, $this->_output, $confirmation_question); + } + + /** + * Asks user to choose. + * + * @param string $question The question to ask. + * @param array $options Valid answer options. + * @param mixed $default Default answer. + * @param string $error_message Error on incorrect answer. + * + * @return mixed + */ + public function choose($question, array $options, $default, $error_message) + { + /** @var QuestionHelper $helper */ + $helper = $this->_helperSet->get('question'); + $choice_question = new ChoiceQuestion('' . $question . ' ', $options, $default); + $choice_question->setErrorMessage($error_message); + + return $helper->ask($this->_input, $this->_output, $choice_question); + } + + /** + * Returns progress bar instance. + * + * @param integer $max Maximum steps (0 if unknown). + * + * @return ProgressBar + */ + public function createProgressBar($max = 0) + { + return new ProgressBar($this->_output, $max); + } + + /** + * Returns output. + * + * @return OutputInterface + */ + public function getOutput() + { + return $this->_output; + } + +} Index: branches/5.3.x/core/kernel/Console/Command/RunScheduledTaskCommand.php =================================================================== diff -u -N -r16252 -r16282 --- branches/5.3.x/core/kernel/Console/Command/RunScheduledTaskCommand.php (.../RunScheduledTaskCommand.php) (revision 16252) +++ branches/5.3.x/core/kernel/Console/Command/RunScheduledTaskCommand.php (.../RunScheduledTaskCommand.php) (revision 16282) @@ -1,6 +1,6 @@ getArgument('scheduled_task_name'); + $scheduled_task_name = $this->io->getArgument('scheduled_task_name'); if ( !$scheduled_task_name ) { $this->Application->EventManager->runScheduledTasks(true); Index: branches/5.3.x/core/kernel/Console/Command/RunEventCommand.php =================================================================== diff -u -N -r16252 -r16282 --- branches/5.3.x/core/kernel/Console/Command/RunEventCommand.php (.../RunEventCommand.php) (revision 16252) +++ branches/5.3.x/core/kernel/Console/Command/RunEventCommand.php (.../RunEventCommand.php) (revision 16282) @@ -1,6 +1,6 @@ getArgument('event_name'); + $event_name = $this->io->getArgument('event_name'); $run_event = new \kEvent($event_name); $this->Application->HandleEvent($run_event); Index: branches/5.3.x/core/kernel/Console/Command/BuildClassMapCommand.php =================================================================== diff -u -N -r16252 -r16282 --- branches/5.3.x/core/kernel/Console/Command/BuildClassMapCommand.php (.../BuildClassMapCommand.php) (revision 16252) +++ branches/5.3.x/core/kernel/Console/Command/BuildClassMapCommand.php (.../BuildClassMapCommand.php) (revision 16282) @@ -1,6 +1,6 @@ getOption('module'); + $user_modules = $this->io->getOption('module'); if ( $user_modules ) { $modules_filter = array(); @@ -86,7 +86,7 @@ $table ->setHeaders(array('Path', 'Scanned in', 'Parsed in')) ->setRows($table_rows); - $table->render($output); + $table->render($this->io->getOutput()); return 0; }