[ Index ]

PHP Cross Reference of phpBB-3.3.0-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\language\language User object
  31      */
  32      protected $language;
  33  
  34      /**
  35      * @param string                        $name        The name of the application
  36      * @param string                        $version    The version of the application
  37      * @param \phpbb\language\language    $language    The user which runs the application (used for translation)
  38      */
  39  	public function __construct($name, $version, \phpbb\language\language $language)
  40      {
  41          $this->language = $language;
  42  
  43          parent::__construct($name, $version);
  44      }
  45  
  46      /**
  47      * {@inheritdoc}
  48      */
  49  	protected function getDefaultInputDefinition()
  50      {
  51          $input_definition = parent::getDefaultInputDefinition();
  52  
  53          $this->register_global_options($input_definition);
  54  
  55          return $input_definition;
  56      }
  57  
  58      /**
  59      * Gets the help message.
  60      *
  61      * It's a hack of the default help message to display the --shell
  62      * option only for the application and not for all the commands.
  63      *
  64      * @return string A help message.
  65      */
  66  	public function getHelp()
  67      {
  68          // If we are already in a shell
  69          // we do not want to have the --shell option available
  70          if ($this->in_shell)
  71          {
  72              return parent::getHelp();
  73          }
  74  
  75          try
  76          {
  77              $definition = $this->getDefinition();
  78              $definition->addOption(new InputOption(
  79                  '--shell',
  80                  '-s',
  81                  InputOption::VALUE_NONE,
  82                  $this->language->lang('CLI_DESCRIPTION_OPTION_SHELL')
  83              ));
  84          }
  85          catch (\LogicException $e)
  86          {
  87              // Do nothing
  88          }
  89  
  90          return parent::getHelp();
  91      }
  92  
  93      /**
  94      * Register a set of commands from the container
  95      *
  96      * @param \phpbb\di\service_collection    $command_collection    The console service collection
  97      */
  98  	public function register_container_commands(\phpbb\di\service_collection $command_collection)
  99      {
 100          foreach ($command_collection as $service_command)
 101          {
 102              $this->add($service_command);
 103          }
 104      }
 105  
 106      /**
 107      * {@inheritdoc}
 108      */
 109  	public function doRun(InputInterface $input, OutputInterface $output)
 110      {
 111          // Run a shell if the --shell (or -s) option is set and if no command name is specified
 112          // Also, we do not want to have the --shell option available if we are already in a shell
 113          if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s')))
 114          {
 115              $shell = new Shell($this);
 116              $this->in_shell = true;
 117              $shell->run();
 118  
 119              return 0;
 120          }
 121  
 122          return parent::doRun($input, $output);
 123      }
 124  
 125      /**
 126       * Register global options
 127       *
 128       * @param InputDefinition $definition An InputDefinition instance
 129       */
 130  	protected function register_global_options(InputDefinition $definition)
 131      {
 132          try
 133          {
 134              $definition->addOption(new InputOption(
 135                  'safe-mode',
 136                  null,
 137                  InputOption::VALUE_NONE,
 138                  $this->language->lang('CLI_DESCRIPTION_OPTION_SAFE_MODE')
 139              ));
 140  
 141              $definition->addOption(new InputOption(
 142                  'env',
 143                  'e',
 144                  InputOption::VALUE_REQUIRED,
 145                  $this->language->lang('CLI_DESCRIPTION_OPTION_ENV')
 146              ));
 147          }
 148          catch (\LogicException $e)
 149          {
 150              // Do nothing
 151          }
 152      }
 153  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1