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


PHP ChoiceQuestion::setErrorMessage方法代码示例

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


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

示例1: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $schoolId = $input->getOption('schoolId');
     if (!$schoolId) {
         $schoolTitles = [];
         foreach ($this->schoolManager->findBy([], ['title' => 'ASC']) as $school) {
             $schoolTitles[$school->getTitle()] = $school->getId();
         }
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion("What is this user's primary school?", array_keys($schoolTitles));
         $question->setErrorMessage('School %s is invalid.');
         $schoolTitle = $helper->ask($input, $output, $question);
         $schoolId = $schoolTitles[$schoolTitle];
     }
     $school = $this->schoolManager->findOneBy(['id' => $schoolId]);
     if (!$school) {
         throw new \Exception("School with id {$schoolId} could not be found.");
     }
     $userRecord = ['firstName' => $input->getOption('firstName'), 'lastName' => $input->getOption('lastName'), 'email' => $input->getOption('email'), 'telephoneNumber' => $input->getOption('telephoneNumber'), 'campusId' => $input->getOption('campusId'), 'username' => $input->getOption('username'), 'password' => $input->getOption('password')];
     $userRecord = $this->fillUserRecord($userRecord, $input, $output);
     $user = $this->userManager->findOneBy(['campusId' => $userRecord['campusId']]);
     if ($user) {
         throw new \Exception('User #' . $user->getId() . " with campus id {$userRecord['campusId']} already exists.");
     }
     $user = $this->userManager->findOneBy(['email' => $userRecord['email']]);
     if ($user) {
         throw new \Exception('User #' . $user->getId() . " with email address {$userRecord['email']} already exists.");
     }
     $table = new Table($output);
     $table->setHeaders(array('Campus ID', 'First', 'Last', 'Email', 'Username', 'Phone Number'))->setRows(array([$userRecord['campusId'], $userRecord['firstName'], $userRecord['lastName'], $userRecord['email'], $userRecord['username'], $userRecord['telephoneNumber']]));
     $table->render();
     $helper = $this->getHelper('question');
     $output->writeln('');
     $question = new ConfirmationQuestion("<question>Do you wish to add this user to Ilios in {$school->getTitle()}?</question>\n", true);
     if ($helper->ask($input, $output, $question)) {
         $user = $this->userManager->create();
         $user->setFirstName($userRecord['firstName']);
         $user->setLastName($userRecord['lastName']);
         $user->setEmail($userRecord['email']);
         $user->setCampusId($userRecord['campusId']);
         $user->setAddedViaIlios(true);
         $user->setEnabled(true);
         $user->setSchool($school);
         $user->setUserSyncIgnore(false);
         $this->userManager->update($user);
         $authentication = $this->authenticationManager->create();
         $authentication->setUsername($userRecord['username']);
         $user->setAuthentication($authentication);
         $encodedPassword = $this->encoder->encodePassword($user, $userRecord['password']);
         $authentication->setPasswordBcrypt($encodedPassword);
         $this->authenticationManager->update($authentication);
         $output->writeln('<info>Success! New user #' . $user->getId() . ' ' . $user->getFirstAndLastName() . ' created.</info>');
     } else {
         $output->writeln('<comment>Canceled.</comment>');
     }
 }
开发者ID:stopfstedt,项目名称:ilios,代码行数:59,代码来源:AddUserCommand.php

示例2: showTasksToDelete

 protected function showTasksToDelete(InputInterface $input, OutputInterface $output, $tasks)
 {
     $helper = $this->getHelper('question');
     $question = new ChoiceQuestion('Please select the task that you want to delete', $tasks->toArray(), 0);
     $question->setErrorMessage('Task %s does not exist.');
     return $helper->ask($input, $output, $question);
 }
开发者ID:destebang,项目名称:taskreporter-1,代码行数:7,代码来源:DeleteTask.php

示例3: interact

 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the Symfony2Admingenerator');
     $output->writeln('<comment>Create an admingenerator bundle with generate:bundle</comment>');
     $generator = $input->getOption('generator');
     $question = new ChoiceQuestion('Generator to use (doctrine, doctrine_odm, propel)', array('doctrine', 'doctrine_odm', 'propel'), 0);
     $question->setErrorMessage('Generator to use have to be doctrine, doctrine_odm or propel.');
     $generator = $questionHelper->ask($input, $output, $question);
     $input->setOption('generator', $generator);
     // Model name
     $modelName = $input->getOption('model-name');
     $question = new Question($questionHelper->getQuestion('Model name', $modelName), $modelName);
     $question->setValidator(function ($answer) {
         if (empty($answer) || preg_match('#[^a-zA-Z0-9]#', $answer)) {
             throw new \RuntimeException('Model name should not contain any special characters nor spaces.');
         }
         return $answer;
     });
     $modelName = $questionHelper->ask($input, $output, $question);
     $input->setOption('model-name', $modelName);
     // prefix
     $prefix = $input->getOption('prefix');
     $question = new Question($questionHelper->getQuestion('Prefix of yaml', $prefix), $prefix);
     $question->setValidator(function ($prefix) {
         if (!preg_match('/([a-z]+)/i', $prefix)) {
             throw new \RuntimeException('Prefix have to be a simple word');
         }
         return $prefix;
     });
     $prefix = $questionHelper->ask($input, $output, $question);
     $input->setOption('prefix', $prefix);
     parent::interact($input, $output);
 }
开发者ID:Restless-ET,项目名称:GeneratorBundle,代码行数:34,代码来源:GenerateAdminCommand.php

示例4: interact

 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     /** @var StorageInterface $storage */
     $storage = $this->getContainer()->get('storage');
     $files = $input->getArgument('files');
     if ($input->getOption('latest')) {
         $remoteFiles = $storage->remoteListing();
         if (count($remoteFiles) > 0) {
             $files[] = end($remoteFiles);
             $input->setArgument('files', $files);
         }
     }
     if ($input->hasArgument('files') && !empty($files)) {
         return;
     }
     $remoteFiles = $storage->remoteListing();
     $localFiles = $storage->localListing();
     if (count(array_diff($remoteFiles, $localFiles)) === 0) {
         $output->writeln('All files fetched');
         return;
     }
     $helper = $this->getHelper('question');
     $question = new ChoiceQuestion('Which backup', array_values(array_diff($remoteFiles, $localFiles)));
     $question->setMultiselect(true);
     $question->setErrorMessage('Backup %s is invalid.');
     $question->setAutocompleterValues([]);
     $input->setArgument('files', $helper->ask($input, $output, $question));
 }
开发者ID:nanbando,项目名称:core,代码行数:31,代码来源:FetchCommand.php

示例5: testAskChoice

    public function testAskChoice()
    {
        $questionHelper = new SymfonyQuestionHelper();

        $helperSet = new HelperSet(array(new FormatterHelper()));
        $questionHelper->setHelperSet($helperSet);

        $heroes = array('Superman', 'Batman', 'Spiderman');

        $inputStream = $this->getInputStream("\n1\n  1  \nFabien\n1\nFabien\n1\n0,2\n 0 , 2  \n\n\n");

        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '2');
        $question->setMaxAttempts(1);
        // first answer is an empty answer, we're supposed to receive the default value
        $this->assertEquals('Spiderman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question));
        $this->assertOutputContains('What is your favorite superhero? [Spiderman]', $output);

        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes);
        $question->setMaxAttempts(1);
        $this->assertEquals('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
        $this->assertEquals('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));

        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes);
        $question->setErrorMessage('Input "%s" is not a superhero!');
        $question->setMaxAttempts(2);
        $this->assertEquals('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question));
        $this->assertOutputContains('Input "Fabien" is not a superhero!', $output);

        try {
            $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '1');
            $question->setMaxAttempts(1);
            $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question);
            $this->fail();
        } catch (\InvalidArgumentException $e) {
            $this->assertEquals('Value "Fabien" is invalid', $e->getMessage());
        }

        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
        $question->setMaxAttempts(1);
        $question->setMultiselect(true);

        $this->assertEquals(array('Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
        $this->assertEquals(array('Superman', 'Spiderman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
        $this->assertEquals(array('Superman', 'Spiderman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));

        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0,1');
        $question->setMaxAttempts(1);
        $question->setMultiselect(true);

        $this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question));
        $this->assertOutputContains('What is your favorite superhero? [Superman, Batman]', $output);

        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, ' 0 , 1 ');
        $question->setMaxAttempts(1);
        $question->setMultiselect(true);

        $this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream), $output = $this->createOutputInterface(), $question));
        $this->assertOutputContains('What is your favorite superhero? [Superman, Batman]', $output);
    }
开发者ID:symfony,项目名称:symfony,代码行数:59,代码来源:SymfonyQuestionHelperTest.php

示例6: interact

 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $instance = $input->getArgument('instance');
     if (empty($instance)) {
         // find instances based on tag(s)
         $tags = $input->getOption('tag');
         $tags = $this->convertTags($tags);
         $repository = new Repository();
         $instanceCollection = $repository->findEc2InstancesByTags($tags);
         $count = count($instanceCollection);
         if ($count == 0) {
             throw new \Exception('No instance found matching the given tags');
         } elseif ($count == 1) {
             $instanceObj = $instanceCollection->getFirst();
             /* @var $instanceObj Instance */
             $input->setArgument('instance', $instanceObj->getInstanceId());
         } else {
             $mapping = [];
             // dynamically add current tags
             foreach (array_keys($tags) as $tagName) {
                 $mapping[$tagName] = 'Tags[?Key==`' . $tagName . '`].Value | [0]';
             }
             foreach ($input->getOption('column') as $tagName) {
                 $mapping[$tagName] = 'Tags[?Key==`' . $tagName . '`].Value | [0]';
             }
             $labels = [];
             foreach ($instanceCollection as $instanceObj) {
                 /* @var $instanceObj Instance */
                 $instanceLabel = $instanceObj->getInstanceId();
                 $tmp = [];
                 foreach ($instanceObj->extractData($mapping) as $field => $value) {
                     if (!empty($value)) {
                         $tmp[] = "{$field}: {$value}";
                     }
                 }
                 if (count($tmp)) {
                     $labels[] = $instanceLabel . ' (' . implode('; ', $tmp) . ')';
                 } else {
                     $labels[] = $instanceLabel;
                 }
             }
             $helper = $this->getHelper('question');
             $question = new ChoiceQuestion('Please select an instance', $labels);
             $question->setErrorMessage('Instance %s is invalid.');
             $instance = $helper->ask($input, $output, $question);
             $output->writeln('Selected Instance: ' . $instance);
             list($instance) = explode(' ', $instance);
             $input->setArgument('instance', $instance);
         }
     }
     if (!$input->getOption('force')) {
         $helper = $this->getHelper('question');
         $question = new ConfirmationQuestion("Are you sure you want to terminate following instance? {$instance} [y/N] ", false);
         if (!$helper->ask($input, $output, $question)) {
             throw new \Exception('Operation aborted');
         }
         $input->setOption('force', true);
     }
 }
开发者ID:aoepeople,项目名称:stackformation,代码行数:59,代码来源:TerminateCommand.php

示例7: __construct

 public function __construct()
 {
     if (!$this->validate(App::get('in')->getOption('environment'))) {
         $question = new ChoiceQuestion('Do you want a development, test, or production environment?', ['development', 'test', 'production'], 'development');
         $question->setErrorMessage('%s is invalid.');
         $this->validate(App::get('io')->question($question));
     }
     App::get('io')->write("<comment>environment:</> <info>{$this->environment}</>");
 }
开发者ID:jeff-puckett,项目名称:mysql-dtp,代码行数:9,代码来源:Environment.php

示例8: choice

 public function choice($question, $choices, $default = null, $errorMessage = null)
 {
     /** @var QuestionHelper $q */
     $q = $this->getHelper('question');
     if (!$question instanceof ChoiceQuestion) {
         $question = new ChoiceQuestion($question, $choices, $default);
     }
     if ($errorMessage !== null) {
         $question->setErrorMessage($errorMessage);
     }
     return $q->ask($this->in, $this->out, $question);
 }
开发者ID:afflicto,项目名称:webdev,代码行数:12,代码来源:Command.php

示例9: interact

 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $profile = $input->getArgument('profile');
     if (empty($profile)) {
         $profileManager = new Manager();
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('Please select the profile you want to use', $profileManager->listAllProfiles());
         $question->setErrorMessage('Profile %s is invalid.');
         $profile = $helper->ask($input, $output, $question);
         $output->writeln('Selected Profile: ' . $profile);
         $input->setArgument('profile', $profile);
     }
 }
开发者ID:aoepeople,项目名称:stackformation,代码行数:13,代码来源:EnableCommand.php

示例10: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var RestaurantRepository $restaurantRepository */
     $restaurantRepository = $this->entityManager->getRepository('SlackOrder\\Entity\\Restaurant');
     /** @var Restaurant $restaurant */
     $restaurant = $restaurantRepository->findOneBy(['command' => $input->getArgument('commandName')]);
     if (null === $restaurant) {
         throw new \InvalidArgumentException('This command doesn\'t exists.');
     }
     $helper = $this->getHelper('question');
     $question = new ChoiceQuestion('Witch field do you want to set ?', ['Token', 'Start hour', 'End hour', 'Phone number', 'Email', 'Name', 'Example', 'Sender email', 'Send order by email [0/1]'], 0);
     $question->setErrorMessage('Invalid field %s.');
     $field = $helper->ask($input, $output, $question);
     $newValueQuestion = new Question(sprintf('The new value of %s : ', $field));
     $newValue = $helper->ask($input, $output, $newValueQuestion);
     switch ($field) {
         case 'Token':
             $restaurant->setToken($newValue);
             break;
         case 'Start hour':
             $restaurant->setStartHour($newValue);
             break;
         case 'End hour':
             $restaurant->setEndHour($newValue);
             break;
         case 'Phone number':
             $restaurant->setPhoneNumber($newValue);
             break;
         case 'Email':
             $restaurant->setEmail($newValue);
             break;
         case 'Name':
             $restaurant->setName($newValue);
             break;
         case 'Url menu':
             $restaurant->setUrlMenu($newValue);
             break;
         case 'Example':
             $restaurant->setExample($newValue);
             break;
         case 'Sender email':
             $restaurant->setSenderEmail($newValue);
             break;
         case 'Send order by email [0/1]':
             $restaurant->setSendOrderByEmail($newValue);
             break;
     }
     $this->validateRestaurant($restaurant);
     $this->entityManager->persist($restaurant);
     $this->entityManager->flush();
 }
开发者ID:pCyril,项目名称:slack-order,代码行数:51,代码来源:UpdateRestaurantCommand.php

示例11: execute

 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $template = $input->getArgument('template');
     $directory = $input->getOption('directory');
     $file = $input->getOption('filename');
     if ($template === null) {
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('Please select your project type (defaults to common):', $this->availableTemplates, 0);
         $question->setErrorMessage('Color %s is invalid.');
         $template = $helper->ask($input, $output, $question);
     }
     $filePath = $this->initializer->initialize($template, $directory, $file);
     $output->writeln(sprintf('<comment>Successfully create deployer configuration: <info>%s</info></comment>', $filePath));
 }
开发者ID:xing393939,项目名称:Laravel-5-Bootstrap-3-Starter-Site,代码行数:17,代码来源:InitCommand.php

示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $config = ['email' => null, 'password' => null, 'user.agent' => null, 'proxy.http' => null];
     // E-mail question
     $question = new Question('eRepublik account e-mail: ');
     $question->setValidator(function ($answer) {
         if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
             throw new \RuntimeException("This is not a valid e-mail address.");
         }
         return $answer;
     });
     $question->setMaxAttempts(2);
     $config['email'] = $helper->ask($input, $output, $question);
     // Password question
     $question = new Question('eRepublik password: ');
     $question->setValidator(function ($answer) {
         if (empty($answer)) {
             throw new \RuntimeException("Password cannot be empty.");
         }
         return $answer;
     });
     $question->setMaxAttempts(2);
     $config['password'] = $helper->ask($input, $output, $question);
     // User-Agent question
     $question = new Question('What User-Agent string to use (you can leave it empty): ');
     $config['user.agent'] = $helper->ask($input, $output, $question);
     // Type of proxy question
     $question = new ChoiceQuestion('What kind of proxy do you want to use: ', ['No proxy at all (default)', 'HTTP proxy']);
     $question->setMaxAttempts(2);
     $question->setErrorMessage('Proxy %s is invalid.');
     $proxyType = $helper->ask($input, $output, $question);
     switch ($proxyType) {
         case 'HTTP proxy':
             $question = new Question('HTTP proxy (ip:port:username:password): ');
             $question->setValidator(function ($answer) {
                 if (empty($answer)) {
                     throw new \RuntimeException("Proxy cannot be empty.");
                 }
                 return $answer;
             });
             $question->setMaxAttempts(2);
             $config['proxy.http'] = $helper->ask($input, $output, $question);
             break;
     }
     $configPath = $this->getApplication()->getConfigPath();
     file_put_contents($configPath, json_encode($config));
     $output->writeln('Config file has been written to ' . realpath($configPath));
 }
开发者ID:erpk,项目名称:erbot,代码行数:49,代码来源:ConfigureCommand.php

示例13: interactAskForJob

 protected function interactAskForJob(InputInterface $input, OutputInterface $output)
 {
     $job = $input->getArgument('job');
     if (empty($job)) {
         $api = new Api();
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('Please select a job', $api->getAllJobs());
         $question->setErrorMessage('Job %s is invalid.');
         $job = $helper->ask($input, $output, $question);
         $output->writeln('Selected Job: ' . $job);
         list($stackName) = explode(' ', $job);
         $input->setArgument('job', $stackName);
     }
     return $job;
 }
开发者ID:AOEpeople,项目名称:JenkinsCli,代码行数:15,代码来源:AbstractCommand.php

示例14: interact

 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     if ($input->getArgument('file')) {
         return;
     }
     /** @var StorageInterface $storage */
     $storage = $this->getContainer()->get('storage');
     $localFiles = $storage->localListing();
     $helper = $this->getHelper('question');
     $question = new ChoiceQuestion('Which backup', $localFiles);
     $question->setErrorMessage('Backup %s is invalid.');
     $question->setAutocompleterValues([]);
     $input->setArgument('file', $helper->ask($input, $output, $question));
     $output->writeln('');
 }
开发者ID:nanbando,项目名称:core,代码行数:18,代码来源:RestoreCommand.php

示例15: execute

 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $templateList = $this->getTemplatesList($this->findTemplates());
     $prettyTemplateList = $this->formatTemplatesList($templateList);
     $helper = $this->getHelper('question');
     $question = new ChoiceQuestion('What kind of template, You would like to create?', $prettyTemplateList);
     $question->setErrorMessage('Template %s is invalid');
     $selectedTemplate = $helper->ask($input, $output, $question);
     // find a key for selected template
     $key = array_search($selectedTemplate, $prettyTemplateList);
     $templateDirectoryName = $templateList[$key];
     $targetPath = $input->getArgument(self::ARGUMENT_PATH_NAME);
     $this->createTemplate($templateDirectoryName, $targetPath);
     $output->writeln(sprintf('<comment>%s</comment> created into <info>%s</info>', $selectedTemplate, $targetPath));
 }
开发者ID:bszala,项目名称:scaffold,代码行数:18,代码来源:TemplateCommand.php


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