Esempio n. 1
0
 /**
  * Initializes the command just after the input has been validated.
  *
  * This is mainly useful when a lot of commands extends one main command
  * where some things need to be initialized based on the input arguments and options.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $dsn = null;
     $user = null;
     $password = null;
     if ($this->input->hasOption('host') && $this->input->getOption('host')) {
         $host = $this->input->getOption('host');
         $port = 3306;
         if ($this->input->getOption('port')) {
             $port = $this->input->getOption('port');
         }
         $dsn = 'mysql:host=' . urlencode($host) . ';port=' . (int) $port;
     }
     if ($this->input->hasOption('user') && $this->input->getOption('user')) {
         $user = $this->input->getOption('user');
     }
     if ($this->input->hasOption('password') && $this->input->getOption('password')) {
         $password = $this->input->getOption('password');
     }
     if ($user !== null || $password !== null) {
         DatabaseConnection::setDsn($dsn, $user, $password);
     }
 }
Esempio n. 2
0
 /**
  * Initializes the command just after the input has been validated.
  *
  * This is mainly useful when a lot of commands extends one main command
  * where some things need to be initialized based on the input arguments and options.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  * @throws \RuntimeException
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     $this->initializeConfiguration();
 }