Page MenuHomeIn-Portal Phabricator

D135.id315.diff
No OneTemporary

File Metadata

Created
Wed, Feb 26, 9:05 AM

D135.id315.diff

Index: core/install/cache/class_structure.php
===================================================================
--- core/install/cache/class_structure.php
+++ core/install/cache/class_structure.php
@@ -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: core/kernel/Console/Command/AbstractCommand.php
===================================================================
--- core/kernel/Console/Command/AbstractCommand.php
+++ core/kernel/Console/Command/AbstractCommand.php
@@ -16,6 +16,7 @@
use InPortal\Core\kernel\Console\ConsoleApplication;
+use InPortal\Core\kernel\Console\ConsoleIO;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -40,6 +41,13 @@
protected $Conn = null;
/**
+ * Console IO.
+ *
+ * @var ConsoleIO
+ */
+ protected $io;
+
+ /**
* Sets the application instance for this command.
*
* @param ConsoleApplication $application An Application instance.
@@ -74,6 +82,9 @@
if ( count($arguments) < $this->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: core/kernel/Console/Command/BuildClassMapCommand.php
===================================================================
--- core/kernel/Console/Command/BuildClassMapCommand.php
+++ core/kernel/Console/Command/BuildClassMapCommand.php
@@ -55,7 +55,7 @@
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $user_modules = $input->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;
}
Index: core/kernel/Console/Command/ResetCacheCommand.php
===================================================================
--- core/kernel/Console/Command/ResetCacheCommand.php
+++ core/kernel/Console/Command/ResetCacheCommand.php
@@ -102,22 +102,22 @@
$error_count = 0;
foreach ( $this->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('<info>OK</info>');
+ $this->io->writeln('<info>OK</info>');
}
else {
$error_count++;
- $output->writeln('<error>FAILED</error>');
+ $this->io->writeln('<error>FAILED</error>');
}
}
Index: core/kernel/Console/Command/RunEventCommand.php
===================================================================
--- core/kernel/Console/Command/RunEventCommand.php
+++ core/kernel/Console/Command/RunEventCommand.php
@@ -53,7 +53,7 @@
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $event_name = $input->getArgument('event_name');
+ $event_name = $this->io->getArgument('event_name');
$run_event = new \kEvent($event_name);
$this->Application->HandleEvent($run_event);
Index: core/kernel/Console/Command/RunScheduledTaskCommand.php
===================================================================
--- core/kernel/Console/Command/RunScheduledTaskCommand.php
+++ core/kernel/Console/Command/RunScheduledTaskCommand.php
@@ -53,7 +53,7 @@
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $scheduled_task_name = $input->getArgument('scheduled_task_name');
+ $scheduled_task_name = $this->io->getArgument('scheduled_task_name');
if ( !$scheduled_task_name ) {
$this->Application->EventManager->runScheduledTasks(true);
Index: core/kernel/Console/ConsoleIO.php
===================================================================
--- /dev/null
+++ core/kernel/Console/ConsoleIO.php
@@ -0,0 +1,230 @@
+<?php
+/**
+* @version $Id$
+* @package In-Portal
+* @copyright Copyright (C) 1997 - 2015 Intechnic. All rights reserved.
+* @license GNU/GPL
+* In-Portal is Open Source software.
+* This means that this software may have been modified pursuant
+* the GNU General Public License, and as distributed it includes
+* or is derivative of works licensed under the GNU General Public License
+* or other free or open source software licenses.
+* See http://www.in-portal.org/license for copyright notices and details.
+*/
+
+namespace InPortal\Core\kernel\Console;
+
+
+use Symfony\Component\Console\Helper\HelperSet;
+use Symfony\Component\Console\Helper\ProgressBar;
+use Symfony\Component\Console\Helper\QuestionHelper;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Question\ChoiceQuestion;
+use Symfony\Component\Console\Question\ConfirmationQuestion;
+
+defined('FULL_PATH') or die('restricted access!');
+
+class ConsoleIO
+{
+
+ /**
+ * Input.
+ *
+ * @var InputInterface
+ */
+ private $_input;
+
+ /**
+ * Output.
+ *
+ * @var OutputInterface
+ */
+ private $_output;
+
+ /**
+ * Helper set.
+ *
+ * @var HelperSet
+ */
+ private $_helperSet;
+
+ /**
+ * Creates class instance.
+ *
+ * @param InputInterface $input Input.
+ * @param OutputInterface $output Output.
+ * @param HelperSet $helper_set Helper set.
+ */
+ public function __construct(InputInterface $input, OutputInterface $output, HelperSet $helper_set)
+ {
+ $this->_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>' . $question . ' [' . ($default ? 'y' : 'n') . ']?</question> ',
+ $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>' . $question . '</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;
+ }
+
+}

Event Timeline