本文整理汇总了PHP中Symfony\Component\Console\Style\SymfonyStyle::confirm方法的典型用法代码示例。如果您正苦于以下问题:PHP SymfonyStyle::confirm方法的具体用法?PHP SymfonyStyle::confirm怎么用?PHP SymfonyStyle::confirm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Style\SymfonyStyle
的用法示例。
在下文中一共展示了SymfonyStyle::confirm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getChangelog
/**
* @return Changelog
*/
protected function getChangelog()
{
$changelogPath = $this->environment->getChangelogPath();
if (!$this->environment->hasChangelog() && $this->output->confirm('No CHANGELOG.md exists, create it?')) {
$stub = file_get_contents(__DIR__ . '/../../stubs/CHANGELOG.md');
file_put_contents($changelogPath, $stub);
}
return new Changelog($changelogPath);
}
示例2: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
$this->sort = $input->getOption('sort');
$this->sleepTime = $input->getOption('sleepTime');
if (!$input->hasOption('sleepTime') && $output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL) {
$this->sleepTime = 25;
}
// Transform milliseconds in microseconds for usleep()
$this->sleepTime = $this->sleepTime * 1000;
$this->numberOfCodesToGenerate = $input->getOption('amount');
// The length of each outputted code
$this->codeLength = $input->getOption('length');
// All possible chars. By default, 'A' to 'Z' and '0' to '9'
$this->possibleChars = str_split($input->getOption('characters'));
$baseNumberOfChars = count($this->possibleChars);
$this->possibleChars = array_unique($this->possibleChars);
// If there's an error here, we'll say it later
$maxPossibleNumberOfCombinations = pow(count($this->possibleChars), $this->codeLength);
if ($maxPossibleNumberOfCombinations < $this->numberOfCodesToGenerate) {
$this->io->error(sprintf('Cannot generate %s combinations because there are only %s combinations possible', number_format($this->numberOfCodesToGenerate, 0, '', ' '), number_format($maxPossibleNumberOfCombinations, 0, '', ' ')));
return 1;
} else {
$this->io->block(sprintf('Generating %s combinations.', number_format($this->numberOfCodesToGenerate, 0, '', ' ')), null, 'info');
if ($maxPossibleNumberOfCombinations > $this->numberOfCodesToGenerate) {
$this->io->block(sprintf('Note: If you need you can generate %s more combinations (with a maximum of %s).', number_format($maxPossibleNumberOfCombinations - $this->numberOfCodesToGenerate, 0, '', ' '), number_format($maxPossibleNumberOfCombinations, 0, '', ' ')), null, 'comment');
}
}
$this->io->block('Available characters:');
$this->io->block(implode('', $this->possibleChars), null, 'info');
$codesList = $this->doGenerate();
$outputFile = $input->getOption('output');
if ($outputFile) {
$save = true;
if (file_exists($outputFile)) {
$save = $this->io->confirm(sprintf('File %s exists. Erase it?', $outputFile), false);
}
if ($save) {
$this->io->block(sprintf('Output results to %s', $outputFile), null, 'info');
if (!file_put_contents($outputFile, implode("\n", $codesList))) {
throw new \Exception(sprintf('Could not write to %s...', $outputFile));
}
}
} else {
$this->io->text($codesList);
}
if ($baseNumberOfChars !== count($this->possibleChars)) {
$this->io->warning(sprintf('We detected that there were duplicate characters in "%s", so we removed them.', $input->getOption('characters')));
}
return 0;
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->title('Pre-commit delete');
$git = new GitVersionControl();
$projectBase = $git->getProjectBase();
$hookDir = $projectBase . '/.git/hooks';
if (!$io->confirm('Are you sure to remove Pre-commit hooks on this project?', true)) {
exit(0);
}
$output->writeln('');
if (!is_dir($hookDir)) {
$io->error(sprintf('The git hook directory does not exist (%s)', $hookDir));
exit(1);
}
$target = $hookDir . '/pre-commit';
$fs = new Filesystem();
if (is_file($target)) {
$fs->remove($target);
$io->success('pre-commit was deleted');
exit(0);
}
$io->error(sprintf('pre-commit file does\'nt exist (%s)', $target));
exit(1);
}
示例4: askToInstall
/**
* @return bool
*/
private function askToInstall()
{
if (array_key_exists($this->workingLocale, $this->installedLocale)) {
$reinstallLocale = $this->formatter->confirm('The locale is already installed, would you like to reinstall and overwrite the current translations?', false);
if (!$reinstallLocale) {
return true;
}
$this->installWorkingLocale(true);
return true;
}
$install = $this->formatter->confirm('Would you like to install this locale?');
if (!$install) {
return false;
}
$this->formatter->writeln('<info>Before you can enable a new locale you need to authenticate to be able to create the pages</info>');
while (!Authentication::loginUser($this->formatter->ask('Login'), $this->formatter->askHidden('Password'))) {
$this->formatter->error('Failed to login, please try again');
}
if (!Authentication::isAllowedAction('Copy', 'Pages')) {
$this->formatter->error('Your profile doesn\'t have the permission to execute the action Copy of the Pages module');
return false;
}
$this->installWorkingLocale();
$this->formatter->writeln('<info>Copying pages from the default locale to the current locale</info>');
BackendPagesModel::copy($this->defaultEnabledLocale, $this->workingLocale);
return true;
}
示例5: pushTags
/**
* Push the tags to Git.
*/
protected function pushTags()
{
if (!$this->output->confirm('Tag and push to remote?')) {
return false;
}
$commands = [['git', 'add', '--all'], ['git', 'commit', '-vam', 'Create version ' . $this->version], ['git', 'tag', $this->version], ['git', 'push'], ['git', 'push', '--tags']];
foreach ($commands as $command) {
$this->execute($command);
}
}
示例6: throwIfInvalidPath
/**
* Thows an exception if the specified path is not valid.
*
* @param string $path
*
* @return void
*
* @throws \SheetFaker\PathException
*/
protected function throwIfInvalidPath($path)
{
if (is_writable(dirname($path))) {
if ($file_exists = file_exists($path)) {
if ($this->output->confirm('The file exists, do you want to remove it? [y|N]', false)) {
unlink($path);
return;
}
throw new PathException("{$path} the specified file already exists.");
}
return;
}
throw new PathException("{$path} is not writable.");
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output = new SymfonyStyle($input, $output);
$queue = $this->queueFactory->createQueue($input->getArgument('queue'));
if ($input->isInteractive()) {
if (!$output->confirm(sprintf(static::CONFIRM_MSG, $queue->getName()), false)) {
return;
}
}
$count = $this->queueRegistry->deregister($queue);
$output->success('Deleted queue "' . $queue->getName() . '"');
if ($count) {
$output->note('Removed ' . $count . ' jobs.');
}
}
示例8: execute
/**
* @param InputInterface $input
* @param OutputInterface|Output $output
* @return void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->getLogger()->debug('Start', ['command_name' => $this->getName(), 'args' => $input->getArguments(), 'opts' => $input->getOptions()]);
$optionDryRun = $input->getOption('dry-run');
$repositories = $this->getRepositoryModelList();
$projectModel = $repositories->getProjectModel();
$xmlFilename = implode(DIRECTORY_SEPARATOR, [$projectModel->getAbsolutePath(), '.idea', 'vcs.xml']);
$fileSystem = new Filesystem();
if (!$fileSystem->exists($xmlFilename)) {
$this->getSymfonyStyle()->error(sprintf('Config file "%s" not found', $xmlFilename));
}
$existsMap = [];
$simpleXml = simplexml_load_file($xmlFilename);
foreach ($simpleXml->component->children() as $child) {
/** @var \SimpleXMLElement $child */
$existsMap[] = (string) $child->attributes()['directory'];
}
$vendors = [];
foreach ($this->getRepositoryModelList()->getAll() as $model) {
$tmp = '$PROJECT_DIR$';
if ($model->getPath()) {
$tmp .= DIRECTORY_SEPARATOR . $model->getPath();
}
$vendors[] = $tmp;
}
$symfonyStyle = new SymfonyStyle($input, $output);
$newDirs = array_diff($vendors, $existsMap);
if (count($newDirs)) {
$question = sprintf('Script will add %d new dirs, would you like to continue?', count($newDirs));
if ($symfonyStyle->confirm($question, true)) {
foreach ($newDirs as $dir) {
$mapping = $simpleXml->component->addChild('mapping', '');
$mapping->addAttribute('directory', $dir);
$mapping->addAttribute('vcs', 'Git');
}
$dom = dom_import_simplexml($simpleXml)->ownerDocument;
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
if (!$optionDryRun) {
$fileSystem->dumpFile($xmlFilename, $dom->saveXML());
}
$symfonyStyle->success(sprintf('File "%s" updated', $xmlFilename));
}
} else {
$symfonyStyle->note('Changes not found');
}
$this->getLogger()->debug('Finish', ['command_name' => $this->getName()]);
}
示例9: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output = new SymfonyStyle($input, $output);
$job = new Job($input->getArgument('target'));
// @todo remove new Job. @todo arguments
if ($input->isInteractive()) {
if (!$output->confirm(sprintf('you sure?', $job->getJobClass()), false)) {
return;
}
}
if (true === ($result = $this->jobPerformer->perform($job))) {
$output->success('Job "' . $job->getJobClass() . '" with arguments (?) successfully performed');
} else {
throw $result;
}
}
示例10: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->title('Pre-commit install');
$git = new GitVersionControl();
$projectBase = $git->getProjectBase();
$phpunit = $io->confirm('Enable PhpUnit ?', true);
$source = realpath($projectBase);
$hookDir = $source . '/.git/hooks';
$defaultPhpUnitConfFile = $source . '/' . self::PHPUNIT_DEFAULT_CONF_FILENAME;
$precommitCommand = sprintf('precommit check%s', $phpunit ? ' --phpunit true' : '');
if ($phpunit) {
$phpunitPath = $io->ask('Specify Phpunit bin path [example: vendor/bin/phpunit] ? : ', 'phpunit');
$phpunitConfFile = $io->ask('Specify Phpunit config file path ? : ', $defaultPhpUnitConfFile);
if ($phpunitPath != '') {
if (strpos($phpunitPath, '/') !== false) {
$phpunitPath = $source . '/' . $phpunitPath;
if (!is_file($phpunitPath)) {
$io->error(sprintf('No phpunit bin found "%s"', $phpunitPath));
exit(1);
}
}
}
if (!is_file($phpunitConfFile)) {
$io->error(sprintf('No phpunit conf file found "%s"', $phpunitConfFile));
exit(1);
}
$precommitCommand .= $phpunitPath != 'phpunit' ? ' --phpunit-bin-path ' . $phpunitPath : '';
$precommitCommand .= $phpunitConfFile != $defaultPhpUnitConfFile ? ' --phpunit-conf ' . $phpunitConfFile : '';
}
if (!is_dir($hookDir)) {
$io->error(sprintf('The git hook directory does not exist (%s)', $hookDir));
exit(1);
}
$target = $hookDir . '/pre-commit';
$fs = new Filesystem();
if (!is_file($target)) {
$fileContent = sprintf("#!/bin/sh\n%s", $precommitCommand);
$fs->dumpFile($target, $fileContent);
chmod($target, 0755);
$io->success('pre-commit file correctly updated');
} else {
$io->note(sprintf('A pre-commit file is already exist. Please add "%s" at the end !', $precommitCommand));
}
exit(0);
}
示例11: actionPasswordReplace
/**
* Password Replace action
*
* @param SymfonyStyle $helper
*
* @return null
*/
private function actionPasswordReplace(SymfonyStyle $helper)
{
if (false === $helper->confirm('Are you sure? Only use this for development purposes!', false)) {
return null;
}
$userClass = $this->getUserEntityClass();
if (null === $userClass) {
throw new \RuntimeException('User entity not found');
}
$password = $helper->ask('New password', 'login123');
$userManager = $this->getContainer()->get('fos_user.user_manager');
/** @var User $user */
foreach ($this->getDoctrine()->getRepository($userClass)->findAll() as $user) {
$user->setPlainPassword($password);
$userManager->updateUser($user);
}
return null;
}
示例12: updateSchema
private function updateSchema(SymfonyStyle $io, $queries)
{
$io->caution("Your database schema needs to be updated. The following queries will be run:");
$io->listing($queries);
if ($this->updateDb === false && $io->confirm("Should we run this queries now?", false) === false) {
return;
}
$cmdOutput = new BufferedOutput();
$command = $this->getApplication()->find('doctrine:schema:update');
$force = new ArrayInput(array('--env' => 'dev', '--dump-sql' => true, '--force' => true));
$command->run($force, $cmdOutput);
$result = $cmdOutput->fetch();
if (strstr($result, 'Database schema updated successfully!') === false) {
$io->error("Couldn't update the schema. Run 'doctrine:schema:update' separately to find out why");
}
$io->success("Database schema updated successfully!");
$this->clearMetadata($io);
}
示例13: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$input->isInteractive() ? $io->title('Symfony Password Encoder Utility') : $io->newLine();
$password = $input->getArgument('password');
$userClass = $input->getArgument('user-class');
$emptySalt = $input->getOption('empty-salt');
$encoder = $this->getContainer()->get('security.encoder_factory')->getEncoder($userClass);
$bcryptWithoutEmptySalt = !$emptySalt && $encoder instanceof BCryptPasswordEncoder;
if ($bcryptWithoutEmptySalt) {
$emptySalt = true;
}
if (!$password) {
if (!$input->isInteractive()) {
$io->error('The password must not be empty.');
return 1;
}
$passwordQuestion = $this->createPasswordQuestion();
$password = $io->askQuestion($passwordQuestion);
}
$salt = null;
if ($input->isInteractive() && !$emptySalt) {
$emptySalt = true;
$io->note('The command will take care of generating a salt for you. Be aware that some encoders advise to let them generate their own salt. If you\'re using one of those encoders, please answer \'no\' to the question below. ' . PHP_EOL . 'Provide the \'empty-salt\' option in order to let the encoder handle the generation itself.');
if ($io->confirm('Confirm salt generation ?')) {
$salt = $this->generateSalt();
$emptySalt = false;
}
} elseif (!$emptySalt) {
$salt = $this->generateSalt();
}
$encodedPassword = $encoder->encodePassword($password, $salt);
$rows = array(array('Encoder used', get_class($encoder)), array('Encoded password', $encodedPassword));
if (!$emptySalt) {
$rows[] = array('Generated salt', $salt);
}
$io->table(array('Key', 'Value'), $rows);
if (!$emptySalt) {
$io->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt)));
} elseif ($bcryptWithoutEmptySalt) {
$io->note('Bcrypt encoder used: the encoder generated its own built-in salt.');
}
$io->success('Password encoding succeeded');
}
示例14: updateReferenceIndex
/**
* Function to update the reference index
* - if the option --update-refindex is set, do it
* - otherwise, if in interactive mode (not having -n set), ask the user
* - otherwise assume everything is fine
*
* @param InputInterface $input holds information about entered parameters
* @param SymfonyStyle $io necessary for outputting information
* @return void
*/
protected function updateReferenceIndex(InputInterface $input, SymfonyStyle $io)
{
// Check for reference index to update
$io->note('Finding missing files referenced by TYPO3 requires a clean reference index (sys_refindex)');
if ($input->hasOption('update-refindex') && $input->getOption('update-refindex')) {
$updateReferenceIndex = true;
} elseif ($input->isInteractive()) {
$updateReferenceIndex = $io->confirm('Should the reference index be updated right now?', false);
} else {
$updateReferenceIndex = false;
}
// Update the reference index
if ($updateReferenceIndex) {
$referenceIndex = GeneralUtility::makeInstance(ReferenceIndex::class);
$referenceIndex->updateIndex(false, !$io->isQuiet());
} else {
$io->writeln('Reference index is assumed to be up to date, continuing.');
}
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$since = $input->getArgument('since');
$dateTimeRequested = null;
$io = new SymfonyStyle($input, $output);
$io->title('Envoi un mail avec les derniers fichiers à ' . $input->getArgument('for'));
if ($since == 'day') {
$dateTimeRequested = (new \Datetime())->modify('-1 day');
} elseif ($since == 'week') {
$dateTimeRequested = (new \Datetime())->modify('-1 week');
} elseif ($since == 'month') {
$dateTimeRequested = (new \Datetime())->modify('-1 month');
} else {
throw new HttpException(500, "Excpected variable 'since' with values 'day', 'week', 'month'");
}
switch ($since) {
case 'day':
$sinceFr = 'un jour';
break;
case 'week':
$sinceFr = 'une semaine';
break;
case 'month':
$sinceFr = "un mois";
break;
}
$mailer = $this->getContainer()->get('mailer');
$templating = $this->getContainer()->get('templating');
$users = $this->getContainer()->get('eveg.user.newsletter');
$emails = $users->getUsersEmailsAction();
$emailsList = array();
foreach ($emails as $key => $email) {
foreach ($email as $key => $value) {
array_push($emailsList, $value);
}
}
$wu = $this->getContainer()->get('eveg_app.whatsup');
$news = $wu->tellMeWhatsNew($limitItems = null, $since = $dateTimeRequested);
$io->writeln(count($news) . ' nouveaux documents ajoutés à eVeg depuis ' . $sinceFr . '.');
if ($input->getArgument('for') == 'users') {
$io->writeln(count($emailsList) . ' mails à envoyer.');
}
if ($input->getArgument('for') == 'admin') {
$io->writeln('Envoyer le mail à Admin.');
}
$message = \Swift_Message::newInstance()->setSubject('eVeg | Derniers ajouts')->setFrom($this->getContainer()->getParameter('eveg')['feedback']['mail_website_admin'])->setBody($templating->render('evegAppBundle:Emails:newsletterLastUploads.html.twig', array('news' => $news, 'since' => $input->getArgument('since'))), 'text/html');
if ($input->getArgument('for') == 'users') {
$message->setBcc($emailsList);
} elseif ($input->getArgument('for') == 'admin') {
$message->setTo($this->getContainer()->getParameter('eveg')['feedback']['mail_website_admin']);
} else {
throw new HttpException(500, "Excpected variable 'for' with values 'admin', 'users'");
}
if (count($news) > 1) {
if ($input->getOption('force') || $io->confirm("Valider l'envoi à " . $input->getArgument('for') . "?", false)) {
$mailer->send($message);
$io->success('La newsletter a été envoyée.');
}
} else {
$output->writeln('Aucun mail envoyé');
}
}