Beispiel #1
0
 /**
  * @return void
  */
 public function execute()
 {
     $this->notEmptyCallback = function ($input) {
         if (empty($input)) {
             throw new \InvalidArgumentException('Please enter a value');
         }
         return $input;
     };
     $dbOptions = array('--dbHost', '--dbUser', '--dbPass', '--dbName');
     $dbOptionsFound = 0;
     foreach ($dbOptions as $dbOption) {
         foreach ($this->getCliArguments() as $definedCliOption) {
             if (BinaryString::startsWith($definedCliOption, $dbOption)) {
                 $dbOptionsFound++;
             }
         }
     }
     $hasAllOptions = $dbOptionsFound == 4;
     // if all database options were passed in at cmd line
     if ($hasAllOptions) {
         $this->config->setString('db_host', $this->input->getOption('dbHost'));
         $this->config->setString('db_user', $this->input->getOption('dbUser'));
         $this->config->setString('db_pass', $this->input->getOption('dbPass'));
         $this->config->setString('db_name', $this->input->getOption('dbName'));
         $this->config->setInt('db_port', intval($this->input->getOption('dbPort')));
         $db = $this->validateDatabaseSettings($this->input, $this->output);
         if ($db === false) {
             throw new \InvalidArgumentException("Database configuration is invalid", null);
         }
     } else {
         $dialog = $this->getCommand()->getHelperSet()->get('dialog');
         do {
             // Host
             $dbHostDefault = $this->input->getOption('dbHost') ? $this->input->getOption('dbHost') : 'localhost';
             $this->config->setString('db_host', $dialog->askAndValidate($this->output, '<question>Please enter the database host</question> <comment>[' . $dbHostDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbHostDefault));
             // Port
             $dbPortDefault = $this->input->getOption('dbPort') ? $this->input->getOption('dbPort') : 3306;
             $this->config->setInt('db_port', intval($dialog->askAndValidate($this->output, '<question>Please enter the database port </question> <comment>[' . $dbPortDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbPortDefault)));
             // User
             $dbUserDefault = $this->input->getOption('dbUser') ? $this->input->getOption('dbUser') : 'root';
             $this->config->setString('db_user', $dialog->askAndValidate($this->output, '<question>Please enter the database username</question> <comment>[' . $dbUserDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbUserDefault));
             // Password
             $dbPassDefault = $this->input->getOption('dbPass') ? $this->input->getOption('dbPass') : '';
             $this->config->setString('db_pass', $dialog->ask($this->output, '<question>Please enter the database password</question> <comment>[' . $dbPassDefault . ']</comment>: ', $dbPassDefault));
             // DB-Name
             $dbNameDefault = $this->input->getOption('dbName') ? $this->input->getOption('dbName') : 'magento';
             $this->config->setString('db_name', $dialog->askAndValidate($this->output, '<question>Please enter the database name</question> <comment>[' . $dbNameDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbNameDefault));
             $db = $this->validateDatabaseSettings($this->input, $this->output);
         } while ($db === false);
     }
     $this->config->setObject('db', $db);
 }
 /**
  * Returns the composer config key -> Composer passed json data
  *
  * @param string $key
  * @param bool $useGlobalConfig
  * @return string|object
  */
 public function getConfigValue($key, $useGlobalConfig = true)
 {
     $jsonCode = '';
     $commandArgs = [];
     if ($useGlobalConfig) {
         $commandArgs[] = 'global';
     }
     $commandArgs[] = 'config';
     $commandArgs[] = $key;
     try {
         $composerOutput = $this->run($commandArgs, true);
         $lines = explode(PHP_EOL, $composerOutput);
         foreach ($lines as $line) {
             if (BinaryString::startsWith($line, 'Changed current directory to')) {
                 continue;
             }
             $jsonCode .= $line;
         }
     } catch (\Exception $e) {
         $jsonCode = 'false';
     }
     return json_decode($jsonCode);
 }
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (BinaryString::startsWith($file->getPathname(), 'vfs://')) {
         $path = $file->getPathname();
     } else {
         $path = $file->getRealPath();
         if ($path === "") {
             throw new \UnexpectedValueException(sprintf("Realpath for '%s' did return an empty string.", $file));
         }
         if ($path === false) {
             $this->log(sprintf("<error>Plugin config file broken link '%s'</error>", $file));
             return;
         }
     }
     $this->logDebug('Load plugin config <comment>' . $path . '</comment>');
     $localPluginConfigFile = ConfigFile::createFromFile($path);
     $localPluginConfigFile->applyVariables($magentoRootFolder, $file);
     $this->_pluginConfig = $localPluginConfigFile->mergeArray($this->_pluginConfig);
 }
Beispiel #4
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws InvalidArgumentException
  */
 protected function createDatabase(InputInterface $input, OutputInterface $output)
 {
     $dbOptions = array('--dbHost', '--dbUser', '--dbPass', '--dbName');
     $dbOptionsFound = 0;
     foreach ($dbOptions as $dbOption) {
         foreach ($this->getCliArguments() as $definedCliOption) {
             if (BinaryString::startsWith($definedCliOption, $dbOption)) {
                 $dbOptionsFound++;
             }
         }
     }
     $hasAllOptions = $dbOptionsFound == 4;
     // if all database options were passed in at cmd line
     if ($hasAllOptions) {
         $this->config['db_host'] = $input->getOption('dbHost');
         $this->config['db_user'] = $input->getOption('dbUser');
         $this->config['db_pass'] = $input->getOption('dbPass');
         $this->config['db_name'] = $input->getOption('dbName');
         $this->config['db_port'] = $input->getOption('dbPort');
         $this->config['db_prefix'] = $input->getOption('dbPrefix');
         $db = $this->validateDatabaseSettings($output, $input);
         if ($db === false) {
             throw new InvalidArgumentException("Database configuration is invalid");
         }
     } else {
         $dialog = $this->getHelperSet()->get('dialog');
         do {
             $dbHostDefault = $input->getOption('dbHost') ? $input->getOption('dbHost') : 'localhost';
             $this->config['db_host'] = $dialog->askAndValidate($output, '<question>Please enter the database host</question> <comment>[' . $dbHostDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbHostDefault);
             $dbUserDefault = $input->getOption('dbUser') ? $input->getOption('dbUser') : 'root';
             $this->config['db_user'] = $dialog->askAndValidate($output, '<question>Please enter the database username</question> <comment>[' . $dbUserDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbUserDefault);
             $dbPassDefault = $input->getOption('dbPass') ? $input->getOption('dbPass') : '';
             $this->config['db_pass'] = $dialog->ask($output, '<question>Please enter the database password</question> <comment>[' . $dbPassDefault . ']</comment>: ', $dbPassDefault);
             $dbNameDefault = $input->getOption('dbName') ? $input->getOption('dbName') : 'magento';
             $this->config['db_name'] = $dialog->askAndValidate($output, '<question>Please enter the database name</question> <comment>[' . $dbNameDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbNameDefault);
             $dbPortDefault = $input->getOption('dbPort') ? $input->getOption('dbPort') : 3306;
             $this->config['db_port'] = $dialog->askAndValidate($output, '<question>Please enter the database port </question> <comment>[' . $dbPortDefault . ']</comment>: ', $this->notEmptyCallback, false, $dbPortDefault);
             $dbPrefixDefault = $input->getOption('dbPrefix') ? $input->getOption('dbPrefix') : '';
             $this->config['db_prefix'] = $dialog->ask($output, '<question>Please enter the table prefix</question> <comment>[' . $dbPrefixDefault . ']</comment>:', $dbPrefixDefault);
             $db = $this->validateDatabaseSettings($output, $input);
         } while ($db === false);
     }
     $this->config['db'] = $db;
 }
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string       $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (BinaryString::startsWith($file->getPathname(), 'vfs://')) {
         $path = $file->getPathname();
     } else {
         $path = $file->getRealPath();
         if ($path === "") {
             throw new \UnexpectedValueException(sprintf("Realpath for '%s' did return an empty string.", $file));
         }
         if ($path === false) {
             $this->_output->writeln(sprintf("<error>Plugin config file broken link '%s'</error>", $file));
             return;
         }
     }
     if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) {
         $this->_output->writeln('<debug>Load plugin config <comment>' . $path . '</comment></debug>');
     }
     $localPluginConfig = \file_get_contents($path);
     $localPluginConfig = Yaml::parse($this->applyVariables($localPluginConfig, $magentoRootFolder, $file));
     $this->_pluginConfig = ArrayFunctions::mergeArrays($this->_pluginConfig, $localPluginConfig);
 }