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


PHP Question\Question类代码示例

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


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

示例1: doIt

 /**
  * @param   InputInterface            $input  An InputInterface instance
  * @param   OutputInterface           $output An OutputInterface instance
  * @param   CollectionFinderInterface $finder The finder
  * @param   string                    $entity The entity name
  *
  * @return  void
  */
 protected function doIt(InputInterface $input, OutputInterface $output, $finder, $entity)
 {
     $count = 0;
     $force = $input->getOption('no-interaction');
     $repository = $this->repositoryFactory->forEntity($entity);
     $idAccessorRegistry = $this->repositoryFactory->getIdAccessorRegistry();
     foreach ($this->getRecords($finder) as $record) {
         $id = $idAccessorRegistry->getEntityId($record);
         $choice = 'no';
         if (!$force) {
             $question = new Question("Delete {$entity} #{$id} (yes,No,all)? ", 'no');
             $question->setAutocompleterValues(['yes', 'no', 'all']);
             $choice = $this->ask($input, $output, $question);
             if ($choice == 'all') {
                 $force = true;
             }
         }
         if ($force || $choice == 'yes') {
             $repository->remove($record);
             $count++;
         }
     }
     $repository->commit();
     $this->writeln($output, "Deleted {$count} {$entity} item(s).");
 }
开发者ID:nibra,项目名称:joomla-pythagoras,代码行数:33,代码来源:DeleteCommand.php

示例2: interact

 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the Doctrine2 CRUD generator');
     // namespace
     $output->writeln(array('', 'This command helps you generate CRUD controllers and templates.', '', 'First, you need to give the entity for which you want to generate a CRUD.', 'You can give an entity that does not exist yet and the wizard will help', 'you defining it.', '', 'You must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>.', ''));
     if ($input->hasArgument('entity') && $input->getArgument('entity') != '') {
         $input->setOption('entity', $input->getArgument('entity'));
     }
     $question = new Question($questionHelper->getQuestion('The Entity shortcut name', $input->getOption('entity')), $input->getOption('entity'));
     $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName'));
     $autocompleter = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager());
     $autocompleteEntities = $autocompleter->getSuggestions();
     $question->setAutocompleterValues($autocompleteEntities);
     $entity = $questionHelper->ask($input, $output, $question);
     $input->setOption('entity', $entity);
     list($bundle, $entity) = $this->parseShortcutNotation($entity);
     // write?
     $withWrite = 'yes';
     $input->setOption('with-write', $withWrite);
     // format
     $format = 'annotation';
     $input->setOption('format', $format);
     // route prefix
     $prefix = $this->getRoutePrefix($input, $entity);
     $output->writeln(array('', 'Determine the routes prefix (all the routes will be "mounted" under this', 'prefix: /prefix/, /prefix/new, ...).', ''));
     $prefix = $questionHelper->ask($input, $output, new Question($questionHelper->getQuestion('Routes prefix', '/' . $prefix), '/' . $prefix));
     $input->setOption('route-prefix', $prefix);
     // summary
     $output->writeln(array('', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf("You are going to generate a CRUD controller for \"<info>%s:%s</info>\"", $bundle, $entity), sprintf("using the \"<info>%s</info>\" format.", $format), ''));
 }
开发者ID:blacksad12,项目名称:oliorga,代码行数:31,代码来源:GenerateDoctrineCrudCommand.php

示例3: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $login = $input->getArgument("login");
     $helper = $this->getHelper('question');
     $question = new Question("Unix password for « {$login} » : ");
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $password = $input->getArgument("password") ? $input->getArgument("password") : $helper->ask($input, $output, $question);
     $blih = new Blih($login, $password);
     $blihRepositoriesResponse = $blih->repository()->all();
     if ($blihRepositoriesResponse->code == 200) {
         $user = $this->getUserOrCreateIt($login);
         $repositoryNames = array_keys(get_object_vars($blihRepositoriesResponse->body->repositories));
         foreach ($repositoryNames as $repositoryName) {
             $output->writeln("> Repository « {$login}/{$repositoryName} »");
             $repository = $this->getRepoOrCreateIt($user, $repositoryName);
             $aclResponse = $blih->repository($repositoryName)->acl()->get();
             if ($aclResponse->code == 200) {
                 $acls = get_object_vars($aclResponse->body);
                 foreach ($acls as $aclLogin => $acl) {
                     $output->writeln("  ACL for « {$aclLogin} »: {$acl}");
                     $aclUser = $this->getUserOrCreateIt($aclLogin);
                     $repositoryACL = $this->getACLOrCreateIt($aclUser, $repository);
                     $repositoryACL->setR(strpos($acl, "r") !== false);
                     $repositoryACL->setW(strpos($acl, "w") !== false);
                     $repositoryACL->setA(strpos($acl, "a") !== false);
                     $this->getContainer()->get("doctrine")->getManager()->persist($repositoryACL);
                 }
             }
             $output->writeln("");
             $this->getContainer()->get("doctrine")->getManager()->persist($repository);
             $this->getContainer()->get("doctrine")->getManager()->flush();
         }
     }
 }
开发者ID:Raphy,项目名称:BlihWI,代码行数:35,代码来源:BlihUpdateCommand.php

示例4: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption("password")) {
         $password = $input->getOption("password");
     } else {
         $question = new Question('Password: ');
         $question->setHidden(true);
         $question->setHiddenFallback(false);
         $helper = $this->getHelper('question');
         $password = $helper->ask($input, $output, $question);
     }
     $server = new Server\Database\Mysql();
     $server->setHostname($input->getArgument("host"));
     $server->setUser("provisioning");
     $server->setPassword($this->createPassword());
     $server->setDatabase("provisioning");
     $server->setMode($input->getArgument("mode"));
     $server->setType($input->getArgument("type"));
     $server->setActive(false);
     // convert errors to PDOExceptions
     $options = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION];
     $dsn = sprintf("mysql:host=%s;port=%s;charset=utf8", $server->getHostname(), 3306);
     $pdo = new \PDO($dsn, $input->getArgument("user"), $password, $options);
     $pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
     $pdo->exec("SET NAMES utf8;");
     $pdo->exec("CREATE USER '{$server->getUser()}'@'%' IDENTIFIED BY '{$server->getPassword()}';");
     $pdo->exec("GRANT CREATE, DROP, GRANT OPTION, LOCK TABLES, REFERENCES, EVENT, ALTER, DELETE, INDEX, INSERT, SELECT, UPDATE, CREATE TEMPORARY TABLES, TRIGGER, CREATE VIEW, SHOW VIEW, ALTER ROUTINE, CREATE ROUTINE, EXECUTE, CREATE USER, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SHOW DATABASES, USAGE ON *.* TO '{$server->getUser()}' WITH GRANT OPTION;");
     $pdo->exec("CREATE DATABASE {$server->getDatabase()} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;");
     // Write to DB
     $entityManager = $this->getProvisioningServer("mysql")->getEntityManager();
     $entityManager->persist($server);
     $entityManager->flush();
     $table = $this->getMySqlServersTable([$server], $output);
     $table->render();
 }
开发者ID:keboola,项目名称:provisioning-bundle,代码行数:35,代码来源:InitMysqlServerCommand.php

示例5: buildAuthorQuestion

 /**
  * @return SimpleQuestion
  */
 private function buildAuthorQuestion()
 {
     $question = new SimpleQuestion('<question>Enter the author (name <mail@mail.com>):</question>');
     $question->setValidator($this->buildValidator());
     $question->setMaxAttempts(3);
     return $question;
 }
开发者ID:raphhh,项目名称:samurai,代码行数:10,代码来源:AuthorQuestion.php

示例6: interact

 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     if (trim($input->getOption('name')) == '') {
         $question = new Question\Question('Please enter the client name: ');
         $question->setValidator(function ($value) {
             if (trim($value) == '') {
                 throw new \Exception('The client name can not be empty');
             }
             $doctrine = $this->getContainer()->get('doctrine');
             $client = $doctrine->getRepository('AppBundle:Client')->findOneBy(['name' => $value]);
             if ($client instanceof \AppBundle\Entity\Client) {
                 throw new \Exception('The client name must be unique');
             }
             return $value;
         });
         $question->setMaxAttempts(5);
         $input->setOption('name', $helper->ask($input, $output, $question));
     }
     $grants = $input->getOption('grant-type');
     if (!(is_array($grants) && count($grants))) {
         $question = new Question\ChoiceQuestion('Please select the grant types (defaults to password and facebook_access_token): ', [\OAuth2\OAuth2::GRANT_TYPE_AUTH_CODE, \OAuth2\OAuth2::GRANT_TYPE_CLIENT_CREDENTIALS, \OAuth2\OAuth2::GRANT_TYPE_EXTENSIONS, \OAuth2\OAuth2::GRANT_TYPE_IMPLICIT, \OAuth2\OAuth2::GRANT_TYPE_REFRESH_TOKEN, \OAuth2\OAuth2::GRANT_TYPE_USER_CREDENTIALS, 'http://grants.api.schoolmanager.ledo.eu.org/facebook_access_token'], '5,6');
         $question->setMultiselect(true);
         $question->setMaxAttempts(5);
         $input->setOption('grant-type', $helper->ask($input, $output, $question));
     }
     parent::interact($input, $output);
 }
开发者ID:eduardoledo,项目名称:schoolmanager,代码行数:28,代码来源:ClientCreateCommand.php

示例7: execute

 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $username = $helper->ask($input, $output, new Question('Username: '));
     if (!$username) {
         $output->writeln("<error>Invalid username</error>");
         return;
     }
     $pw_question = new Question('Password: ');
     $pw_question->setHidden(true);
     $password = $helper->ask($input, $output, $pw_question);
     if (!$password) {
         $output->writeln("<error>Invalid password</error>");
         return;
     }
     $roles = $this->getRoles(null, $input, $output);
     $output->writeln('Username: <info>' . $username . '</info>');
     $output->writeln('Roles:    <info>' . implode(', ', $roles) . '</info>');
     $this->showRoleWarnings($roles, $output);
     if (!$helper->ask($input, $output, new ConfirmationQuestion('Create user? [y/N]: ', false))) {
         return;
     }
     $provider = $this->getContainer()->get('orm.user_provider');
     $provider->createUser($username, $password, $roles);
     $output->writeln("Created new user");
 }
开发者ID:bravo3,项目名称:orm-bundle,代码行数:31,代码来源:CreateUserCommand.php

示例8: execute

 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $name = $input->getArgument('name');
     $email = $input->getOption('email');
     $pass = $input->getOption('password');
     $roles = explode(",", $input->getOption('roles'));
     $helper = $this->getHelper('question');
     if (!$email) {
         $question = new Question('Please enter a email address : ', 'email');
         $email = $helper->ask($input, $output, $question);
     }
     if (!$pass) {
         $question = new Question('Please enter a password : ', 'password');
         $question->setHidden(true);
         $question->setHiddenFallback(false);
         $pass = $helper->ask($input, $output, $question);
     }
     if (!\ProcessWire\wire("pages")->get("name={$name}") instanceof \ProcessWire\NullPage) {
         $output->writeln("<error>User '{$name}' already exists!</error>");
         exit(1);
     }
     $user = $this->createUser($email, $name, $this->userContainer, $pass);
     $user->save();
     if ($input->getOption('roles')) {
         $this->attachRolesToUser($name, $roles, $output);
     }
     if ($pass) {
         $output->writeln("<info>User '{$name}' created successfully!</info>");
     } else {
         $output->writeln("<info>User '{$name}' created successfully! Please do not forget to set a password.</info>");
     }
 }
开发者ID:wireshell,项目名称:wireshell,代码行数:38,代码来源:UserCreateCommand.php

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

示例10: interact

 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getHelper('question');
     $question = new Question($this->getQuestion('Enter a comma separated list of the models you want to create the pivot table for', $input->getOption('models')), $input->getOption('models'));
     $question->setValidator(function ($answer) {
         $answer = array_map(function ($el) {
             return trim($el);
         }, explode(',', $answer));
         if (2 != count($answer)) {
             throw new \RuntimeException('This Option requires exactly 2 models');
         }
         return $answer;
     });
     $question->setMaxAttempts(3);
     $models = $questionHelper->ask($input, $output, $question);
     $table = $input->getOption('table');
     if (!$table) {
         $table = 'tl_' . strtolower($models[0]) . '_' . strtolower($models[1]);
     }
     $question = new Question($this->getQuestion('Enter the name of the table being created', $table), $table);
     $question->setValidator(function ($answer) {
         if ('tl_' !== substr($answer, 0, 3)) {
             throw new \RuntimeException('The name of the table should be prefixed with \'tl_\'');
         }
         return $answer;
     });
     $question->setMaxAttempts(3);
     $table = $questionHelper->ask($input, $output, $question);
     $question = new Question($this->getQuestion('Enter the relative path to your contao bundle', './src'), './src');
     $base = $questionHelper->ask($input, $output, $question);
     $this->parameters = ['models' => $models, 'table' => $table, 'base' => $base];
 }
开发者ID:fuzzyma,项目名称:contao-eloquent-bundle,代码行数:32,代码来源:CreateDCAForPivotCommand.php

示例11: execute

 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $secret = $input->getArgument('secret');
     if (empty($secret)) {
         /** @var QuestionHelper $dialog */
         $helper = $this->getHelper('question');
         $question = new Question('<question>The secret to share</question>: ');
         $secret = $helper->ask($input, $output, $question);
         $question = new Question('<question>Number of shared secrets to create</question> <comment>[3]</comment>: ', 3);
         $question->setValidator(function ($a) {
             if (!is_int($a) && !ctype_digit($a)) {
                 throw new \Exception('The number of shared secrets must be an integer');
             }
             return (int) $a;
         });
         $shares = $helper->ask($input, $output, $question);
         $question = new Question('<question>Number of shared secrets required</question> <comment>[2]</comment>: ', 2);
         $question->setValidator(function ($a) {
             if (!is_int($a) && !ctype_digit($a)) {
                 throw new \Exception('The number of shared secrets required must be an integer');
             }
             return (int) $a;
         });
         $threshold = $helper->ask($input, $output, $question);
     } else {
         $shares = $input->getOption('shares');
         $threshold = $input->getOption('threshold');
     }
     $shared = Secret::share($secret, $shares, $threshold);
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     $block = $formatter->formatBlock($shared, 'info', true);
     $output->writeln($block);
 }
开发者ID:teqneers,项目名称:shamir,代码行数:37,代码来源:ShareCommand.php

示例12: execute

 /**
  * Execute the command
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $db = $input->getOption('db');
     if (empty($db)) {
         throw new \InvalidArgumentException('You must define the database name with --db');
     }
     $password = $input->getOption('password');
     if (is_null($password)) {
         $helper = $this->getHelper('question');
         $question = new Question('Password: ');
         $question->setHidden(true);
         $question->setHiddenFallback(false);
         $password = $helper->ask($input, $output, $question);
     }
     try {
         $pdo = new \PDO("mysql:dbname={$db};host=" . $input->getOption('host'), $input->getOption('user'), $password);
     } catch (\Exception $e) {
         throw new \RuntimeException("Can't connect to the database. Check your credentials");
     }
     $writer = new \Inet\Neuralyzer\Configuration\Writer();
     $ignoreFields = $input->getOption('ignore-field');
     $writer->protectCols($input->getOption('protect'));
     // Override the protection if fields are defined
     if (!empty($ignoreFields)) {
         $writer->protectCols(true);
         $writer->setProtectedCols($ignoreFields);
     }
     $writer->setIgnoredTables($input->getOption('ignore-table'));
     $data = $writer->generateConfFromDB($pdo, new \Inet\Neuralyzer\Guesser());
     $writer->save($data, $input->getOption('file'));
     $output->writeln('<comment>Configuration written to ' . $input->getOption('file') . '</comment>');
 }
开发者ID:inetprocess,项目名称:neuralyzer,代码行数:40,代码来源:ConfigGenerateCommand.php

示例13: handle

 public function handle(InputInterface $input, OutputInterface $output)
 {
     $data = [];
     $helper = $this->command->getHelper('question');
     $data['jiraHost'] = $helper->ask($input, $output, new Question('Domain (yourdomain.atlassian.net): ', false));
     $data['jiraUser'] = $helper->ask($input, $output, new Question('Username: ', false));
     $passwordQuestion = new Question('Password: ', false);
     $passwordQuestion->setHidden(true)->setHiddenFallback(false);
     $password = $helper->ask($input, $output, $passwordQuestion);
     //        $passwordQuestion2 = new Question('Confirm Password: ', false);
     //        $passwordQuestion2->setHidden(true)->setHiddenFallback(false);
     //        $password2 = $helper->ask($input, $output, $passwordQuestion2);
     //        if (empty($password) || empty($password2)) {
     //            throw new \RuntimeException('Password cannot be blank');
     //        }
     //
     //        if ($password !== $password2) {
     //            throw new \RuntimeException('Passwords must match.');
     //        }
     $data['jiraPassword'] = $password;
     if ($this->config->write($data) !== false) {
         $output->writeln('Config written to file: ' . $this->config->filePath());
     } else {
         $output->writeln('Nothing written..');
     }
 }
开发者ID:humweb,项目名称:slackpipe,代码行数:26,代码来源:SetupCommand.php

示例14: interact

 /**
  *
  * TODO Provide extensibility to list of Sugar 7 boxes (allow hard coding, usage of a web service, etc.)
  * {inheritDoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $box = $input->getArgument('box');
     if (empty($box)) {
         $output->writeln('You MUST provide a <info>Vagrant Box Name</info> for your Sugar instance.');
         $output->writeln('<comment>You may pick one from below OR provide your own.</comment>');
         $table = new Table($output);
         $table->setHeaders(array('Box Name', 'PHP', 'Apache', 'MySQL', 'Elasticsearch', 'OS'));
         $table->addRow(['mmarum/sugar7-php54', '5.4.x', '2.2.x', '5.5.x', '1.4.x', 'Ubuntu 12.04']);
         $table->addRow(['mmarum/sugar7-php53', '5.3.x', '2.2.x', '5.5.x', '1.4.x', 'Ubuntu 12.04']);
         $table->render();
         $helper = $this->getHelper('question');
         $question = new Question('<info>Name of Vagrant Box?</info> <comment>[mmarum/sugar7-php54]</comment> ', 'mmarum/sugar7-php54');
         $question->setValidator(function ($answer) {
             if (empty($answer)) {
                 throw new \RuntimeException('You must provide a Box Name to continue!');
             }
             return $answer;
         });
         $question->setMaxAttempts(2);
         $box = $helper->ask($input, $output, $question);
         $input->setArgument('box', $box);
     }
     $output->writeln("<info>Using {$box} ...</info>");
 }
开发者ID:mmarum-sugarcrm,项目名称:cli-tools,代码行数:30,代码来源:VagrantQuickstart.php

示例15: interact

 /**
  * @see Command
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questions = array();
     if (!$input->getArgument('username')) {
         $question = new Question('Please give the username:');
         $question->setValidator(function ($username) {
             if (empty($username)) {
                 throw new \Exception('Username can not be empty');
             }
             return $username;
         });
         $questions['username'] = $question;
     }
     if (!$input->getArgument('password')) {
         $question = new Question('Please enter the new password:');
         $question->setValidator(function ($password) {
             if (empty($password)) {
                 throw new \Exception('Password can not be empty');
             }
             return $password;
         });
         $question->setHidden(true);
         $questions['password'] = $question;
     }
     foreach ($questions as $name => $question) {
         $answer = $this->getHelper('question')->ask($input, $output, $question);
         $input->setArgument($name, $answer);
     }
 }
开发者ID:ismailbaskin,项目名称:FOSUserBundle,代码行数:32,代码来源:ChangePasswordCommand.php


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