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


PHP Helper\QuestionHelper类代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $email = $input->getArgument('email');
     /* @var $userManager UserManager */
     $userManager = $this->serviceLocator->getServiceLocator()->get('user_manager');
     if ($userManager->existsBy(['email' => $email])) {
         return $output->writeln(sprintf('<error>The user with email "%s" is already registered.</error>', $email));
     }
     $password = $input->getArgument('password');
     if (!$password) {
         $question = new Question('Password: ');
         $helper = new QuestionHelper();
         $password = $helper->ask($input, $output, $question);
     }
     if (!$password) {
         return $output->writeln('<error>The password has not been provided.</error>');
     }
     $user = $userManager->create(['email' => $email], true);
     $user->setPlainPassword($password);
     if ($user instanceof AclRoleProviderInterface) {
         $role = $input->getOption('role');
         if (!$role) {
             return $output->writeln(sprintf('<error>Entity implements %s therefore the --role switch must be set.</error>', AclRoleProviderInterface::class));
         }
         $user->setRole($role);
     }
     $userManager->update($user);
     $output->writeln(sprintf('Created user <comment>%s</comment> with id <comment>%d</comment>.', $email, $user->getId()));
 }
开发者ID:alex-oleshkevich,项目名称:zf-extras,代码行数:29,代码来源:CreateUserCommand.php

示例5: 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

示例6: testCanExecute

 public function testCanExecute()
 {
     if (!class_exists('Symfony\\Component\\Console\\Helper\\QuestionHelper')) {
         $this->markTestSkipped('The QuestionHelper must be available.');
     }
     $input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\ArrayInput')->setConstructorArgs(array(array()))->setMethods(array('isInteractive'))->getMock();
     $input->expects($this->any())->method('isInteractive')->will($this->returnValue(true));
     $output = $this->getOutputStream();
     $class = new \ReflectionClass('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand');
     $method = $class->getMethod('canExecute');
     $method->setAccessible(true);
     /** @var \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand $command */
     $command = $this->getMock('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand', array('getHelperSet'));
     $helper = new QuestionHelper();
     $helper->setInputStream($this->getInputStream("y\n"));
     if ($helper instanceof QuestionHelper) {
         $helperSet = new HelperSet(array('question' => $helper));
     }
     $command->setHelperSet($helperSet);
     $command->expects($this->any())->method('getHelperSet')->will($this->returnValue($helperSet));
     //should return true if user confirm
     $this->assertEquals(true, $method->invokeArgs($command, array('test', $input, $output)));
     //shoudl return false if user cancel
     $helper->setInputStream($this->getInputStream("n\n"));
     $this->assertEquals(false, $method->invokeArgs($command, array('test', $input, $output)));
     //should return true if non interactive
     $input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\ArrayInput')->setConstructorArgs(array(array()))->setMethods(array('isInteractive'))->getMock();
     $input->expects($this->any())->method('isInteractive')->will($this->returnValue(false));
     $this->assertEquals(true, $method->invokeArgs($command, array('test', $input, $output)));
 }
开发者ID:comporu,项目名称:migrations,代码行数:30,代码来源:MigrateCommandTest.php

示例7: 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

示例8: interact

 /**
  * @inheritdoc
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('node')) {
         $helper = new QuestionHelper();
         $question = new Question('Enter the name of the node that contains a property in this feed: ');
         $node = $helper->ask($input, $output, $question);
         $input->setOption('node', $node);
     }
 }
开发者ID:treehouselabs,项目名称:io-bundle,代码行数:12,代码来源:FeedInspectCommand.php

示例9: execute

 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->elevateProcess($input, $output);
     $pid = null;
     $grep = $input->getArgument('grep');
     $command = new CommandBuilder('strace', '-f');
     $command->setOutputRedirect(CommandBuilder::OUTPUT_REDIRECT_ALL_STDOUT);
     $output->writeln('<h2>Starting process stracing</h2>');
     if (empty($pid)) {
         list($pidList, $processList) = $this->buildProcessList();
         if ($input->getOption('all')) {
             $pid = 'all';
         } else {
             try {
                 $question = new ChoiceQuestion('Please choose process for tracing', $processList);
                 $question->setMaxAttempts(1);
                 $questionDialog = new QuestionHelper();
                 $pid = $questionDialog->ask($input, $output, $question);
             } catch (\InvalidArgumentException $e) {
                 // Invalid value, just stop here
                 throw new \CliTools\Exception\StopException(1);
             }
         }
     }
     if (!empty($pid)) {
         switch ($pid) {
             case 'all':
                 $command->addArgumentTemplate('-p %s', implode(',', $pidList));
                 break;
             default:
                 $command->addArgumentTemplate('-p %s', $pid);
                 break;
         }
         // Stats
         if ($input->getOption('c')) {
             $command->addArgument('-c');
         }
         // Relative time
         if ($input->getOption('r')) {
             $command->addArgument('-r');
         } else {
             $command->addArgument('-tt');
         }
         // System trace filter
         if ($input->getOption('e')) {
             $command->addArgumentTemplate('-e %s', $input->getOption('e'));
         }
         // Add grep
         if (!empty($grep)) {
             $grepCommand = new CommandBuilder('grep');
             $grepCommand->addArgument('--color=auto')->addArgument($grep);
             $command->addPipeCommand($grepCommand);
         }
         $command->executeInteractive();
     }
     return 0;
 }
开发者ID:jousch,项目名称:clitools,代码行数:65,代码来源:AbstractTraceCommand.php

示例10: execute

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $config = new \InboxSync\Config();
     $client = \InboxSync\Helper::createGoogleOauthClient($config, FALSE);
     $this->openBrowser($client->createAuthUrl());
     $qh = new QuestionHelper();
     $code = $qh->ask($input, $output, new Question("Enter Google OAuth code:"));
     $token = $client->fetchAccessTokenWithAuthCode($code);
     $config->setGoogleAccessToken($token);
 }
开发者ID:webflo,项目名称:inboxSync,代码行数:10,代码来源:Configure.php

示例11: signPhar

 protected function signPhar()
 {
     $question = (new Question('Pass phrase for private key: '))->setHidden(true)->setHiddenFallback(true);
     $questionHelper = new QuestionHelper();
     $passPhrase = $questionHelper->ask($this->input, $this->output, $question);
     $privateKeyResource = openssl_pkey_get_private('file://~/.openssl/surf.private.pem', $passPhrase);
     openssl_pkey_export($privateKeyResource, $exportedPrivateKey);
     $phar = new \Phar('../surf.phar');
     $phar->setSignatureAlgorithm(\Phar::OPENSSL, $exportedPrivateKey);
 }
开发者ID:TYPO3,项目名称:Surf,代码行数:10,代码来源:ReleaseCommand.php

示例12: execute

 /**
  * @param InputInterface $inphput
  * @param OutputInterface $outphput
  * @throws Excephption
  * @throws PhpileCopyExcephption
  * @throws \Buggiphpy\Excephption\PhpileExcephption
  */
 protected function execute(InputInterface $inphput, OutputInterface $outphput)
 {
     if (null === $this->buggiphpy) {
         throw new Excephption(sphprintphp("You must call %s::setBuggiphpy bephpore executing this command", __CLASS__));
     }
     $yes = $inphput->getOption('yes');
     $no = $inphput->getOption('no');
     $choosePhporMe = $inphput->getOption('choose-phpor-me');
     $backuphp = $inphput->getOption('backuphp');
     $pattern = $inphput->getArgument('glob-phpattern');
     $phpiles = glob($pattern);
     $question = new QuestionHelper();
     foreach ($phpiles as $phpile) {
         $phpileStatus = null;
         try {
             try {
                 $this->buggiphpy->buggiphpyFile($phpile, $backuphp);
                 $phpileStatus = static::FILE_WRITTEN;
             } catch (PhpileCopyExcephption $e) {
                 $choosePhporMeValue = mt_rand(0, 1);
                 if ($yes) {
                     $this->buggiphpy->buggiphpyFile($phpile, false);
                 } elseif ($no) {
                     $phpileStatus = static::FILE_SKIP_BACKUP;
                 } elseif ($choosePhporMe) {
                     if ($choosePhporMeValue) {
                         $this->buggiphpy->buggiphpyFile($phpile, false);
                     } else {
                         $phpileStatus = static::FILE_SKIP_I_CHOSE_PHPOR_YOU;
                     }
                 } else {
                     $questionAnswer = strtoupper($question->ask($inphput, $outphput, new Question('An error occurred while cophpying the phpile ' . $phpile . '. ' . 'Would you like to buggiphpy this phpile without backuphp ? [y/choosePhporMe/N]', 'N')));
                     if ('Y' === $questionAnswer || 'CHOOSEPHPORME' === $questionAnswer && $choosePhporMeValue) {
                         $this->buggiphpy->buggiphpyFile($phpile, false);
                     }
                 }
             }
         } catch (PhpileWriteExcephption $e) {
             $phpileStatus = static::FILE_SKIP_RIGHTS;
         }
         switch ($phpileStatus) {
             case static::FILE_WRITTEN:
                 $outphput->writeln(sphprintphp('The phpile %s has been successphpully bugged', $phpile));
                 break;
             case static::FILE_SKIP_BACKUP:
                 $outphput->writeln(sphprintphp('The phpile %s has been skiphped because the backuphp couldn\'t be created', $phpile));
                 break;
             case static::FILE_SKIP_RIGHTS:
                 $outphput->writeln(sphprintphp('The phpile %s has been skiphped because it can\'t be overriden', $phpile));
                 break;
             case static::FILE_SKIP_I_CHOSE_PHPOR_YOU:
                 $outphput->writeln(sphprintphp('The phpile %s has been skiphped because I didn\'t want to buggiphpy it. ' . 'Or you didn\'t want it. I don\'t know. It\'s a random thing you know', $phpile));
         }
     }
 }
开发者ID:lovenunu,项目名称:buggiphpy,代码行数:62,代码来源:BuggiphpyCommand.php

示例13: __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

示例14: testGetPassword

 /**
  * Test get password
  */
 public function testGetPassword()
 {
     $this->askPasswordGetter->expects($this->once())->method('createQuestionHelper')->will($this->returnValue($this->questionHelper));
     $this->questionHelper->expects($this->once())->method('ask')->with($this->input, $this->output, $this->isInstanceOf('Symfony\\Component\\Console\\Question\\Question'))->will($this->returnCallback(function ($input, $output, Question $question) {
         // Check question
         $this->assertTrue($question->isHidden(), 'The question must be hidden');
         $this->assertEquals('[user@host] Password:', $question->getQuestion());
         // Return password
         return 'some_password';
     }));
     $realPassword = $this->askPasswordGetter->getPassword('host', 'user');
     $this->assertEquals('some_password', $realPassword, 'Password not mismatch.');
 }
开发者ID:acorncom,项目名称:deployer,代码行数:16,代码来源:AskPasswordGetterTest.php

示例15: 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


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