예제 #1
0
 /**
  * @param IOInterface $io
  * @param CommitMsg   $commitMsg
  *
  * @return CommitMsg
  */
 public static function configure(IOInterface $io, CommitMsg $commitMsg)
 {
     $answer = $io->ask(HookQuestions::COMMIT_MSG_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER);
     $commitMsg = $commitMsg->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
     if (true === $commitMsg->isEnabled()) {
         $regularExpressionAnswer = $io->ask(HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION, HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION_ANSWER);
         $commitMsg = $commitMsg->addRegularExpression(new RegularExpression($regularExpressionAnswer));
     }
     return $commitMsg;
 }
예제 #2
0
 /**
  * @param IOInterface $io
  * @param PhpMd       $phpMd
  *
  * @return PhpMd
  */
 public static function configure(IOInterface $io, PhpMd $phpMd)
 {
     if (true === $phpMd->isUndefined()) {
         $answer = $io->ask(HookQuestions::PHPMD_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER);
         $phpMd = $phpMd->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
         $optionsAnswer = $io->ask(HookQuestions::PHPMD_OPTIONS, null);
         $options = new PhpMdOptions($optionsAnswer);
         $phpMd = $phpMd->setOptions($options);
     }
     return $phpMd;
 }
예제 #3
0
 public static function configure(IOInterface $input, PrePush $prePush)
 {
     $answer = $input->ask(HookQuestions::PRE_PUSH_HOOK_QUESTION, HookQuestions::DEFAULT_TOOL_ANSWER);
     $prePush = $prePush->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
     if (true === $prePush->isEnabled()) {
         $rightMessageAnswer = $input->ask(HookQuestions::PRE_PUSH_RIGHT_MESSAGE, HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT);
         $errorMessageAnswer = $input->ask(HookQuestions::PRE_PUSH_ERROR_MESSAGE, HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT);
         $prePush = $prePush->setMessages(new Messages(new Message($rightMessageAnswer), new Message($errorMessageAnswer)));
     }
     return $prePush;
 }
예제 #4
0
 /**
  * @param IOInterface $io
  * @param PreCommit   $preCommit
  *
  * @return PreCommit
  */
 public static function configure(IOInterface $io, PreCommit $preCommit)
 {
     $answer = $io->ask(HookQuestions::PRE_COMMIT_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER);
     $preCommit = $preCommit->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
     if (true === $preCommit->isEnabled()) {
         $rightMessageAnswer = $io->ask(HookQuestions::PRE_COMMIT_RIGHT_MESSAGE, HookQuestions::PRE_COMMIT_RIGHT_MESSAGE_DEFAULT);
         $errorMessageAnswer = $io->ask(HookQuestions::PRE_COMMIT_ERROR_MESSAGE, HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT);
         $preCommit = $preCommit->setMessages(new Messages(new Message($rightMessageAnswer), new Message($errorMessageAnswer)));
     }
     return $preCommit;
 }
 /**
  * @param IOInterface           $io
  * @param PhpUnitStrictCoverage $strictCoverage
  *
  * @return PhpUnitStrictCoverage
  */
 public static function configure(IOInterface $io, PhpUnitStrictCoverage $strictCoverage)
 {
     if (true === $strictCoverage->isUndefined()) {
         $strictCoverageAnswer = $io->ask(HookQuestions::PHPUNIT_STRICT_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER);
         $strictCoverage = $strictCoverage->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($strictCoverageAnswer)));
         /** @var PhpUnitStrictCoverage $strictCoverage */
         if (true === $strictCoverage->isEnabled()) {
             $minimum = $io->ask(HookQuestions::PHPUNIT_STRICT_COVERAGE_MINIMUM, 0.0);
             $strictCoverage = $strictCoverage->setStrictCoverage(new MinimumStrictCoverage((double) $minimum));
         }
     }
     return $strictCoverage;
 }
예제 #6
0
 /**
  * @param IOInterface $io
  * @param PhpCs       $phpCs
  *
  * @return PhpCs|\Module\Configuration\Model\ToolInterface
  */
 public static function configure(IOInterface $io, PhpCs $phpCs)
 {
     if (true === $phpCs->isUndefined()) {
         $answer = $io->ask(HookQuestions::PHPCS_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER);
         $phpCs = $phpCs->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
         if (true === $phpCs->isEnabled()) {
             $standardAnswer = $io->ask(HookQuestions::PHPCS_STANDARD, null);
             /** @var PhpCs $phpCs */
             $phpCs = $phpCs->addStandard(new PhpCsStandard($standardAnswer));
         }
     }
     return $phpCs;
 }
 /**
  * @param IOInterface $input
  * @param PhpUnitGuardCoverage $phpUnitGuardCoverage
  *
  * @return PhpUnitGuardCoverage
  */
 public function configure(IOInterface $input, PhpUnitGuardCoverage $phpUnitGuardCoverage)
 {
     if (true === $phpUnitGuardCoverage->isUndefined()) {
         $guardCoverageAnswer = $input->ask(HookQuestions::PHPUNIT_GUARD_COVERAGE, HookQuestions::DEFAULT_TOOL_ANSWER);
         $phpUnitGuardCoverage = $phpUnitGuardCoverage->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($guardCoverageAnswer)));
         if (true === $phpUnitGuardCoverage->isEnabled()) {
             $defaultMessage = $input->ask(HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE, HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT);
             /** @var PhpUnitGuardCoverage $phpUnitGuardCoverage */
             $phpUnitGuardCoverage = $phpUnitGuardCoverage->setWarningMessage(new Message($defaultMessage));
             $this->coverageGitIgnoreConfigurator->configure();
         }
     }
     return $phpUnitGuardCoverage;
 }
예제 #8
0
 protected function processParams($params, $actualParams)
 {
     if (!$this->io->isInteractive()) {
         return $actualParams;
     }
     $this->io->write('<comment>Some parameters are missing. Please provide them.</comment>');
     foreach ($params as $key => $value) {
         $result = $this->io->ask(sprintf("<question>%s</question> (<comment>%s</comment>): ", $this->messages[$key], $value));
         if (!empty($result)) {
             $actualParams[$key] = $result;
         }
     }
     return $actualParams;
 }
예제 #9
0
 /**
  * @param IOInterface $io
  * @param PhpCsFixer  $phpCsFixer
  *
  * @return PhpCsFixer
  */
 public static function configure(IOInterface $io, PhpCsFixer $phpCsFixer)
 {
     if (true === $phpCsFixer->isUndefined()) {
         $answer = $io->ask(HookQuestions::PHPCSFIXER_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER);
         $phpCsFixer = $phpCsFixer->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
         if (true === $phpCsFixer->isEnabled()) {
             $psr0Answer = $io->ask(HookQuestions::PHPCSFIXER_PSR0_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER);
             $psr1Answer = $io->ask(HookQuestions::PHPCSFIXER_PSR1_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER);
             $psr2Answer = $io->ask(HookQuestions::PHPCSFIXER_PSR2_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER);
             $symfonyAnswer = $io->ask(HookQuestions::PHPCSFIXER_SYMFONY_LEVEL, HookQuestions::DEFAULT_TOOL_ANSWER);
             $phpCsFixer = $phpCsFixer->addLevels(new PhpCsFixerLevels(new Level(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($psr0Answer)), new Level(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($psr1Answer)), new Level(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($psr2Answer)), new Level(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($symfonyAnswer))));
         }
     }
     return $phpCsFixer;
 }
예제 #10
0
 public function ask($question, array $options)
 {
     $output = [];
     $output[] = sprintf('<question>%s</question>', $question);
     foreach ($options as $selection => $title) {
         $output[] = sprintf('[<comment>%s</comment>] %s', $selection, $title);
     }
     while (1) {
         $answer = $this->io->ask(implode(PHP_EOL, $output) . PHP_EOL);
         if (!array_key_exists($answer, $options)) {
             $this->io->write('<error>Invalid option selected.</error>');
         } else {
             return $answer;
         }
     }
 }
 public static function start(Configuration $configuration, IOInterface $io)
 {
     $params = array();
     $params['database-model'] = $io->ask("> Database model? (MYSQLI) ", "MYSQLI");
     $params['database-host'] = $io->ask("> Database host? (localhost) ", "localhost");
     $params['database-port'] = $io->askAndValidate("> Database port? (3306) ", function ($value) {
         return is_int($value);
     }, 3, 3306);
     $params['database-name'] = $io->ask("> Database name? (comodojo) ", "comodojo");
     $params['database-user'] = $io->ask("> Database user? (comodojo) ", "comodojo");
     $params['database-password'] = $io->askAndHideAnswer("> Database password? ");
     $params['database-prefix'] = $io->ask("> Common prefix for database tables? (cmdj_) ", "cmdj_");
     foreach ($params as $param => $value) {
         $configuration->set($param, $value);
     }
 }
예제 #12
0
 /**
  * Generate database config. will store in: etc/secret.yml.
  *
  * @param IOInterface $io
  *
  * @return  void
  */
 protected static function genSecretConfig(IOInterface $io)
 {
     $etc = __DIR__ . '/../../../etc';
     $secret = Yaml::parse(file_get_contents($etc . '/secret.dist.yml'));
     $driver = 'mysql';
     $host = $io->ask("Database host [localhost]: ", 'localhost');
     $name = $io->ask("Database name [natika]: ", 'natika');
     $user = $io->ask("Database user [root]: ", 'root');
     $pass = $io->askAndHideAnswer("Database password: ");
     $prefix = '';
     $secret['database'] = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $pass, 'name' => $name, 'prefix' => $prefix);
     file_put_contents($etc . '/secret.yml', Yaml::dump($secret, 4));
     $io->write('');
     $io->write('Database config setting complete.');
     $io->write('');
 }
예제 #13
0
 /**
  * Treat params and display Q&A.
  *
  * @param array $expectedKeys
  * @param boolean $isStarted
  * @param string $prefix
  *
  * @since 0.0.3
  */
 private function treatParams(array $expectedKeys, $isStarted = false, $prefix = '')
 {
     $params = [];
     // Iterate on expected keys
     foreach ($expectedKeys as $key => $message) {
         if (is_array($message)) {
             $params[$key] = $this->treatParams($message, $isStarted, $key);
         } else {
             // Display a first message before treating params
             if (!$isStarted) {
                 $isStarted = true;
                 # Write
                 $this->io->write("\n<comment>Some parameters are missing. Please provide them.</comment>");
             }
             // Display prefix when its needed, treat special boolean case
             $p = !empty($prefix) ? $prefix . ' ' : '';
             $m = is_bool($message) && !$message ? '0' : $message;
             # Read
             $value = $this->io->ask(sprintf("<question>%s%s</question> (<comment>%s</comment>): ", $p, $key, $m), $message);
             $value = is_bool($message) ? (bool) $value : (is_int($message) ? (int) $value : $value);
             // Special case: 'debug'
             if ('debug' === $key && $value) {
                 $params[$key] = $this->treatParams(['savequeries' => true, 'script_debug' => true, 'wp_debug_display' => true, 'wp_debug' => true], false, $key);
             } else {
                 $params[$key] = $value;
             }
         }
     }
     return $params;
 }
예제 #14
0
 /**
  * @param IOInterface $io
  * @param PhpUnit     $phpUnit
  *
  * @return PhpUnit
  */
 public static function configure(IOInterface $io, PhpUnit $phpUnit)
 {
     /** @var PhpUnit $phpUnit */
     if (true === $phpUnit->isUndefined()) {
         $answer = $io->ask(HookQuestions::PHPUNIT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER);
         $phpUnit = $phpUnit->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
         if (true === $phpUnit->isEnabled()) {
             $randomAnswer = $io->ask(HookQuestions::PHPUNIT_RANDOM_MODE, HookQuestions::DEFAULT_TOOL_ANSWER);
             $optionsAnswer = $io->ask(HookQuestions::PHPUNIT_OPTIONS, null);
             $randomMode = new PhpUnitRandomMode(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($randomAnswer));
             $options = new PhpUnitOptions($optionsAnswer);
             $phpUnit = $phpUnit->setRandomModeAndOptions($randomMode, $options);
         }
     }
     return $phpUnit;
 }
예제 #15
0
 /**
  * @param IOInterface $io
  * @param PhpLint     $phpLint
  *
  * @return PhpLint
  */
 public static function configure(IOInterface $io, PhpLint $phpLint)
 {
     if (true === $phpLint->isUndefined()) {
         $answer = $io->ask(HookQuestions::PHPLINT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER);
         $phpLint = $phpLint->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
     }
     return $phpLint;
 }
예제 #16
0
 /**
  * @param IOInterface $io
  * @param Composer    $composer
  *
  * @return Composer
  */
 public static function configure(IOInterface $io, Composer $composer)
 {
     if (true === $composer->isUndefined()) {
         $answer = $io->ask(HookQuestions::COMPOSER_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER);
         $composer = $composer->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer)));
     }
     return $composer;
 }
예제 #17
0
 /**
  * Repositories requests credentials, let's put them in.
  *
  * @return \Composer\Util\Svn
  */
 protected function doAuthDance()
 {
     $this->io->write("The Subversion server ({$this->url}) requested credentials:");
     $this->hasAuth = true;
     $this->credentials['username'] = $this->io->ask("Username: "******"Password: "******"Should Subversion cache these credentials? (yes/no) ", true);
     return $this;
 }
예제 #18
0
 /**
  * Check if the `.bash_profile` root dir exists. Prompt for a new one if it does not exist.
  * @param IOInterface $io
  * @param string      $dir
  * @return mixed
  */
 public static function getDir(IOInterface $io, $dir)
 {
     if (!is_dir($dir)) {
         $io->write(sprintf('<info>The `.bash_profile` specified location specified in the composer.json file: %s does not exist.</info>', $dir));
         $dir = $io->ask('<info>Please provide the root directory for your `.bash_profile` file:</info> ', $dir);
         return self::getDir($io, $dir);
     }
     return $dir;
 }
예제 #19
0
 /**
  * @param IOInterface $io
  * @param string      $question
  * @param mixed       $default
  * @return string
  */
 public function ask(IOInterface $io, $question, $default = null)
 {
     $question = $this->getDecoratedMessage($question, 'question', $io->isDecorated()) . ' ';
     if ($default !== null) {
         $question .= '(' . $this->getDecoratedMessage($default, 'comment', $io->isDecorated()) . ')';
     }
     $question .= ': ';
     return $io->ask($question, $default);
 }
예제 #20
0
 /**
  * Get a patch-data
  *
  * @param   string          $section
  * @param   string          $key
  * @param   string          $ask
  * @param   string          $default
  * @param   string|callable $validator
  * @param   int|false       $attempts
  * @param   bool            $throwIfEmpty
  * @return  string
  * @throws  Exception\DomainException
  */
 public function get($section, $key, $ask = null, $default = null, $validator = null, $attempts = 3, $throwIfEmpty = true)
 {
     if (!empty($this->data[$section][$key])) {
         return $this->data[$section][$key];
     }
     if (!$this->io->isInteractive() || empty($ask)) {
         $result = $default;
     } else {
         $question = (string) $ask;
         if (null !== $default) {
             $question .= ' (default: <info>' . $default . '</info>)';
         }
         $ask = static::PADDING . $question . ': ';
         $hidden = false;
         if (true === $validator) {
             $hidden = true;
             $validator = null;
         }
         if (is_string($validator) && !function_exists($validator)) {
             $pattern = (string) $validator;
             $validator = function ($value) use($pattern) {
                 $matches = array();
                 if (!preg_match($pattern, $value, $matches)) {
                     throw new LogicException(sprintf('"%s" does not match "%s"', $value, $pattern));
                 }
                 return $matches[0];
             };
         }
         if (is_array($validator) && (count($validator) != 2 || !function_exists($validator))) {
             $values = (array) $validator;
             $validator = function ($value) use($values) {
                 if (!in_array($value, $values)) {
                     throw new LogicException(sprintf('"%s" is not available, only "%s" accepted', $value, implode('", "', $values)));
                 }
                 return $value;
             };
         }
         if (is_callable($validator)) {
             $result = $this->io->askAndValidate($ask, $validator, $attempts, $default);
         } else {
             if ($hidden) {
                 $result = $this->io->askAndHideAnswer($ask) ?: $default;
             } else {
                 $result = $this->io->ask($ask, $default);
             }
         }
     }
     if (empty($result)) {
         if ($throwIfEmpty) {
             throw new Exception\DomainException(sprintf('%s: patch-data "%s": "%s", asked as "%s" should not be empty', __METHOD__, $section, $key, $ask));
         }
     } else {
         $this->data[$section][$key] = $result;
     }
     return $result;
 }
예제 #21
0
 /**
  * Generate database config. will store in: etc/secret.yml.
  *
  * @param IOInterface $io
  *
  * @return  void
  */
 protected static function genSecretConfig(IOInterface $io)
 {
     $etc = __DIR__ . '/../../../etc';
     $secret = Yaml::parse(file_get_contents($etc . '/secret.dist.yml'));
     if ($io->askConfirmation("\nDo you want to use database? [Y/n]: ", true)) {
         $io->write('');
         $io->write('Database driver only support mysql/postgresql now.');
         $driver = $io->ask("Database driver [mysql]: ", 'mysql');
         $host = $io->ask("Database host [localhost]: ", 'localhost');
         $name = $io->ask("Database name [acme]: ", 'acme');
         $user = $io->ask("Database user [root]: ", 'root');
         $pass = $io->askAndHideAnswer("Database password: "******"Table prefix [wind_]: ", 'wind_');
         $secret['database'] = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $pass, 'name' => $name, 'prefix' => $prefix);
     }
     file_put_contents($etc . '/secret.yml', Yaml::dump($secret, 4));
     $io->write('');
     $io->write('Database config setting complete.');
     $io->write('');
 }
예제 #22
0
 /**
  * Repositories requests credentials, let's put them in.
  *
  * @throws \RuntimeException
  * @return \Composer\Util\Svn
  */
 protected function doAuthDance()
 {
     // cannot ask for credentials in non interactive mode
     if (!$this->io->isInteractive()) {
         throw new \RuntimeException('can not ask for authentication in non interactive mode');
     }
     $this->io->writeError("The Subversion server ({$this->url}) requested credentials:");
     $this->hasAuth = true;
     $this->credentials['username'] = $this->io->ask("Username: "******"Password: "******"Should Subversion cache these credentials? (yes/no) ", true);
     return $this;
 }
예제 #23
0
    public function activate(Composer $composer, IOInterface $io)
    {
        echo <<<TEXT

                  ,-.-.,---.,--.         ,---.
                  | | ||   ||   |.  ,    |---',---..    ,,---.
                  | | ||   ||   | ><     |  \\ |---' \\  / |   |
                  ` ' '`---'`--' '  `    `   ``---'  `'  `---'


                   o          |         |    |
                   .,---.,---.|--- ,---.|    |    ,---.,---.
                   ||   |`---.|    ,---||    |    |---'|
                   ``   '`---'`---'`---^`---'`---'`---'`


TEXT;
        echo "\nBefore we begin, please specify database config data.\n";
        $db_name = $io->ask('Database name (may not exist): ');
        $db_user = $io->ask('Database user: '******'Database password: '******'.env', "DB_NAME={$db_name}" . "\n" . "DB_USER={$db_user}" . "\n" . "DB_PASS={$db_password}" . "\n");
    }
예제 #24
0
 public static function initMagentoRootDir(ProjectConfig $projectConfig, \Composer\IO\IOInterface $io, \Composer\Util\Filesystem $filesystem, $vendorDir)
 {
     if (false === $projectConfig->hasMagentoRootDir()) {
         $projectConfig->setMagentoRootDir($io->ask(sprintf('please define your magento root dir [%s]', ProjectConfig::DEFAULT_MAGENTO_ROOT_DIR), ProjectConfig::DEFAULT_MAGENTO_ROOT_DIR));
     }
     $magentoRootDirPath = $projectConfig->getMagentoRootDir();
     $magentoRootDir = new \SplFileInfo($magentoRootDirPath);
     if (!is_dir($magentoRootDirPath) && $io->askConfirmation('magento root dir "' . $magentoRootDirPath . '" missing! create now? [Y,n] ')) {
         $filesystem->ensureDirectoryExists($magentoRootDir);
         $io->write('magento root dir "' . $magentoRootDirPath . '" created');
     }
     if (!is_dir($magentoRootDirPath)) {
         $dir = self::joinFilePath($vendorDir, $magentoRootDirPath);
     }
 }
 /**
  * Prompt the user to determine if the selection should be remembered for later packages.
  *
  * @todo Will need to store selection in filesystem and remove when all packages are complete
  * @param Injector\InjectorInterface $injector
  * @param int[] $packageTypes
  * return void
  */
 private function promptToRememberOption(Injector\InjectorInterface $injector, array $packageTypes)
 {
     $ask = ["\n  <question>Remember this option for other packages of the same type? (y/N)</question>"];
     while (true) {
         $answer = strtolower($this->io->ask($ask, 'n'));
         switch ($answer) {
             case 'y':
                 $this->cacheInjector($injector);
                 return;
             case 'n':
                 // intentionaly fall-through
             // intentionaly fall-through
             default:
                 return;
         }
     }
 }
 /**
  * Create the callback for emitting and handling a package prompt.
  *
  * @param OptionalPackage $package
  * @return bool
  */
 private function promptForPackage(OptionalPackage $package)
 {
     $question = [sprintf("\n    <question>%s</question> <comment>y/N</comment>\n", $package->getPrompt())];
     while (true) {
         $answer = $this->io->ask($question, 'n');
         $answer = strtolower($answer);
         if ('n' === $answer) {
             return false;
         }
         if ('y' === $answer) {
             $this->io->write(sprintf('<info>    Will install %s (%s)</info>', $package->getName(), $package->getConstraint()));
             if ($package->isModule()) {
                 $extra = $package->isDev() ? $this->packageConfigPrompts['require-dev'] : $this->packageConfigPrompts['require'];
                 $this->io->write($extra);
             }
             return true;
         }
         $this->io->write('<error>Invalid answer</error>');
     }
 }
 /**
  * Ask if the user would like a minimal install.
  *
  * @param IOInterface $io
  * @return bool
  */
 private static function requestMinimal(IOInterface $io)
 {
     $query = [sprintf("\n  <question>%s</question>\n", 'Minimal skeleton? (no default middleware, templates, or assets; configuration only)'), "  [<comment>y</comment>] Yes (minimal)\n", "  [<comment>n</comment>] No (full; recommended)\n", "  Make your selection <comment>(No)</comment>: "];
     $answer = $io->ask($query, 'n');
     if ($answer == 'n') {
         // Nothing else to do!
         return false;
     }
     return true;
 }
예제 #28
0
 public function runCommand($commandCallable, $url, $cwd, $initialClone = false)
 {
     if (preg_match('{^(http|git):}i', $url) && $this->config->get('secure-http')) {
         throw new TransportException("Your configuration does not allow connection to {$url}. See https://getcomposer.org/doc/06-config.md#secure-http for details.");
     }
     if ($initialClone) {
         $origCwd = $cwd;
         $cwd = null;
     }
     if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $url)) {
         throw new \InvalidArgumentException('The source URL ' . $url . ' is invalid, ssh URLs should have a port number after ":".' . "\n" . 'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.');
     }
     if (!$initialClone) {
         // capture username/password from URL if there is one
         $this->process->execute('git remote -v', $output, $cwd);
         if (preg_match('{^(?:composer|origin)\\s+https?://(.+):(.+)@([^/]+)}im', $output, $match)) {
             $this->io->setAuthentication($match[3], urldecode($match[1]), urldecode($match[2]));
         }
     }
     $protocols = $this->config->get('github-protocols');
     if (!is_array($protocols)) {
         throw new \RuntimeException('Config value "github-protocols" must be an array, got ' . gettype($protocols));
     }
     // public github, autoswitch protocols
     if (preg_match('{^(?:https?|git)://' . self::getGitHubDomainsRegex($this->config) . '/(.*)}', $url, $match)) {
         $messages = array();
         foreach ($protocols as $protocol) {
             if ('ssh' === $protocol) {
                 $protoUrl = "git@" . $match[1] . ":" . $match[2];
             } else {
                 $protoUrl = $protocol . "://" . $match[1] . "/" . $match[2];
             }
             if (0 === $this->process->execute(call_user_func($commandCallable, $protoUrl), $ignoredOutput, $cwd)) {
                 return;
             }
             $messages[] = '- ' . $protoUrl . "\n" . preg_replace('#^#m', '  ', $this->process->getErrorOutput());
             if ($initialClone) {
                 $this->filesystem->removeDirectory($origCwd);
             }
         }
         // failed to checkout, first check git accessibility
         $this->throwException('Failed to clone ' . self::sanitizeUrl($url) . ' via ' . implode(', ', $protocols) . ' protocols, aborting.' . "\n\n" . implode("\n", $messages), $url);
     }
     // if we have a private github url and the ssh protocol is disabled then we skip it and directly fallback to https
     $bypassSshForGitHub = preg_match('{^git@' . self::getGitHubDomainsRegex($this->config) . ':(.+?)\\.git$}i', $url) && !in_array('ssh', $protocols, true);
     $command = call_user_func($commandCallable, $url);
     $auth = null;
     if ($bypassSshForGitHub || 0 !== $this->process->execute($command, $ignoredOutput, $cwd)) {
         // private github repository without git access, try https with auth
         if (preg_match('{^git@' . self::getGitHubDomainsRegex($this->config) . ':(.+?)\\.git$}i', $url, $match)) {
             if (!$this->io->hasAuthentication($match[1])) {
                 $gitHubUtil = new GitHub($this->io, $this->config, $this->process);
                 $message = 'Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos';
                 if (!$gitHubUtil->authorizeOAuth($match[1]) && $this->io->isInteractive()) {
                     $gitHubUtil->authorizeOAuthInteractively($match[1], $message);
                 }
             }
             if ($this->io->hasAuthentication($match[1])) {
                 $auth = $this->io->getAuthentication($match[1]);
                 $authUrl = 'https://' . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[1] . '/' . $match[2] . '.git';
                 $command = call_user_func($commandCallable, $authUrl);
                 if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) {
                     return;
                 }
             }
         } elseif ($this->isAuthenticationFailure($url, $match)) {
             // private non-github repo that failed to authenticate
             if (strpos($match[2], '@')) {
                 list($authParts, $match[2]) = explode('@', $match[2], 2);
             }
             $storeAuth = false;
             if ($this->io->hasAuthentication($match[2])) {
                 $auth = $this->io->getAuthentication($match[2]);
             } elseif ($this->io->isInteractive()) {
                 $defaultUsername = null;
                 if (isset($authParts) && $authParts) {
                     if (false !== strpos($authParts, ':')) {
                         list($defaultUsername, ) = explode(':', $authParts, 2);
                     } else {
                         $defaultUsername = $authParts;
                     }
                 }
                 $this->io->writeError('    Authentication required (<info>' . parse_url($url, PHP_URL_HOST) . '</info>):');
                 $auth = array('username' => $this->io->ask('      Username: '******'password' => $this->io->askAndHideAnswer('      Password: '******'store-auths');
             }
             if ($auth) {
                 $authUrl = $match[1] . rawurlencode($auth['username']) . ':' . rawurlencode($auth['password']) . '@' . $match[2] . $match[3];
                 $command = call_user_func($commandCallable, $authUrl);
                 if (0 === $this->process->execute($command, $ignoredOutput, $cwd)) {
                     $this->io->setAuthentication($match[2], $auth['username'], $auth['password']);
                     $authHelper = new AuthHelper($this->io, $this->config);
                     $authHelper->storeAuth($match[2], $storeAuth);
                     return;
                 }
             }
         }
         if ($initialClone) {
             $this->filesystem->removeDirectory($origCwd);
         }
         $this->throwException('Failed to execute ' . self::sanitizeUrl($command) . "\n\n" . $this->process->getErrorOutput(), $url);
     }
 }
예제 #29
0
 /**
  * generateDatabase
  * Execute TickiSql for application
  * @param string $dir The application's root directory.
  * @param \Composer\IO\IOInterface $io IO interface to write to console.
  * @return void
  */
 public static function generateDatabase($rootDir, $io)
 {
     $installDatabase = $io->ask('Install Ticki database automatically ? </info> [<comment>Y,n</comment>]? ', 'Y', 'Y');
     if ($installDatabase !== 'N' || $installDatabase !== 'n') {
         $TickiConfig = $rootDir . '/config/schema/Ticki.sql';
         $content = file_get_contents($TickiConfig);
         $content = str_replace('_DATABASE_', static::$_databaseName, $content);
         $result = file_put_contents($TickiConfig, $content);
         if (!$result) {
             $io->write('Unable to update Database value on sql file.');
             return;
         }
         $mysqli = null;
         if (static::$_port) {
             $mysqli = new Mysqli(static::$_hostName, static::$_userName, static::$_password, "", static::$_port);
         } else {
             $mysqli = new Mysqli(static::$_hostName, static::$_userName, static::$_password);
         }
         if ($mysqli->connect_errno) {
             $io->write("<error>Connection fail : " . $mysqli->connect_error . '</error>');
             return;
         }
         if (!$mysqli->multi_query($content)) {
             $io->write('<error>Unable to install database, do it manually please</error>');
         }
         $mysqli->close();
         $io->write('<info>Set up database Ticki is a success.</info>');
     }
 }
예제 #30
0
 /**
  * Set the datasources.default.database value in the application's config file.
  *
  * @param string $dir The application's root directory.
  * @param \Composer\IO\IOInterface $io IO interface to write to console.
  *
  * @return void
  */
 public static function setDatabaseName($dir, $io)
 {
     $config = $dir . '/config/app.php';
     $content = file_get_contents($config);
     $databaseName = $io->ask('What is your new database name ? ', 'xeta');
     $content = str_replace('__DATABASE__', $databaseName, $content, $count);
     if ($count == 0) {
         $io->write('No Datasources.default.database placeholder to replace.');
         return;
     }
     $result = file_put_contents($config, $content);
     if ($result) {
         $io->write('Updated Datasources.default.database value in config/app.php');
         return;
     }
     $io->write('Unable to update Datasources.default.database value.');
 }