当前位置: 首页>>代码示例>>PHP>>正文


PHP QuestionHelper::ask方法代码示例

本文整理汇总了PHP中Symfony\Component\Console\Helper\QuestionHelper::ask方法的典型用法代码示例。如果您正苦于以下问题:PHP QuestionHelper::ask方法的具体用法?PHP QuestionHelper::ask怎么用?PHP QuestionHelper::ask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Console\Helper\QuestionHelper的用法示例。


在下文中一共展示了QuestionHelper::ask方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: askQuestion

 /**
  * @param string|Question $question Question text or a Question object
  * @param null|string $default The default answer
  * @param bool|\Closure $requireAnswer True for not-empty validation, or a closure for custom validation
  * @return string User's answer
  */
 protected function askQuestion($question, $default = null, $requireAnswer = true)
 {
     if (!$this->questionHelper) {
         $this->questionHelper = $this->getHelper("question");
     }
     if (!$question instanceof Question) {
         if (strpos($question, '<question>') === false) {
             $question = '<question>' . $question . '</question> ';
         }
         if ($default !== null) {
             $question .= "({$default}) ";
         }
         $question = new Question($question, $default);
     }
     if (is_callable($requireAnswer)) {
         $question->setValidator($requireAnswer);
     } elseif ($requireAnswer) {
         $question->setValidator(function ($answer) {
             if (trim($answer) == '') {
                 throw new \Exception('You must provide an answer to this question');
             }
             return $answer;
         });
     }
     return $this->questionHelper->ask($this->input, $this->output, $question);
 }
开发者ID:rhubarbphp,项目名称:custard,代码行数:32,代码来源:CustardCommand.php

示例2: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = $input->getArgument('username');
     $email = $input->getArgument('email');
     $repository = $this->getRepository();
     /* @var $entity User */
     $entity = $repository->createModel(array());
     try {
         $repository->findByUsername($username);
         $output->writeln(sprintf('A user with the username %s already exists.', $username));
         return 1;
     } catch (NotFound $e) {
     }
     $entity->setUsername($username);
     if ($email) {
         try {
             $repository->findByEmail($email);
             $output->writeln(sprintf('A user with the email %s already exists.', $email));
             return 1;
         } catch (NotFound $e) {
         }
         $entity->setEmail($username);
     }
     $questionHelper = new QuestionHelper();
     $question = new Question(sprintf('<question>%s</question>: ', 'Name (not required):'));
     $entity->setName($questionHelper->ask($input, $output, $question));
     $question = new Question(sprintf('<question>%s</question>: ', 'Enter a password:'));
     $question->setHidden(true);
     $password = $questionHelper->ask($input, $output, $question);
     $entity->setPassword($this->getPasswordEncoder()->encodePassword($password));
     $entity->setRoles(array(User::ROLE_MASTER));
     $repository->add($entity);
     $output->writeln(sprintf('User %s added successfully.', $username));
 }
开发者ID:devture,项目名称:silex-user-bundle,代码行数:34,代码来源:AddUserCommand.php

示例3: prepare

 /**
  * prepare encryption module to decrypt all files
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param $user
  * @return bool
  */
 public function prepare(InputInterface $input, OutputInterface $output, $user)
 {
     $question = new Question('Please enter the recovery key password: ');
     $recoveryKeyId = $this->keyManager->getRecoveryKeyId();
     if (!empty($user)) {
         $questionUseLoginPassword = new ConfirmationQuestion('Do you want to use the users login password to decrypt all files? (y/n) ', false);
         $useLoginPassword = $this->questionHelper->ask($input, $output, $questionUseLoginPassword);
         if ($useLoginPassword) {
             $question = new Question('Please enter the users login password: ');
         } else {
             if ($this->util->isRecoveryEnabledForUser($user) === false) {
                 $output->writeln('No recovery key available for user ' . $user);
                 return false;
             } else {
                 $user = $recoveryKeyId;
             }
         }
     } else {
         $user = $recoveryKeyId;
     }
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $password = $this->questionHelper->ask($input, $output, $question);
     $privateKey = $this->getPrivateKey($user, $password);
     if ($privateKey !== false) {
         $this->updateSession($user, $privateKey);
         return true;
     } else {
         $output->writeln('Could not decrypt private key, maybe you entered the wrong password?');
     }
     return false;
 }
开发者ID:unrealbato,项目名称:core,代码行数:40,代码来源:decryptall.php

示例4: setupAdministrator

 /**
  * Setup administrator
  */
 protected function setupAdministrator()
 {
     $question = new ConfirmationQuestion('Would you like to create default administrator user (Recommended)? [y/n] ', true);
     if (!$this->helper->ask($this->input, $this->output, $question)) {
         return;
     }
     $this->runCommand('avoo:user:create');
 }
开发者ID:avoo,项目名称:FrameworkInstallerBundle,代码行数:11,代码来源:ConfigureCommand.php

示例5: execute

 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$this->questionHelper->ask($input, $output, $this->buildQuestion())) {
         return ITask::NO_ERROR_CODE;
     }
     if (!$this->plannerBuilder->count()) {
         $output->writeln('<error>Nothing to run</error>');
         return ITask::NON_BLOCKING_ERROR_CODE;
     }
     return $this->getPlanner()->execute($input, $output);
 }
开发者ID:raphhh,项目名称:samurai,代码行数:16,代码来源:PlannerAdapter.php

示例6: __construct

    public function __construct()
    {
        $this->name = 'zyncroapp:create:database';
        $this->definition = array(new InputArgument('namespace', InputArgument::REQUIRED, 'The namespace of the ZyncroApp'));
        $this->description = 'Create a new database for the given Zyncroapp';
        $this->help = 'The <info>zyncroapp:create:database</info> command will create the database, a user for that database and configure the "config.yml" file for the ZyncroApp.

This is an example of how to create the database for a ZyncroApp called <options=bold>FeaturedGroups</options=bold>:

    <info>php bin/console.php zyncroapp:create:database FeaturedGroups</info>';
        $this->execute = function (InputInterface $input, OutputInterface $output) {
            $args = $input->getArguments();
            $namespace = $args['namespace'];
            $appFolder = __DIR__ . '/../../../../../../src/' . $namespace;
            $configFilePath = $appFolder . '/Config/config.yml';
            $helper = new QuestionHelper();
            $question = new Question('<info>MySQL user which will execute the creation of the database and user: </info>');
            $mysqlUser = $helper->ask($input, $output, $question);
            $question = new Question('<info>Password for the MySQL user: </info>');
            $mysqlPassword = $helper->ask($input, $output, $question);
            $question = new Question('<info>Host of the MySQL server: </info>');
            $mysqlHost = $helper->ask($input, $output, $question);
            $question = new Question('<info>Port of the MySQL server: </info>');
            $mysqlPort = $helper->ask($input, $output, $question);
            if (!is_dir($appFolder) || !is_file($configFilePath)) {
                $output->writeln('<error>ZyncroApp with namespace ' . $args['namespace'] . ' is not found or doesn\'t have a config.yml file</error>');
                exit;
            }
            if (!$mysqlUser) {
                $output->writeln('<error>You must provide a MySQL user</error>');
                exit;
            }
            if (!$mysqlHost) {
                $output->writeln('<error>You must provide a MySQL host</error>');
                exit;
            }
            if (!$mysqlPort) {
                $output->writeln('<error>You must provide a MySQL port</error>');
                exit;
            }
            $result = $this->createDatabaseAndUser(strtolower($namespace), $mysqlUser, $mysqlPassword, $mysqlHost, $mysqlPort);
            if (!$result) {
                $output->writeln('<error>There was and error using MySQL with username "' . $mysqlUser . '" and password "' . $mysqlPassword . '"</error>');
            } else {
                $written = $this->writeConfigYmlFile($configFilePath, strtolower($namespace), $result, $mysqlHost);
                if ($written) {
                    $output->writeln('<info>Database and user created successfully. All the parameters are in the "config.yml" file.</info>');
                } else {
                    $output->writeln('<error>There was and error writting the configuration to the "config.yml" file</error>');
                }
            }
        };
    }
开发者ID:zyncro,项目名称:framework,代码行数:53,代码来源:CreateZyncroAppDatabase.php

示例7: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $purge = $input->getOption('purge');
     $force = $input->getOption('force');
     if ($purge && false === $force) {
         $question = new ConfirmationQuestion('<question>Are you sure you want to purge ALL the configured workspaces?</>', false);
         if (false === $this->questionHelper->ask($input, $output, $question)) {
             $output->writeln('Cancelled');
             return;
         }
     }
     $this->initializer->initialize($output, $purge);
 }
开发者ID:sulu,项目名称:sulu,代码行数:16,代码来源:InitializeCommand.php

示例8: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $isAlreadyEnabled = $this->util->isMasterKeyEnabled();
     if ($isAlreadyEnabled) {
         $output->writeln('Master key already enabled');
     } else {
         $question = new ConfirmationQuestion('Warning: Only available for fresh installations with no existing encrypted data! ' . 'There is also no way to disable it again. Do you want to continue? (y/n) ', false);
         if ($this->questionHelper->ask($input, $output, $question)) {
             $this->config->setAppValue('encryption', 'useMasterKey', '1');
             $output->writeln('Master key successfully enabled.');
         } else {
             $output->writeln('aborted.');
         }
     }
 }
开发者ID:loulancn,项目名称:core,代码行数:15,代码来源:enablemasterkey.php

示例9: createConfiguration

 /**
  * Creates configuration file of application.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function createConfiguration(InputInterface $input, OutputInterface $output)
 {
     $path = $this->getApplication()->getRoot() . '/.jedi.php';
     $output->writeln('  - Configuration');
     if (file_exists($path)) {
         $question = new ConfirmationQuestion('    <error>Configuration file ' . $path . ' already exists</error>' . PHP_EOL . '    <info>Overwrite? [Y/n]</info> ', true, '/^(y|j)/i');
         if (!$this->questionHelper->ask($input, $output, $question)) {
             return;
         }
     }
     $fs = new Filesystem();
     $question = new Question('    <info>Enter path to web directory relative to ' . $this->getApplication()->getRoot() . ':</info> ' . PHP_EOL . '    (or do not specify if you are already in the web directory)' . PHP_EOL);
     $question->setValidator(function ($answer) use($fs) {
         $path = $answer;
         if ($answer === null) {
             $path = $this->getApplication()->getRoot();
         } elseif (!$fs->isAbsolutePath($answer)) {
             $path = $this->getApplication()->getRoot() . '/' . $answer;
         }
         if (!is_dir($path)) {
             throw new \RuntimeException('Directory "' . $path . '" is missing');
         }
         return $answer;
     });
     $webDir = $this->questionHelper->ask($input, $output, $question);
     $content = file_get_contents($this->tmplDir . '/.jedi.php');
     $content = str_replace(['%web-dir%', '%env-dir%'], [addslashes($webDir), addslashes($this->envDir)], $content);
     $fs->dumpFile($path, $content);
     $output->writeln('    Created configuration file of application <comment>' . $path . '</comment>');
 }
开发者ID:notamedia,项目名称:console-jedi,代码行数:36,代码来源:InitCommand.php

示例10: execute

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $args = $input->getArguments();
     $config = $this->getZyncroAppConfig($args['namespace']);
     $helper = new QuestionHelper();
     $newParameters = array();
     if ($config) {
         $output->writeln('');
         $parameters = $this->getParametersFromConfig($config);
         foreach ($parameters as $parameter) {
             if (!isset($newParameters[$parameter['block']])) {
                 $newParameters[$parameter['block']] = array();
             }
             $question = new Question('Set value for parameter <fg=green>' . $parameter['key'] . '</fg=green> of block <fg=green>' . $parameter['block'] . '</fg=green> (default: <fg=yellow>' . $parameter['value'] . '</fg=yellow>): ', $parameter['value']);
             $newParameters[$parameter['block']][$parameter['key']] = $helper->ask($input, $output, $question);
         }
         $dataSaved = $this->saveZyncroAppConfig($args['namespace'], $newParameters);
         if ($dataSaved) {
             $output->writeln('');
             $output->writeln('<info>The new configuration for the ZyncroApp with the namespace ' . $args['namespace'] . ' has been saved</info>');
             $output->writeln('');
         }
     } else {
         $output->writeln('<error>ZyncroApp with namespace ' . $args['namespace'] . ' is not found or doesn\'t have a config.yml file</error>');
     }
 }
开发者ID:zyncro,项目名称:framework,代码行数:26,代码来源:ConfigureZyncroApp.php

示例11: ask

 protected function ask(QuestionHelper $oQuestionHelper, InputInterface $oInput, OutputInterface $oOutput, $sLabel, $sDefault = null, $bMandatory = true, $aChoices = [])
 {
     // Update label
     $sLabel = sprintf('%s%s: ', $sLabel, !is_null($sDefault) ? sprintf(' [%s]', $sDefault) : '');
     // Create question
     if ($aChoices === []) {
         $oQuestion = new Question($sLabel, $sDefault);
     } else {
         $oQuestion = new ChoiceQuestion($sLabel, $aChoices, $sDefault);
     }
     // Ask
     do {
         // Initialize
         $bTerminate = true;
         // Ask
         $sValue = $oQuestionHelper->ask($oInput, $oOutput, $oQuestion);
         // Mandatory
         if ($bMandatory and empty($sValue)) {
             // Output
             $oOutput->writeln('Value can\'t be blank');
             // Update terminate
             $bTerminate = false;
         }
     } while (!$bTerminate);
     // Return
     return $sValue;
 }
开发者ID:asticode,项目名称:php-deployment-manager,代码行数:27,代码来源:AbstractCommand.php

示例12: ask

 /**
  * {@inheritdoc}
  */
 public function ask(InputInterface $input, OutputInterface $output, Question $question)
 {
     if (null !== $this->attempts && null === $question->getMaxAttempts()) {
         $question->setMaxAttempts($this->attempts);
     }
     return QuestionHelper::ask($input, $output, $question);
 }
开发者ID:mistymagich,项目名称:gush,代码行数:10,代码来源:GushQuestionHelper.php

示例13: outputPasswords

 /**
  * output one-time encryption passwords
  */
 protected function outputPasswords()
 {
     $table = new Table($this->output);
     $table->setHeaders(array('Username', 'Private key password'));
     //create rows
     $newPasswords = array();
     $unchangedPasswords = array();
     foreach ($this->userPasswords as $uid => $password) {
         if (empty($password)) {
             $unchangedPasswords[] = $uid;
         } else {
             $newPasswords[] = [$uid, $password];
         }
     }
     if (empty($newPasswords)) {
         $this->output->writeln("\nAll users already had a key-pair, no further action needed.\n");
         return;
     }
     $table->setRows($newPasswords);
     $table->render();
     if (!empty($unchangedPasswords)) {
         $this->output->writeln("\nThe following users already had a key-pair which was reused without setting a new password:\n");
         foreach ($unchangedPasswords as $uid) {
             $this->output->writeln("    {$uid}");
         }
     }
     $this->writePasswordsToFile($newPasswords);
     $this->output->writeln('');
     $question = new ConfirmationQuestion('Do you want to send the passwords directly to the users by mail? (y/n) ', false);
     if ($this->questionHelper->ask($this->input, $this->output, $question)) {
         $this->sendPasswordsByMail();
     }
 }
开发者ID:ErikPel,项目名称:core,代码行数:36,代码来源:encryptall.php

示例14: choosePatch

 /**
  * @param Issue $issue
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return string|bool
  */
 protected function choosePatch(Issue $issue, InputInterface $input, OutputInterface $output)
 {
     $patch = FALSE;
     $patches_to_search = $issue->getLatestPatch();
     if (count($patches_to_search) > 1) {
         // Need to choose patch.
         $question_helper = new QuestionHelper();
         $output->writeln('Multiple patches detected:');
         $output->writeln($this->getChoices($patches_to_search));
         $question = new Question('Choose patch to search: ', 1);
         $question->setValidator(function ($patch_key) use($patches_to_search) {
             if (!in_array($patch_key, range(0, count($patches_to_search)))) {
                 throw new \InvalidArgumentException(sprintf('Choice "%s" is invalid.', $patch_key));
             }
             return $patch_key;
         });
         $patch_key = $question_helper->ask($input, $output, $question);
         $patch = $patches_to_search[$patch_key - 1];
     } elseif (count($patches_to_search) == 1) {
         $patch = $patches_to_search[0];
     } else {
         // Nothing to do.
         $output->writeln("No patches available on " . $issue->getUri());
     }
     return $patch;
 }
开发者ID:joelpittet,项目名称:dopatchutils,代码行数:32,代码来源:PatchChooserBase.php

示例15: askQuestion

 /**
  * Asks user question.
  *
  * @param string   $message
  * @param string[] $choices
  * @param string   $default
  *
  * @return string
  */
 private function askQuestion($message, $choices, $default)
 {
     $this->output->writeln('');
     $helper = new QuestionHelper();
     $question = new ChoiceQuestion(' ' . $message . "\n", $choices, $default);
     return $helper->ask($this->input, $this->output, $question);
 }
开发者ID:behat,项目名称:behat,代码行数:16,代码来源:InteractiveContextIdentifier.php


注:本文中的Symfony\Component\Console\Helper\QuestionHelper::ask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。