本文整理汇总了PHP中Composer\IO\IOInterface::askConfirmation方法的典型用法代码示例。如果您正苦于以下问题:PHP IOInterface::askConfirmation方法的具体用法?PHP IOInterface::askConfirmation怎么用?PHP IOInterface::askConfirmation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\IO\IOInterface
的用法示例。
在下文中一共展示了IOInterface::askConfirmation方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doAuthDance
/**
* 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: ");
$this->credentials['password'] = $this->io->askAndHideAnswer("Password: ");
$this->cacheCredentials = $this->io->askConfirmation("Should Subversion cache these credentials? (yes/no) ", true);
return $this;
}
示例2: doAuthDance
/**
* 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: ");
$this->credentials['password'] = $this->io->askAndHideAnswer("Password: ");
$this->cacheCredentials = $this->io->askConfirmation("Should Subversion cache these credentials? (yes/no) ", true);
return $this;
}
示例3: initMagentoRootDir
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);
}
}
示例4: handleCommit
private function handleCommit()
{
if ($this->outputter->isEmpty()) {
return;
}
switch ($this->config->getCommitAuto()) {
case 'never':
return;
case 'ask':
if ($this->io->askConfirmation('<info>Would you like to commit the update? </info>[<comment>no</comment>]: ', false)) {
$this->doCommit();
}
break;
case 'always':
$this->doCommit();
}
}
示例5: genSecretConfig
/**
* 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: ");
$prefix = $io->ask("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('');
}
示例6: ask
/**
* Get an array of question lines and a default response and use them to format and ask a
* question to console.
*
* @param array $lines
* @param bool $default
* @return bool
*/
public function ask(array $lines, $default = true)
{
if ($this->verbosity < 1) {
return $default;
}
array_unshift($lines, 'QUESTION');
$length = max(array_map('strlen', $lines));
array_walk($lines, function (&$line) use($length) {
$len = strlen($line);
if ($len < $length) {
$line = $line . str_repeat(' ', $length - $len);
}
$line = " {$line} ";
});
$space = str_repeat(' ', $length + 4);
array_unshift($lines, ' <question>' . $space);
array_push($lines, $space . '</question>');
$question = PHP_EOL . implode('</question>' . PHP_EOL . ' <question>', $lines);
$prompt = PHP_EOL . ' <option=bold>Y</option=bold> or <option=bold>N</option=bold> ';
$prompt .= $default ? '[Y]' : '[N]';
return $this->io->askConfirmation($question . PHP_EOL . $prompt, $default);
}
示例7: askConfirmation
/**
* @param IOInterface $io
* @param string $question
* @param bool $default
* @return bool
*/
public function askConfirmation(IOInterface $io, $question, $default = true)
{
$question = $this->getDecoratedMessage($question, 'question', $io->isDecorated()) . ' ';
$question .= '(Y/n): ';
return $io->askConfirmation($question, $default);
}
示例8: getPackagesInteractively
private function getPackagesInteractively(IOInterface $io, InputInterface $input, OutputInterface $output, Composer $composer, array $packages)
{
if (!$input->isInteractive()) {
throw new \InvalidArgumentException('--interactive cannot be used in non-interactive terminals.');
}
$requires = array_merge($composer->getPackage()->getRequires(), $composer->getPackage()->getDevRequires());
$autocompleterValues = array();
foreach ($requires as $require) {
$autocompleterValues[strtolower($require->getTarget())] = $require->getTarget();
}
$installedPackages = $composer->getRepositoryManager()->getLocalRepository()->getPackages();
foreach ($installedPackages as $package) {
$autocompleterValues[$package->getName()] = $package->getPrettyName();
}
$helper = $this->getHelper('question');
$question = new Question('<comment>Enter package name: </comment>', null);
$io->writeError('<info>Press enter without value to end submission</info>');
do {
$autocompleterValues = array_diff($autocompleterValues, $packages);
$question->setAutocompleterValues($autocompleterValues);
$addedPackage = $helper->ask($input, $output, $question);
if (!is_string($addedPackage) || empty($addedPackage)) {
break;
}
$addedPackage = strtolower($addedPackage);
if (!in_array($addedPackage, $packages)) {
$packages[] = $addedPackage;
}
} while (true);
$packages = array_filter($packages);
if (!$packages) {
throw new \InvalidArgumentException('You must enter minimum one package.');
}
$table = new Table($output);
$table->setHeaders(array('Selected packages'));
foreach ($packages as $package) {
$table->addRow(array($package));
}
$table->render();
if ($io->askConfirmation(sprintf('Would you like to continue and update the above package%s [<comment>yes</comment>]? ', 1 === count($packages) ? '' : 's'), true)) {
return $packages;
}
throw new \RuntimeException('Installation aborted.');
}
示例9: createDatabase
/**
* Create the database schema if needed
*
* @param IOInterface $io Composer's IO interface
* @param string $host The database host
* @param string $username The username for the MySQL user
* @param string $password The password for the MySQL user
* @param string $database The name of the database
*/
private static function createDatabase(IOInterface $io, $host, $username, $password, $database)
{
$io->write(" Connecting to MySQL database {$database}@{$host}");
$dsn = 'mysql:host=' . $host . ';charset=UTF8';
$pdo = new \PDO($dsn, $username, $password);
$statement = $pdo->prepare("USE `{$database}`");
$status = $statement->execute();
$errors = $statement->errorInfo();
// Throw an exception on error for any query that will be sent next
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
// 1049 is the error code thrown when the database doesn't exist, but
// the MySQL user has the privilege to see it
if ($errors[1] == 1049) {
$answer = $io->askConfirmation(" <fg=green>The {$database} database doesn't exist. Would you like to have it created? (yes/no)</> [<comment>yes</comment>]\n > ", true);
if ($answer) {
$pdo->query("CREATE DATABASE `{$database}` COLLATE utf8_unicode_ci");
$pdo->query("USE `{$database}`");
$io->write(" <fg=green>New database created</>");
} else {
return false;
}
} elseif (!$status) {
throw new \Exception("Unable to connect to database: " . $errors[2]);
}
// If the database is empty, fill it
if ($pdo->query('SHOW TABLES')->rowCount() === 0) {
$io->write(" <fg=green>Creating database schema...</> ", false);
$sqlPath = realpath(__DIR__ . '/../../migrations/' . 'DATABASE.sql');
$pdo->exec(file_get_contents($sqlPath));
$io->write("<fg=green>done.</>");
}
return true;
}
示例10: verifyGitignore
/**
* Merges the dist gitignore to the project’s one
*
* @param IOInterface $io
* @param string $destination Absolute path to target .gitignore
*/
private static function verifyGitignore(IOInterface $io, $destination)
{
$source = dirname(dirname(__DIR__)) . '/dist/gitignore';
if (is_file($destination)) {
// do not consider commented or empty lines
$parseLines = function ($file) {
$lines = file($file);
$lines = array_filter($lines, function ($line) {
return !preg_match('/^(#|\\s*$)/', $line);
});
$lines = array_map('trim', $lines);
return $lines;
};
$lines = $parseLines($source);
$existings = $parseLines($destination);
$missings = array_diff($lines, $existings);
if (!empty($missings)) {
$io->write(sprintf('<info>%s</info> is missing those lines:', str_replace(getcwd() . '/', '', $destination)));
foreach ($missings as $missing) {
$io->write(' • ' . $missing);
}
if ($io->askConfirmation('Would you like to add them ? (y/N) ', false)) {
$io->write(sprintf('Adding <info>%s</info> lines to gitignore.', count($missings)));
file_put_contents($destination, PHP_EOL . implode(PHP_EOL, $missings) . PHP_EOL, FILE_APPEND);
}
}
} else {
// do not prompt, add file automatically
$io->write(sprintf('Installing default <info>%s</info>.', str_replace(getcwd() . '/', '', $destination)));
copy($source, $destination);
}
}
示例11: askConfirmation
/**
* @param IOInterface $io
* @param $parameters
* @return bool
*/
private static function askConfirmation(IOInterface $io, $parameters)
{
if (!$io->isInteractive()) {
return true;
}
$confirmation = $io->askConfirmation(sprintf('Do you want to create MySQL database \'%s\' and install Magento on it [Y,n]?', $parameters['db_name']), true);
return $confirmation;
}