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


PHP SymfonyStyle::ask方法代码示例

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


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

示例1: interact

 public function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $bundle = $input->getArgument('bundle');
     $name = $input->getArgument('name');
     $container = $this->getContainer();
     if (null !== $bundle && null !== $name) {
         return;
     }
     $io->title('Generate new RPC method');
     // Bundle name
     $bundle = $io->ask('Bundle name', null, function ($answer) use($container) {
         try {
             $container->get('kernel')->getBundle($answer);
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('Bundle "%s" does not exist.', $answer));
         }
         return $answer;
     });
     $input->setArgument('bundle', $bundle);
     // Method name
     $name = $io->ask('Method name', null, function ($answer) use($container, $bundle) {
         if (empty($answer)) {
             throw new \RuntimeException('Method name can`t be empty.');
         }
         $answer = str_replace(' ', ':', $answer);
         if ($this->isMethodExist($container->get('kernel')->getBundle($bundle), $answer)) {
             throw new \RuntimeException(sprintf('Method "%s" already exist.', $answer));
         }
         return $answer;
     });
     $input->setArgument('name', $name);
 }
开发者ID:timiki,项目名称:rpc-server-bundle,代码行数:33,代码来源:GenerateMethodCommand.php

示例2: interact

 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     foreach ($input->getOptions() as $option => $value) {
         if ($value === null) {
             $input->setOption($option, $this->io->ask(sprintf('%s', ucfirst($option))));
         }
     }
 }
开发者ID:symfony,项目名称:swiftmailer-bundle,代码行数:11,代码来源:NewEmailCommand.php

示例3: interact

 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     // --title option
     if (!$input->getOption('title')) {
         $input->setOption('title', $io->ask('Enter the title of the post'));
     }
     // --fieldname option
     if (!$input->getOption('filename')) {
         $date = \DateTime::createFromFormat('U', time())->format('Y-m-d');
         $input->setOption('filename', $io->ask('Enter the name of the file', $date . self::FILENAME_SEPARATOR . str_replace(' ', self::FILENAME_SEPARATOR, strtolower($input->getOption('title'))) . '.' . self::FILETYPE));
     }
 }
开发者ID:opdavies,项目名称:sculpin-content-generator-bundle,代码行数:16,代码来源:NewPostCommand.php

示例4: loadConfiguration

 /**
  * Loads the local configuration from "~/.localhook/config.json" file.
  */
 protected function loadConfiguration()
 {
     try {
         $configuration = $this->configurationStorage->loadFromFile()->get();
     } catch (NoConfigurationException $e) {
         $this->io->comment($e->getMessage());
         if (!$this->secret) {
             $this->secret = $this->io->ask('Secret');
         }
         $configuration = $this->parseConfigurationKey();
     }
     $this->serverUrl = $configuration['socket_url'];
     $this->secret = $configuration['secret'];
     $this->configurationStorage->merge($configuration)->save();
 }
开发者ID:localhook,项目名称:localhook,代码行数:18,代码来源:AbstractCommand.php

示例5: 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;
 }
开发者ID:forkcms,项目名称:forkcms,代码行数:30,代码来源:EnableLocaleCommand.php

示例6: interact

 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     // --title option
     if (!$input->getOption('title')) {
         $input->setOption('title', $io->ask('Enter the title of the page'));
     }
     // --extension option
     if (!$input->getOption('extension')) {
         $input->setOption('extension', $io->choice('Which file extension?', ['md', 'html.twig', 'twig', 'html']));
     }
     // --fieldname option
     if (!$input->getOption('filename')) {
         $input->setOption('filename', $io->ask('Enter the name of the file', str_replace(' ', self::FILENAME_SEPARATOR, strtolower($input->getOption('title'))) . '.' . $input->getOption('extension')));
     }
 }
开发者ID:opdavies,项目名称:sculpin-content-generator-bundle,代码行数:19,代码来源:NewPageCommand.php

示例7: 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);
 }
开发者ID:edetaillac,项目名称:static-review,代码行数:49,代码来源:HookInstallCommand.php

示例8: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $jwt = $this->getContainer()->get('jwt_coder');
     $username = $input->getArgument('username');
     if (!$username) {
         $username = $io->ask('Username');
     }
     $io->text('Token: ' . $jwt->encode(['username' => $username]));
     $io->success('JWT created');
 }
开发者ID:tuimedia,项目名称:forum,代码行数:11,代码来源:GenerateTokenCommand.php

示例9: askAppBasePath

 protected function askAppBasePath($message, $default)
 {
     $appBasePath = $this->io->ask($message, $default);
     if ($appBasePath[0] === '~') {
         if (!function_exists('posix_getuid')) {
             throw new \InvalidArgumentException('cannot use tilde(~) character in your php enviroment.');
         }
         $info = posix_getpwuid(posix_getuid());
         $appBasePath = str_replace('~', $info['dir'], $appBasePath);
     }
     if ($appBasePath[0] !== '/') {
         $appBasePath = $this->basePath . "/{$appBasePath}";
     }
     return rtrim($appBasePath, '/');
 }
开发者ID:wandu,项目名称:framework,代码行数:15,代码来源:InstallCommand.php

示例10: 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;
 }
开发者ID:pmdevelopment,项目名称:tool-bundle,代码行数:25,代码来源:FOSUserCommand.php

示例11: ask

 /**
  * Prompt the user for input.
  *
  * @param  string $question
  * @param  string $default
  * @return string
  */
 public function ask($question, $default = null)
 {
     return $this->output->ask($question, $default);
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:11,代码来源:Command.php

示例12: testSymfonyStyleCommandWithInputs

 public function testSymfonyStyleCommandWithInputs()
 {
     $questions = array('What\'s your name?', 'How are you?', 'Where do you come from?');
     $command = new Command('foo');
     $command->setCode(function ($input, $output) use($questions, $command) {
         $io = new SymfonyStyle($input, $output);
         $io->ask($questions[0]);
         $io->ask($questions[1]);
         $io->ask($questions[2]);
     });
     $tester = new CommandTester($command);
     $tester->setInputs(array('Bobby', 'Fine', 'France'));
     $tester->execute(array());
     $this->assertEquals(0, $tester->getStatusCode());
 }
开发者ID:Gladhon,项目名称:symfony,代码行数:15,代码来源:CommandTesterTest.php

示例13: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output = new SymfonyStyle($input, $output);
     if (!extension_loaded('pcntl')) {
         $output->error(array('This command needs the pcntl extension to run.', 'You can either install it or use the "server:run" command instead to run the built-in web server.'));
         if ($output->ask('Do you want to execute <info>server:run</info> immediately? [Yn] ', true)) {
             $command = $this->getApplication()->find('server:run');
             return $command->run($input, $output);
         }
         return 1;
     }
     $documentRoot = $input->getOption('docroot');
     if (null === $documentRoot) {
         $documentRoot = $this->getContainer()->getParameter('kernel.root_dir') . '/../web';
     }
     if (!is_dir($documentRoot)) {
         $output->error(sprintf('The given document root directory "%s" does not exist.', $documentRoot));
         return 1;
     }
     $env = $this->getContainer()->getParameter('kernel.environment');
     if (false === ($router = $this->determineRouterScript($input->getOption('router'), $env, $output))) {
         return 1;
     }
     $address = $input->getArgument('address');
     if (false === strpos($address, ':')) {
         $address = $address . ':' . $input->getOption('port');
     }
     if (!$input->getOption('force') && $this->isOtherServerProcessRunning($address)) {
         $output->error(array(sprintf('A process is already listening on http://%s.', $address), 'Use the --force option if the server process terminated unexpectedly to start a new web server process.'));
         return 1;
     }
     if ('prod' === $env) {
         $output->error('Running PHP built-in server in production environment is NOT recommended!');
     }
     $pid = pcntl_fork();
     if ($pid < 0) {
         $output->error('Unable to start the server process.');
         return 1;
     }
     if ($pid > 0) {
         $output->success(sprintf('Web server listening on http://%s', $address));
         return;
     }
     if (posix_setsid() < 0) {
         $output->error('Unable to set the child process as session leader');
         return 1;
     }
     if (null === ($process = $this->createServerProcess($output, $address, $documentRoot, $router))) {
         return 1;
     }
     $process->disableOutput();
     $process->start();
     $lockFile = $this->getLockFile($address);
     touch($lockFile);
     if (!$process->isRunning()) {
         $output->error('Unable to start the server process');
         unlink($lockFile);
         return 1;
     }
     // stop the web server when the lock file is removed
     while ($process->isRunning()) {
         if (!file_exists($lockFile)) {
             $process->stop();
         }
         sleep(1);
     }
 }
开发者ID:0mars,项目名称:symfony,代码行数:70,代码来源:ServerStartCommand.php

示例14: actionDatabaseImport

 /**
  * Database Import
  *
  * @param SymfonyStyle $helper
  *
  * @return null
  */
 private function actionDatabaseImport(SymfonyStyle $helper)
 {
     $timestamp = date('ymdHi');
     /*
      * Select Host
      */
     $remoteHost = $helper->ask('Remote host');
     /*
      * Select external database (default: database_name)
      */
     $remoteDatabase = $helper->ask('Remote database', $this->getContainer()->getParameter('database_name'));
     /*
      * Select local database (default: database_name)
      */
     $localDatabase = $helper->ask('New local database', sprintf('%s_%s', $this->getContainer()->getParameter('database_name'), $timestamp));
     /*
      * mysqldump
      */
     $fileName = sprintf('%s_%s_%s.sql', $remoteDatabase, $timestamp, uniqid());
     $command = sprintf('ssh %s "mysqldump %s > %s"', $remoteHost, $remoteDatabase, $fileName);
     $helper->comment($command);
     $process = new Process($command);
     $process->setTimeout(600);
     $process->run(function ($type, $buffer) use($helper) {
         if (Process::ERR === $type) {
             $helper->error($buffer);
             if (false !== strpos($buffer, 'Access denied')) {
                 $helper->note('Missing .my.cnf for mysql access?');
             }
         } else {
             $helper->comment($buffer);
         }
     });
     /*
      * scp
      */
     $command = sprintf('scp %s:%s %s/%s', $remoteHost, $fileName, sys_get_temp_dir(), $fileName);
     $helper->comment($command);
     $process = new Process($command);
     $process->setTimeout(300);
     $process->run(function ($type, $buffer) use($helper) {
         if (Process::ERR === $type) {
             $helper->error($buffer);
         } else {
             $helper->comment($buffer);
         }
     });
     /*
      * create database database_name_ymdHis
      * if exists: ask for drop
      */
     $command = sprintf('mysql -e "CREATE DATABASE %s;"', $localDatabase);
     $helper->comment($command);
     $process = new Process($command);
     $process->run(function ($type, $buffer) use($helper) {
         if (Process::ERR === $type) {
             $helper->error($buffer);
             if (false !== strpos($buffer, 'Access denied')) {
                 $helper->note('Missing .my.cnf for mysql access?');
             }
         } else {
             $helper->comment($buffer);
         }
     });
     /*
      * mysql -D database_name_ymdhis < /backup/y-m-d_H-i-s_unique.sql
      */
     $command = sprintf('mysql -D %s < %s/%s', $localDatabase, sys_get_temp_dir(), $fileName);
     $helper->comment($command);
     $process = new Process($command);
     $process->setTimeout(3600);
     $process->run(function ($type, $buffer) use($helper) {
         if (Process::ERR === $type) {
             $helper->error($buffer);
         } else {
             $helper->comment($buffer);
         }
     });
     /**
      * Remove
      */
     $command = sprintf('ssh %s "rm %s"', $remoteHost, $fileName);
     $helper->comment($command);
     $process = new Process($command);
     $process->run(function ($type, $buffer) use($helper) {
         if (Process::ERR === $type) {
             $helper->error($buffer);
         } else {
             $helper->comment($buffer);
         }
     });
     $command = sprintf('%s/%s', sys_get_temp_dir(), $fileName);
     $helper->comment(sprintf('unlink %s', $command));
//.........这里部分代码省略.........
开发者ID:pmdevelopment,项目名称:tool-bundle,代码行数:101,代码来源:DoctrineCommand.php

示例15: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     if (!extension_loaded('pcntl')) {
         $io->error(array('This command needs the pcntl extension to run.', 'You can either install it or use the "mongodb:run" command instead to run the MongoDB server.'));
         if ($io->ask('Do you want to execute <info>mongodb:run</info> immediately? [Yn] ', true)) {
             $command = $this->getApplication()->find('mongodb:run');
             return $command->run($input, $output);
         }
         return 1;
     }
     $dbPath = $input->getOption('dbpath');
     $fs = new Filesystem();
     try {
         $fs->mkdir('data/mongodb/');
     } catch (IOException $e) {
         $io->warning('Could not create "data/mongodb/" directory');
     }
     // $env = $this->getContainer()->getParameter('kernel.environment');
     $env = null;
     $address = $input->getArgument('address');
     if (false === strpos($address, ':')) {
         $address = $address . ':' . $input->getOption('port');
     }
     if (!$input->getOption('force') && $this->isOtherServerProcessRunning($address)) {
         $io->error(array(sprintf('A process is already listening on mongodb://%s.', $address), 'Use the --force option if the server process terminated unexpectedly to start a new MongoDB server process.'));
         return 1;
     }
     $pid = pcntl_fork();
     if ($pid < 0) {
         $io->error('Unable to start the server process.');
         return 1;
     }
     if ($pid > 0) {
         $io->success(sprintf('MongoDB server listening on mongodb://%s', $address));
         return;
     }
     if (posix_setsid() < 0) {
         $io->error('Unable to set the child process as session leader');
         return 1;
     }
     if (null === ($process = $this->createServerProcess($io, $input->getArgument('address'), $input->getOption('port'), $dbPath))) {
         return 1;
     }
     $process->disableOutput();
     $process->start();
     $lockFile = $this->getLockFile($address);
     touch($lockFile);
     if (!$process->isRunning()) {
         $io->error('Unable to start the server process');
         unlink($lockFile);
         return 1;
     }
     // stop the web server when the lock file is removed
     while ($process->isRunning()) {
         if (!file_exists($lockFile)) {
             $process->stop();
         }
         sleep(1);
     }
 }
开发者ID:100hz,项目名称:hive-console,代码行数:64,代码来源:MongoDBStartCommand.php


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