Ejemplo n.º 1
0
 /**
  * Informs the display about the structure of a Field.
  * 
  * Each time the Field structure changes for some reason, this method shall
  * be called.
  *
  * @param \Feeld\Display\DisplayDataSourceInterface $field
  * @throws Exception
  */
 public function informAboutStructure(\Feeld\Display\DisplayDataSourceInterface $field)
 {
     parent::informAboutStructure($field);
     $this->field = $field;
     if ($field instanceof \Feeld\Field\Entry) {
         $this->symfonyQuestion = new SymfonyQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
     } elseif ($field instanceof \Feeld\Field\Select) {
         $this->symfonyQuestion = new \Symfony\Component\Console\Question\ChoiceQuestion((string) $this, array_keys($field->getOptions()), $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
         if ($field instanceof \Feeld\Field\CommonProperties\MultipleChoiceInterface && $field->isMultipleChoice()) {
             $field->symfonyQuestion->setMultiselect(true);
         }
     } elseif ($field instanceof \Feeld\Field\CloakedEntry) {
         $this->symfonyQuestion = new SymfonyQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
         $this->symfonyQuestion->setHidden(true);
     } elseif ($field instanceof \Feeld\Field\Constant) {
         throw new Exception('Constants are currently not supported in SymfonyConsoleDisplay');
     } elseif ($field instanceof \Feeld\Field\Checkbox) {
         $this->symfonyQuestion = new \Symfony\Component\Console\Question\ConfirmationQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : true, '/^' . strtolower(substr($this->getTrueOption(), 0, 1)) . '/i');
     }
     $this->symfonyQuestion->setNormalizer(function ($value) {
         return $this->field->getSanitizer()->filter($value);
     });
     $this->symfonyQuestion->setValidator(function ($value) {
         $validationResultSet = $this->field->validateValue($value);
         if ($validationResultSet->hasErrors()) {
             $this->field->clearValidationResult();
             throw new \Exception(implode(PHP_EOL, $validationResultSet->getErrorMessages()));
         }
         return $this->field->getFilteredValue();
     });
     $this->symfonyQuestion->setMaxAttempts(null);
 }
Ejemplo n.º 2
0
 /**
  * @param string|Question $question Question text or a Question object
  * @param null|string $default The default answer
  * @param bool|\Closure $requireAnswer True for not-empty validation, or a closure for custom validation
  * @return string User's answer
  */
 protected function askQuestion($question, $default = null, $requireAnswer = true)
 {
     if (!$this->questionHelper) {
         $this->questionHelper = $this->getHelper("question");
     }
     if (!$question instanceof Question) {
         if (strpos($question, '<question>') === false) {
             $question = '<question>' . $question . '</question> ';
         }
         if ($default !== null) {
             $question .= "({$default}) ";
         }
         $question = new Question($question, $default);
     }
     if (is_callable($requireAnswer)) {
         $question->setValidator($requireAnswer);
     } elseif ($requireAnswer) {
         $question->setValidator(function ($answer) {
             if (trim($answer) == '') {
                 throw new \Exception('You must provide an answer to this question');
             }
             return $answer;
         });
     }
     return $this->questionHelper->ask($this->input, $this->output, $question);
 }
Ejemplo n.º 3
0
 /**
  * @return SimpleQuestion
  */
 private function buildQuestion()
 {
     $question = new SimpleQuestion('<question>Enter your project homepage:</question>');
     $question->setValidator($this->buildValidator());
     $question->setMaxAttempts(3);
     return $question;
 }
Ejemplo n.º 4
0
 /**
  * Executes the command.
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$this->getGitHelper()->available()) {
         throw new \Exception('Is not a git project.');
     }
     $git = $this->getGitHelper();
     do {
         $tags = $git->getTags();
         foreach ($tags as $id => $tagName) {
             $output->writeln(sprintf('[%s] %s', $id, $tagName));
         }
         /* @var $question \Symfony\Component\Console\Helper\QuestionHelper */
         $question = $this->getHelper('question');
         $tagQuestion = new Question('Which branch should deleted? ');
         $tagQuestion->setValidator(function ($answer) use($tags) {
             if (!isset($tags[$answer])) {
                 throw new \Exception($answer . ' is not a valid value');
             }
         });
         $tagQuestion->setMaxAttempts(3);
         $answer = $question->ask($input, $output, $tagQuestion);
         $git->deleteTag($tags[$answer]);
         $deleteOtherTagQuestion = new Question('Delete another tag/branch? [y/n]: ');
         $deleteOtherTag = $question->ask($input, $output, $deleteOtherTagQuestion);
     } while (strtolower(substr($deleteOtherTag, 0, 1)) == 'y');
 }
Ejemplo n.º 5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new Question('Please enter app\'s shared secret: ');
     $question->setValidator(function ($answer) {
         if (empty($answer)) {
             throw new RuntimeException('Shared secret must be provided');
         }
         return $answer;
     });
     $question->setHidden(true);
     $question->setMaxAttempts(2);
     $sharedSecret = $helper->ask($input, $output, $question);
     $receiptFile = __DIR__ . '/../../../tmp/receipt';
     if (!is_file(realpath($receiptFile))) {
         throw new RuntimeException(sprintf('Create a file with receipt data here %s', $receiptFile));
     }
     $receiptData = file_get_contents($receiptFile);
     if (empty($receiptData)) {
         throw new RuntimeException(sprintf('Put receipt data here %s', $receiptFile));
     }
     $validator = new Validator();
     $validator->setSecret($sharedSecret);
     $validator->setReceiptData($receiptData);
     $response = $validator->validate();
     var_dump($response);
 }
Ejemplo n.º 6
0
 /**
  * @return SimpleQuestion
  */
 private function buildAuthorQuestion()
 {
     $question = new SimpleQuestion('<question>Enter the author (name <*****@*****.**>):</question>');
     $question->setValidator($this->buildValidator());
     $question->setMaxAttempts(3);
     return $question;
 }
Ejemplo n.º 7
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     if ($input->hasOption("browse") && $input->getOption("browse")) {
         # print the status list
         $command = $this->getApplication()->find('status');
         $statusInput = new ArrayInput(array(), $command->getDefinition());
         $command->run($statusInput, $output);
         # ask with boxes to handle
         $helper = $this->getHelper('question');
         $question = new Question('<fg=yellow>' . "Select box/boxes to " . $this->action . ':</> ', null);
         $question->setMaxAttempts(5);
         # set up validation for the question
         $question->setValidator(function ($answer) {
             $vagrant = new Vagrant();
             # check if the answer can be resolved
             if (!count($vagrant->resolveStr($answer))) {
                 throw new \RuntimeException('Your selection does not match any boxes');
             }
             return $answer;
         });
         # if we have an answer, set it as an argument, and move on
         if ($answer = $helper->ask($input, $output, $question)) {
             $input->setArgument("identifier", $answer);
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * @param $dialog
  * @param null $default
  * @return mixed
  */
 protected function useSymfonyQuestion($dialog, $default = null, $validation)
 {
     $question = new Question($dialog . ' ', $default);
     $question->setValidator($validation);
     $helper = $this->getHelper('question');
     return $helper->ask($this->input, $this->output, $question);
 }
Ejemplo n.º 9
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws \Exception
  * @throws \Symfony\Component\Console\Exception\ExceptionInterface
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     # print the status list
     /** @var StatusCommand $command */
     $command = $this->getApplication()->find('status');
     $statusInput = new ArrayInput(array(), $command->getDefinition());
     $command->run($statusInput, $output);
     foreach (array_keys($this->actions) as $name) {
         # ask with boxes to handle
         $helper = $this->getHelper('question');
         $question = new Question('<fg=yellow>' . "Select box/boxes to " . $name . ' []:</> ', null);
         $question->setMaxAttempts(5);
         # set up validation for the question
         $question->setValidator(function ($answer) {
             $vagrant = new Vagrant();
             # check if the answer can be resolved
             if ($answer != "" && !count($vagrant->resolveStr($answer))) {
                 throw new \RuntimeException('Your selection does not match any boxes');
             }
             return $answer;
         });
         # if we have an answer, set it as an argument, and move on
         if ($answer = $helper->ask($input, $output, $question)) {
             $this->actions[$name]["boxes"] = $answer;
         }
     }
 }
Ejemplo n.º 10
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine')->getManager();
     $helper = $this->getHelper('question');
     $output->writeln("\n<question>                                      ");
     $output->writeln(' Welcome to the Fbeen slug generator. ');
     $output->writeln("                                      </question>\n");
     $entityName = $input->getArgument('entity');
     if (!$entityName) {
         $output->writeln('This command helps you to update slugs on an entire table.');
         $output->writeln('First, you need to give the entity for which you want to generate the slugs.');
         $output->writeln("\nYou must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>.\n");
         $question = new Question('<info>The Entity shortcut name: </info>');
         $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName'));
         $autocompleter = new EntitiesAutoCompleter($em);
         $autocompleteEntities = $autocompleter->getSuggestions();
         $question->setAutocompleterValues($autocompleteEntities);
         $entityName = $helper->ask($input, $output, $question);
     }
     $entities = $em->getRepository($entityName)->findAll();
     $question = new ConfirmationQuestion('<info>Continue generating slugs for ' . $entityName . '</info> [<comment>no</comment>]? ', false);
     if (!$helper->ask($input, $output, $question)) {
         return;
     }
     $output->writeln("\nGenerating the slugs...");
     $slugupdater = new SlugUpdater();
     foreach ($entities as $entity) {
         $slugupdater->preUpdate(new LifecycleEventArgs($entity, $em));
         $em->flush();
     }
     $output->writeln("\nDone!\n");
 }
Ejemplo n.º 11
0
 /**
  * @return SimpleQuestion
  */
 private function buildQuestion()
 {
     $question = new SimpleQuestion('<question>Enter your project name (<vendor>/<package>):</question>');
     $question->setValidator($this->buildValidator());
     $question->setMaxAttempts(3);
     return $question;
 }
 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);
 }
 private function confirmSend($input, $output)
 {
     //Symfony の Console コンポーネ ントには、確認プロンプトを出したり、
     //そこでの入力値をバリデーションしたりするための機能が
     // Questionとして組み込まれています。
     $qHelper = $this->getHelper('question');
     //Question クラス
     $question = new Question('通知メールを送信しますか? [y/n]: ', null);
     //setValidator( )メソッドに、バリデーション時に呼び出すコールバックを渡します
     //引数:入力された値
     //戻り値:正常な場合はバリデーション後の値、エラーがある場合は例外をスロー
     $question->setValidator(function ($answer) {
         //strtolower 大文字を小文字に substrは$answerの0番目の1文字を返す
         $answer = strtolower(substr($answer, 0, 1));
         if (!in_array($answer, ['y', 'n'])) {
             throw new \RuntimeException('yまたはnを入力してください');
         }
         return $answer;
     });
     //❺許容する試行回数の設定
     $question->setMaxAttempts(3);
     //プロンプトを表示して回答を得る
     //Questionヘルパのask( )メソッドを呼び出します。ask( )メソッドの戻り値は、
     //入力バリデーション後の値です。これが'y'だった場合は、confirmSend( )メソッドの戻り値として
     // true が返るようにしています。
     return $qHelper->ask($input, $output, $question) == 'y';
 }
Ejemplo n.º 14
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var QuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     $usernameQuestion = new Question('E-mail: ');
     $usernameQuestion->setValidator(function ($value) {
         if (trim($value) === '') {
             throw new \Exception('E-mail can not be empty');
         }
         if (!Validators::isEmail($value)) {
             throw new \Exception('E-mail is not valid');
         }
         return $value;
     });
     $passwordQuestion = new Question('Password: '******'') {
             throw new \Exception('The password can not be empty');
         }
         return $value;
     });
     $passwordQuestion->setHidden(TRUE);
     $passwordQuestion->setHiddenFallback(FALSE);
     $username = $questionHelper->ask($input, $output, $usernameQuestion);
     $password = $questionHelper->ask($input, $output, $passwordQuestion);
     $name = $questionHelper->ask($input, $output, new Question('Name: '));
     $user = $this->userFacade->add($username, $password, $name);
     $output->writeln('User ' . $user->getEmail() . ' was successfully created!');
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the Parse.com CRUD generator');
     // namespace
     $output->writeln(array('', 'This command helps you generate CRUD controllers and templates.', 'You must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>.', ''));
     if ($input->hasArgument('parse-entity-name') && $input->getArgument('parse-entity-name') != '') {
         $input->setOption('parse-entity-name', $input->getArgument('parse-entity-name'));
     }
     $question = new Question($questionHelper->getQuestion('The Entity shortcut name', $input->getOption('parse-entity-name')), $input->getOption('parse-entity-name'));
     $question->setValidator(array('BcTic\\ParseCrudGenerator\\CrudGeneratorBundle\\Command\\Validators', 'validateParseEntityName'));
     $autocompleter = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager());
     $autocompleteEntities = $autocompleter->getSuggestions();
     $question->setAutocompleterValues($autocompleteEntities);
     $entity = $questionHelper->ask($input, $output, $question);
     $input->setOption('parse-entity-name', $entity);
     list($bundle, $entity) = $this->parseShortcutNotation($entity);
     // 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), ''));
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the Kunstmaan Article generator');
     $inputAssistant = GeneratorUtils::getInputAssistant($input, $output, $questionHelper, $this->getApplication()->getKernel(), $this->getContainer());
     $inputAssistant->askForNamespace(array('', 'This command helps you to generate the Article classes.', 'You must specify the namespace of the bundle where you want to generate the classes in.', 'Use <comment>/</comment> instead of <comment>\\ </comment>for the namespace delimiter to avoid any problem.', ''));
     // entity
     $entity = $input->getOption('entity') ? $input->getOption('entity') : null;
     if (is_null($entity)) {
         $output->writeln(array('', 'You must specify a name for the collection of Article entities.', 'This name will be prefixed before every new entity.', 'For example entering <comment>News</comment> will result in:', '<comment>News</comment>OverviewPage, <comment>News</comment>Page and <comment>News</comment>Author', ''));
         $entityValidation = function ($entity) {
             if (empty($entity)) {
                 throw new \RuntimeException('You have to provide a entity name!');
             } elseif (!preg_match('/^[a-zA-Z][a-zA-Z_0-9]+$/', $entity)) {
                 throw new \InvalidArgumentException(sprintf("%s" . ' contains invalid characters', $entity));
             } else {
                 return $entity;
             }
         };
         $question = new Question($questionHelper->getQuestion('Name', $entity), $entity);
         $question->setValidator($entityValidation);
         $entity = $questionHelper->ask($input, $output, $question);
         $input->setOption('entity', $entity);
     }
     $inputAssistant->askForPrefix();
 }
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     // Start question helper
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the united CRUD generator!');
     // get entity
     $entity = $input->getOption('entity');
     $question = new Question($questionHelper->getQuestion('Entity', $entity), $entity);
     $question->setValidator(function ($answer) {
         return Validators::validateEntityName($answer);
     });
     $complete = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager());
     $completeEntities = $complete->getSuggestions();
     $question->setAutocompleterValues($completeEntities);
     $entity = $questionHelper->ask($input, $output, $question);
     $input->setOption('entity', $entity);
     // get bundle
     $destinationBundle = $input->getOption('bundle');
     $question = new Question($questionHelper->getQuestion('Destination bundle', $destinationBundle), $destinationBundle);
     $question->setValidator(function ($answer) {
         return Validators::validateBundleName($answer);
     });
     $question->setAutocompleterValues($this->getBundleSuggestions());
     $destinationBundle = $questionHelper->ask($input, $output, $question);
     $input->setOption('bundle', $destinationBundle);
 }
 /**
  * @see Command
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questions = array();
     if (!$input->getArgument('username')) {
         $question = new Question('Please give the username:'******'Username can not be empty');
             }
             return $username;
         });
         $questions['username'] = $question;
     }
     if (!$input->getArgument('password')) {
         $question = new Question('Please enter the new password:'******'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);
     }
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     /** @var QuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     if ($input->getArgument('state') === null) {
         $output->writeln('<info>State required</info>');
         $question = new ChoiceQuestion('<question>Select state</question>', ['new', 'used', 'future'], 'new');
         $state = $questionHelper->ask($input, $output, $question);
         $input->setArgument('state', $state);
     }
     if ($input->getArgument('year') === null) {
         $output->writeln('<info>Year required</info>');
         $question = new Question('<question>Enter year:</question> ', 1990);
         $question->setValidator(function ($answer) {
             if ($answer < 1990) {
                 throw new \RuntimeException('Year has to be bigger then 1990');
             }
             return $answer;
         });
         $year = $questionHelper->ask($input, $output, $question);
         $input->setArgument('year', $year);
     }
     $style = new OutputFormatterStyle('black', 'white', ['bold', 'underscore']);
     $output->getFormatter()->setStyle('thanks', $style);
     $output->writeln('<thanks>Thanks!</thanks>');
 }
Ejemplo n.º 20
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $number = $input->getOption('number');
     $debug = true;
     try {
         // Create a instance of Registration class.
         $r = new \Registration($number, $debug);
         $r->codeRequest('sms');
         // could be 'voice' too
     } catch (\Exception $e) {
         $output->writeln('<error>the number is invalid ' . $number . '</error>');
         return false;
     }
     $helper = $this->getHelper('question');
     $question = new Question('Digite seu código de confirmação recebido por SMS (sem hífen "-"): ', false);
     $question->setValidator(function ($value) use($output, $r) {
         try {
             $response = $r->codeRegister($value);
             $output->writeln('<fg=green>Your password is: ' . $response->pw . ' and your login: '******'</>');
         } catch (\Exception $e) {
             $output->writeln("<error>Código inválido, tente novamente mais tarde!</error>");
             return false;
         }
         return true;
     });
     $codigo = $helper->ask($input, $output, $question);
     $output->writeln('<fg=green>Your number is ' . $number . ' and your code: ' . $codigo . '</>');
 }
Ejemplo n.º 21
0
 /**
  * @see Command
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questions = array();
     if (!$input->getArgument('username')) {
         $question = new Question('Please choose a username:'******'Username can not be empty');
             }
             return $username;
         });
         $questions['username'] = $question;
     }
     if (true !== $input->getOption('super') && !$input->getArgument('role')) {
         $question = new Question('Please choose a role:');
         $question->setValidator(function ($role) {
             if (empty($role)) {
                 throw new \Exception('Role can not be empty');
             }
             return $role;
         });
         $questions['role'] = $question;
     }
     foreach ($questions as $name => $question) {
         $answer = $this->getHelper('question')->ask($input, $output, $question);
         $input->setArgument($name, $answer);
     }
 }
Ejemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $io = new ConsoleIO($input, $output, $this->getHelperSet());
     $this->welcomeMessage($io);
     $title = $input->getOption('title');
     $question = new Question('Post title: ', $title);
     $question->setMaxAttempts(null);
     $question->setValidator(function ($answer) {
         return Validators::validatePostTitle($answer);
     });
     $title = $helper->ask($input, $output, $question);
     $input->setOption('title', $title);
     $layout = $input->getOption('layout');
     $question = new Question('Post layout: ', $layout);
     $layout = $helper->ask($input, $output, $question);
     $input->setOption('layout', $layout);
     $date = $input->getOption('date') ?: $this->getDateFormated();
     $question = new Question("Post date ({$date}): ", $date);
     $date = $helper->ask($input, $output, $question);
     $input->setOption('date', $date);
     $tags = $input->getOption('tags') ?: '';
     $question = new Question('Comma separated list of post tags: ', $tags);
     $tags = $helper->ask($input, $output, $question);
     $input->setOption('tags', $tags);
     $categories = $input->getOption('categories') ?: '';
     $question = new Question('Comma separated list of post categories: ', $categories);
     $categories = $helper->ask($input, $output, $question);
     $input->setOption('categories', $categories);
 }
 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);
 }
Ejemplo n.º 24
0
 /**
  * {@inheritdoc}
  */
 public function interact(InputInterface $input, OutputInterface $output)
 {
     if (null !== $input->getOption('more-than-days') && null !== $input->getOption('less-than-days')) {
         throw new InvalidArgumentException('Options --more-than-days and --less-than-days cannot be used together.');
     }
     if (null === $input->getOption('more-than-days') && null === $input->getOption('less-than-days')) {
         $input->setOption('more-than-days', self::DEFAULT_MORE_THAN_DAYS);
     }
     $resourceFQCN = $input->hasArgument('entity') ? $input->getArgument('entity') : null;
     $isForced = $input->getOption('force');
     if (null !== $resourceFQCN && !class_exists($resourceFQCN)) {
         $errorCallback = function ($resourceFQCN) use($output) {
             $output->writeln('<info>Abort the purge operation. Nothing has been deleted from the database.</info>');
             throw new InvalidArgumentException(sprintf('Entity %s is not a valid fully qualified class name.', $resourceFQCN));
         };
         $output->writeln(sprintf('<info>"%s" is not a valid resource name.</info>', $resourceFQCN));
         if ($isForced) {
             $errorCallback($resourceFQCN);
         }
         $helper = $this->getHelper('question');
         $question = new Question('<question>Please insert a valid fully qualified class name: </question>');
         $question->setValidator(function ($answer) {
             if (!class_exists($answer)) {
                 throw new \RuntimeException('The fully qualified class name does not exist. Please choose a value from the table above.');
             }
             return $answer;
         });
         $question->setMaxAttempts(2);
         $resourceFQCN = $helper->ask($input, $output, $question);
         if (!$resourceFQCN) {
             $errorCallback($resourceFQCN);
         }
         $input->setArgument('entity', $resourceFQCN);
     }
 }
Ejemplo n.º 25
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new Question('Choose the status for the account [0=Consumer, 1=Administrator]: ');
     $question->setValidator(function ($value) {
         if (preg_match('/^0|1$/', $value)) {
             return $value;
         } else {
             throw new \Exception('Status must be either 0 or 1');
         }
     });
     $status = $helper->ask($input, $output, $question);
     $question = new Question('Enter the username of the account: ');
     $question->setValidator(function ($value) {
         if (!preg_match('/^[A-z0-9\\-\\_\\.]{3,32}$/', $value)) {
             throw new \Exception('The username must match the following regexp [A-z0-9\\-\\_\\.]{3,32}');
         }
         return $value;
     });
     $userName = $helper->ask($input, $output, $question);
     $password = sha1(mcrypt_create_iv(40));
     $this->userTable->create(array('status' => $status, 'name' => $userName, 'password' => \password_hash($password, PASSWORD_DEFAULT), 'date' => new DateTime()));
     $output->writeln('Created user ' . $userName . ' successful');
     $output->writeln('The following passord was assigned to the account:');
     $output->writeln($password);
 }
Ejemplo n.º 26
0
 /**
  *
  * 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>");
 }
 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), ''));
 }
 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];
 }
 /**
  * Asks for the namespace and sets it on the InputInterface as the 'namespace' option, if this option is not set yet.
  *
  * @param array $text What you want printed before the namespace is asked.
  *
  * @return string The namespace. But it's also been set on the InputInterface.
  */
 public function askForNamespace(array $text = null)
 {
     $namespace = $this->input->hasOption('namespace') ? $this->input->getOption('namespace') : null;
     // When the Namespace is filled in return it immediately if valid.
     try {
         if (!is_null($namespace) && !empty($namespace)) {
             Validators::validateBundleNamespace($namespace);
             return $namespace;
         }
     } catch (\Exception $error) {
         $this->writeError(array("Namespace '{$namespace}' is incorrect. Please provide a correct value.", $error->getMessage()));
         exit;
     }
     $ownBundles = $this->getOwnBundles();
     if (count($ownBundles) <= 0) {
         $this->writeError("Looks like you don't have created a bundle for your project, create one first.", true);
     }
     $namespace = '';
     // If we only have 1 or more bundles, we can prefill it.
     if (count($ownBundles) > 0) {
         $namespace = $ownBundles[1]['namespace'] . '/' . $ownBundles[1]['name'];
     }
     $namespaces = $this->getNamespaceAutoComplete($this->kernel);
     if (!is_null($text) && count($text) > 0) {
         $this->output->writeln($text);
     }
     $question = new Question($this->questionHelper->getQuestion('Bundle Namespace', $namespace), $namespace);
     $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleNamespace'));
     $question->setAutocompleterValues($namespaces);
     $namespace = $this->questionHelper->ask($this->input, $this->output, $question);
     if ($this->input->hasOption('namespace')) {
         $this->input->setOption('namespace', $namespace);
     }
     return $namespace;
 }
Ejemplo n.º 30
0
 /**
  * @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);
 }