[ Index ]

PHP Cross Reference of phpBB-3.1.12-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\Shell;
  17  use Symfony\Component\Console\Input\InputInterface;
  18  use Symfony\Component\Console\Input\InputOption;
  19  use Symfony\Component\Console\Output\OutputInterface;
  20  
  21  class application extends \Symfony\Component\Console\Application
  22  {
  23      /**
  24      * @var bool Indicates whether or not we are in a shell
  25      */
  26      protected $in_shell = false;
  27  
  28      /**
  29      * @var \phpbb\user User object
  30      */
  31      protected $user;
  32  
  33      /**
  34      * @param string            $name        The name of the application
  35      * @param string            $version    The version of the application
  36      * @param \phpbb\user    $user        The user which runs the application (used for translation)
  37      */
  38  	public function __construct($name, $version, \phpbb\user $user)
  39      {
  40          $this->user = $user;
  41  
  42          parent::__construct($name, $version);
  43      }
  44  
  45      /**
  46      * {@inheritdoc}
  47      */
  48  	protected function getDefaultInputDefinition()
  49      {
  50          $input_definition = parent::getDefaultInputDefinition();
  51  
  52          $input_definition->addOption(new InputOption(
  53              'safe-mode',
  54              null,
  55              InputOption::VALUE_NONE,
  56              $this->user->lang('CLI_DESCRIPTION_OPTION_SAFE_MODE')
  57          ));
  58  
  59          return $input_definition;
  60      }
  61  
  62      /**
  63      * Gets the help message.
  64      *
  65      * It's a hack of the default help message to display the --shell
  66      * option only for the application and not for all the commands.
  67      *
  68      * @return string A help message.
  69      */
  70  	public function getHelp()
  71      {
  72          // If we are already in a shell
  73          // we do not want to have the --shell option available
  74          if ($this->in_shell)
  75          {
  76              return parent::getHelp();
  77          }
  78  
  79          $this->getDefinition()->addOption(new InputOption(
  80              '--shell',
  81              '-s',
  82              InputOption::VALUE_NONE,
  83              $this->user->lang('CLI_DESCRIPTION_OPTION_SHELL')
  84          ));
  85  
  86          return parent::getHelp();
  87      }
  88  
  89      /**
  90      * Register a set of commands from the container
  91      *
  92      * @param \phpbb\di\service_collection    $command_collection    The console service collection
  93      */
  94  	public function register_container_commands(\phpbb\di\service_collection $command_collection)
  95      {
  96          foreach ($command_collection as $service_command)
  97          {
  98              $this->add($service_command);
  99          }
 100      }
 101  
 102      /**
 103      * {@inheritdoc}
 104      */
 105  	public function doRun(InputInterface $input, OutputInterface $output)
 106      {
 107          // Run a shell if the --shell (or -s) option is set and if no command name is specified
 108          // Also, we do not want to have the --shell option available if we are already in a shell
 109          if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s')))
 110          {
 111              $shell = new Shell($this);
 112              $this->in_shell = true;
 113              $shell->run();
 114  
 115              return 0;
 116          }
 117  
 118          return parent::doRun($input, $output);
 119      }
 120  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1