From 5efd55a34883acad2971117d3a7faf20ecd7e08b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 4 Jun 2014 14:26:40 +0200 Subject: [ticket/12655] Run the shell when --shell is used PHPBB3-12655 --- phpBB/phpbb/console/application.php | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'phpBB/phpbb/console/application.php') diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index da2bfbb49a..00477ee7d7 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,10 +13,33 @@ namespace phpbb\console; +use Symfony\Component\Console\Shell; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\DependencyInjection\TaggedContainerInterface; class application extends \Symfony\Component\Console\Application { + /** + * @param string $name The name of the application + * @param string $version The version of the application + * @param \phpbb\user $user The user which runs the application (used for translation) + */ + public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN', \phpbb\user $user) + { + parent::__construct($name, $version); + + $this->getDefinition()->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, $user->lang('CLI_DESCRIPTION_OPTION_SHELL'))); + } + + /** + * Register a set of commands from the container + * + * @param TaggedContainerInterface $container The container + * @param string $tag The tag used to register the commands + */ function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command') { foreach($container->findTaggedServiceIds($tag) as $id => $void) @@ -24,4 +47,19 @@ class application extends \Symfony\Component\Console\Application $this->add($container->get($id)); } } + + /** + * {@inheritdoc} + */ + public function doRun(InputInterface $input, OutputInterface $output) + { + if ($input->hasParameterOption(array('--shell', '-s')) === true) { + $shell = new Shell($this); + $shell->run(); + + return 0; + } + + parent::doRun($input, $output); + } } -- cgit v1.2.1 From a14d16172c26fd8f849be4d3afcaac93b6dc4086 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 4 Jun 2014 15:34:11 +0200 Subject: [ticket/12655] Set the arguments of \phpbb\console\application as required PHPBB3-12655 --- phpBB/phpbb/console/application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/application.php') diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 00477ee7d7..eb8094e65f 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -27,7 +27,7 @@ class application extends \Symfony\Component\Console\Application * @param string $version The version of the application * @param \phpbb\user $user The user which runs the application (used for translation) */ - public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN', \phpbb\user $user) + public function __construct($name, $version, \phpbb\user $user) { parent::__construct($name, $version); -- cgit v1.2.1 From 99ebf4b8ddb53c796247fda7993f8999ceb16816 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 4 Jun 2014 21:08:11 +0200 Subject: [ticket/12655] Fix coding style in \phpbb\console\application PHPBB3-12655 --- phpBB/phpbb/console/application.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/application.php') diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index eb8094e65f..99fb5fbe97 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -31,7 +31,12 @@ class application extends \Symfony\Component\Console\Application { parent::__construct($name, $version); - $this->getDefinition()->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, $user->lang('CLI_DESCRIPTION_OPTION_SHELL'))); + $this->getDefinition()->addOption(new InputOption( + '--shell', + '-s', + InputOption::VALUE_NONE, + $user->lang('CLI_DESCRIPTION_OPTION_SHELL') + )); } /** @@ -53,7 +58,8 @@ class application extends \Symfony\Component\Console\Application */ public function doRun(InputInterface $input, OutputInterface $output) { - if ($input->hasParameterOption(array('--shell', '-s')) === true) { + if ($input->hasParameterOption(array('--shell', '-s')) === true) + { $shell = new Shell($this); $shell->run(); -- cgit v1.2.1 From ce104e2c72a00c58d19691f6af6ee5a3935a5fbd Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 4 Jun 2014 22:33:05 +0200 Subject: [ticket/12655] Make the --shell option available only for phpbbcli.php PHPBB3-12655 --- phpBB/phpbb/console/application.php | 47 ++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/console/application.php') diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 99fb5fbe97..9750367df0 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,6 +13,9 @@ namespace phpbb\console; +use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Output\ConsoleOutput; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Shell; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; @@ -22,6 +25,11 @@ use Symfony\Component\DependencyInjection\TaggedContainerInterface; class application extends \Symfony\Component\Console\Application { + /** + * @var bool Indicates whether or not we are in a shell + */ + protected $in_shell = false; + /** * @param string $name The name of the application * @param string $version The version of the application @@ -31,12 +39,42 @@ class application extends \Symfony\Component\Console\Application { parent::__construct($name, $version); + $this->user = $user; + } + + /** + * Gets the help message. + * + * It's a hack of the default help message to display the --shell + * option only for the application and not for all the commands. + * + * @return string A help message. + */ + public function getHelp() + { + // If we are already in a shell + // we do not want to have the --shell option available + if($this->in_shell) + { + return parent::getHelp(); + } + + // We store the definition to restore it later. + // Otherwise, in the shell mode the --shell option + // will be available for all command. + $definition_backup = $this->getDefinition(); + $this->getDefinition()->addOption(new InputOption( '--shell', '-s', InputOption::VALUE_NONE, - $user->lang('CLI_DESCRIPTION_OPTION_SHELL') + $this->user->lang('CLI_DESCRIPTION_OPTION_SHELL') )); + + $help_message = parent::getHelp(); + $this->setDefinition($definition_backup); + + return $help_message; } /** @@ -58,14 +96,17 @@ class application extends \Symfony\Component\Console\Application */ public function doRun(InputInterface $input, OutputInterface $output) { - if ($input->hasParameterOption(array('--shell', '-s')) === true) + // Run a shell if the --shell (or -s) option is set and if any command name is specified + // Also, we do not want to have the --shell option available if we are already in a shell + if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s')) === true) { $shell = new Shell($this); + $this->in_shell = true; $shell->run(); return 0; } - parent::doRun($input, $output); + return parent::doRun($input, $output); } } -- cgit v1.2.1 From 012702307b1503005f1b5b6c20e654dc8d23e8a0 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 5 Jun 2014 00:21:53 +0200 Subject: [ticket/12655] Fix coding style PHPBB3-12655 --- phpBB/phpbb/console/application.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/console/application.php') diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 9750367df0..ff90a76a92 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,11 +13,7 @@ namespace phpbb\console; -use Symfony\Component\Console\Input\ArgvInput; -use Symfony\Component\Console\Output\ConsoleOutput; -use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Shell; -use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -30,6 +26,11 @@ class application extends \Symfony\Component\Console\Application */ protected $in_shell = false; + /** + * @var \phpbb\user User object + */ + protected $user; + /** * @param string $name The name of the application * @param string $version The version of the application @@ -54,7 +55,7 @@ class application extends \Symfony\Component\Console\Application { // If we are already in a shell // we do not want to have the --shell option available - if($this->in_shell) + if ($this->in_shell) { return parent::getHelp(); } @@ -96,9 +97,9 @@ class application extends \Symfony\Component\Console\Application */ public function doRun(InputInterface $input, OutputInterface $output) { - // Run a shell if the --shell (or -s) option is set and if any command name is specified + // Run a shell if the --shell (or -s) option is set and if no command name is specified // Also, we do not want to have the --shell option available if we are already in a shell - if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s')) === true) + if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s'))) { $shell = new Shell($this); $this->in_shell = true; -- cgit v1.2.1 From 5e9c8a0ceaabb84a679bd56e7165a9e29fc3da71 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 5 Jun 2014 01:00:33 +0200 Subject: [ticket/12655] Don't try to restore the definition in the help PHPBB3-12655 --- phpBB/phpbb/console/application.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/console/application.php') diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index ff90a76a92..91d95b9a7b 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,6 +13,9 @@ namespace phpbb\console; +use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Output\ConsoleOutput; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Shell; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -60,11 +63,6 @@ class application extends \Symfony\Component\Console\Application return parent::getHelp(); } - // We store the definition to restore it later. - // Otherwise, in the shell mode the --shell option - // will be available for all command. - $definition_backup = $this->getDefinition(); - $this->getDefinition()->addOption(new InputOption( '--shell', '-s', @@ -72,10 +70,7 @@ class application extends \Symfony\Component\Console\Application $this->user->lang('CLI_DESCRIPTION_OPTION_SHELL') )); - $help_message = parent::getHelp(); - $this->setDefinition($definition_backup); - - return $help_message; + return parent::getHelp(); } /** -- cgit v1.2.1 From 5b51acf245fc1fbd454d394e8b44bf73d6439248 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 5 Jun 2014 01:03:16 +0200 Subject: [ticket/12655] Set register_container_commands as public PHPBB3-12655 --- phpBB/phpbb/console/application.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/application.php') diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 91d95b9a7b..b1f0635913 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,9 +13,6 @@ namespace phpbb\console; -use Symfony\Component\Console\Input\ArgvInput; -use Symfony\Component\Console\Output\ConsoleOutput; -use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Shell; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -79,7 +76,7 @@ class application extends \Symfony\Component\Console\Application * @param TaggedContainerInterface $container The container * @param string $tag The tag used to register the commands */ - function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command') + public function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command') { foreach($container->findTaggedServiceIds($tag) as $id => $void) { -- cgit v1.2.1