1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-31 19:49:20 +02:00

[ticket/14125] Add --env option to all CLI commands

PHPBB3-14125
This commit is contained in:
Tristan Darricau 2015-08-24 17:45:24 +02:00
parent f6a4843c6d
commit c868582e44
3 changed files with 56 additions and 14 deletions

View File

@ -46,13 +46,17 @@ require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx);
$phpbb_container = $phpbb_container_builder->with_config($phpbb_config_php_file);
$phpbb_container_builder->without_cache();
$input = new ArgvInput();
if ($input->hasParameterOption(array('--env')))
{
$phpbb_container_builder->with_environment($input->getParameterOption('--env'));
}
if ($input->hasParameterOption(array('--safe-mode')))
{
$phpbb_container_builder->without_extensions();
$phpbb_container_builder->without_cache();
}
else
{
@ -68,6 +72,8 @@ require($phpbb_root_path . 'includes/compatibility_globals.' . $phpEx);
$user = $phpbb_container->get('user');
$user->add_lang('acp/common');
$user->add_lang('cli');
/* @var $lang \phpbb\language\language */
$lang = $phpbb_container->get('language');
$application = new \phpbb\console\application('phpBB Console', PHPBB_VERSION, $lang);

View File

@ -58,8 +58,11 @@ $lang = array_merge($lang, array(
'CLI_DESCRIPTION_GET_CONFIG' => 'Gets a configuration options value',
'CLI_DESCRIPTION_INCREMENT_CONFIG' => 'Increments a configuration options value',
'CLI_DESCRIPTION_LIST_EXTENSIONS' => 'Lists all extensions in the database and on the filesystem.',
'CLI_DESCRIPTION_OPTION_ENV' => 'The Environment name.',
'CLI_DESCRIPTION_OPTION_SAFE_MODE' => 'Run in Safe Mode (without extensions).',
'CLI_DESCRIPTION_OPTION_SHELL' => 'Launch the shell.',
'CLI_DESCRIPTION_PURGE_EXTENSION' => 'Purges the specified extension.',
'CLI_DESCRIPTION_REPARSER_LIST' => 'Lists the types of text that can be reparsed.',
'CLI_DESCRIPTION_REPARSER_REPARSE' => 'Reparses stored text with the current text_formatter services.',

View File

@ -13,6 +13,7 @@
namespace phpbb\console;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Shell;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@ -49,12 +50,7 @@ class application extends \Symfony\Component\Console\Application
{
$input_definition = parent::getDefaultInputDefinition();
$input_definition->addOption(new InputOption(
'safe-mode',
null,
InputOption::VALUE_NONE,
$this->language->lang('CLI_DESCRIPTION_OPTION_SAFE_MODE')
));
$this->register_global_options($input_definition);
return $input_definition;
}
@ -76,12 +72,20 @@ class application extends \Symfony\Component\Console\Application
return parent::getHelp();
}
$this->getDefinition()->addOption(new InputOption(
'--shell',
'-s',
InputOption::VALUE_NONE,
$this->language->lang('CLI_DESCRIPTION_OPTION_SHELL')
));
try
{
$definition = $this->getDefinition();
$definition->addOption(new InputOption(
'--shell',
'-s',
InputOption::VALUE_NONE,
$this->language->lang('CLI_DESCRIPTION_OPTION_SHELL')
));
}
catch (\LogicException $e)
{
// Do nothing
}
return parent::getHelp();
}
@ -117,4 +121,33 @@ class application extends \Symfony\Component\Console\Application
return parent::doRun($input, $output);
}
/**
* Register global options
*
* @param InputDefinition $definition An InputDefinition instance
*/
protected function register_global_options(InputDefinition $definition)
{
try
{
$definition->addOption(new InputOption(
'safe-mode',
null,
InputOption::VALUE_NONE,
$this->language->lang('CLI_DESCRIPTION_OPTION_SAFE_MODE')
));
$definition->addOption(new InputOption(
'env',
'e',
InputOption::VALUE_REQUIRED,
$this->language->lang('CLI_DESCRIPTION_OPTION_ENV')
));
}
catch (\LogicException $e)
{
// Do nothing
}
}
}