[ Index ]

PHP Cross Reference of phpBB-3.3.7-deutsch

title

Body

[close]

/phpbb/console/ -> application.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\console;
  15  
  16  use Symfony\Component\Console\Input\InputDefinition;
  17  use Symfony\Component\Console\Shell;
  18  use Symfony\Component\Console\Input\InputInterface;
  19  use Symfony\Component\Console\Input\InputOption;
  20  use Symfony\Component\Console\Output\OutputInterface;
  21  
  22  class application extends \Symfony\Component\Console\Application
  23  {
  24      /**
  25      * @var bool Indicates whether or not we are in a shell
  26      */
  27      protected $in_shell = false;
  28  
  29      /**
  30      * @var \phpbb\config\config Config object
  31      */
  32      protected $config;
  33  
  34      /**
  35      * @var \phpbb\language\language Language object
  36      */
  37      protected $language;
  38  
  39      /**
  40      * @param string                        $name        The name of the application
  41      * @param string                        $version    The version of the application
  42      * @param \phpbb\language\language    $language    The user which runs the application (used for translation)
  43      * @param \phpbb\config\config        $config        Config object
  44      */
  45  	public function __construct($name, $version, \phpbb\language\language $language, \phpbb\config\config $config)
  46      {
  47          $this->language = $language;
  48          $this->config = $config;
  49  
  50          parent::__construct($name, $version);
  51      }
  52  
  53      /**
  54      * {@inheritdoc}
  55      */
  56  	protected function getDefaultInputDefinition()
  57      {
  58          $input_definition = parent::getDefaultInputDefinition();
  59  
  60          $this->register_global_options($input_definition);
  61  
  62          return $input_definition;
  63      }
  64  
  65      /**
  66      * Gets the help message.
  67      *
  68      * It's a hack of the default help message to display the --shell
  69      * option only for the application and not for all the commands.
  70      *
  71      * @return string A help message.
  72      */
  73  	public function getHelp()
  74      {
  75          // If we are already in a shell
  76          // we do not want to have the --shell option available
  77          if ($this->in_shell)
  78          {
  79              return parent::getHelp();
  80          }
  81  
  82          try
  83          {
  84              $definition = $this->getDefinition();
  85              $definition->addOption(new InputOption(
  86                  '--shell',
  87                  '-s',
  88                  InputOption::VALUE_NONE,
  89                  $this->language->lang('CLI_DESCRIPTION_OPTION_SHELL')
  90              ));
  91          }
  92          catch (\LogicException $e)
  93          {
  94              // Do nothing
  95          }
  96  
  97          return parent::getHelp();
  98      }
  99  
 100      /**
 101      * Register a set of commands from the container
 102      *
 103      * @param \phpbb\di\service_collection    $command_collection    The console service collection
 104      */
 105  	public function register_container_commands(\phpbb\di\service_collection $command_collection)
 106      {
 107          $commands_list = array_keys($command_collection->getArrayCopy());
 108          foreach ($commands_list as $service_command)
 109          {
 110              // config_text DB table does not exist in phpBB prior to 3.1
 111              // Hence skip cron tasks as they include reparser cron as it uses config_text table
 112              if (phpbb_version_compare($this->config['version'], '3.1.0', '<') && strpos($service_command, 'cron') !== false)
 113              {
 114                  continue;
 115              }
 116              $this->add($command_collection[$service_command]);
 117  
 118          }
 119      }
 120  
 121      /**
 122      * {@inheritdoc}
 123      */
 124  	public function doRun(InputInterface $input, OutputInterface $output)
 125      {
 126          // Run a shell if the --shell (or -s) option is set and if no command name is specified
 127          // Also, we do not want to have the --shell option available if we are already in a shell
 128          if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s')))
 129          {
 130              $shell = new Shell($this);
 131              $this->in_shell = true;
 132              $shell->run();
 133  
 134              return 0;
 135          }
 136  
 137          return parent::doRun($input, $output);
 138      }
 139  
 140      /**
 141       * Register global options
 142       *
 143       * @param InputDefinition $definition An InputDefinition instance
 144       */
 145  	protected function register_global_options(InputDefinition $definition)
 146      {
 147          try
 148          {
 149              $definition->addOption(new InputOption(
 150                  'safe-mode',
 151                  null,
 152                  InputOption::VALUE_NONE,
 153                  $this->language->lang('CLI_DESCRIPTION_OPTION_SAFE_MODE')
 154              ));
 155  
 156              $definition->addOption(new InputOption(
 157                  'env',
 158                  'e',
 159                  InputOption::VALUE_REQUIRED,
 160                  $this->language->lang('CLI_DESCRIPTION_OPTION_ENV')
 161              ));
 162          }
 163          catch (\LogicException $e)
 164          {
 165              // Do nothing
 166          }
 167      }
 168  }


Generated: Thu Mar 24 21:31:15 2022 Cross-referenced by PHPXref 0.7.1