示例#1
0
 public function testCanSelectOptionWithCustomIndex()
 {
     fwrite($this->adapter->stream, "2");
     $select = new Select('Select an option :', array('2' => 'foo', '6' => 'bar'));
     $select->setConsole($this->adapter);
     ob_start();
     $response = $select->show();
     $text = ob_get_clean();
     $this->assertTrue((bool) preg_match('#2\\) foo#', $text));
     $this->assertTrue((bool) preg_match('#6\\) bar#', $text));
     $this->assertEquals('2', $response);
 }
示例#2
0
 public function createAction()
 {
     $emailValidator = new EmailAddress();
     $m = $this->message();
     $priorityList = ['urgent', 'high', 'normal', 'low'];
     $typeList = ['problem', 'incident', 'question', 'task'];
     $m->show('[info]What is you subject?[/info]');
     $subject = $this->getConsole()->readLine();
     $m->show('[info]Type[/info]');
     $select = new Select('Which type?', $typeList);
     $type = $typeList[$select->show()];
     $m->show('[info]What is your email?[/info]');
     $email = $this->getConsole()->readLine();
     $m->show('[info]What is your tags (separated by comma)?[/info]');
     $tags = explode(',', $this->getConsole()->readLine());
     $tags = array_map('trim', $tags);
     while (empty($description)) {
         $m->show('[info]What is your description[/info]');
         $description = $this->getConsole()->readLine();
     }
     $m->show('[info]Priority[/info]');
     $select = new Select('Which priority?', $priorityList);
     $priority = $priorityList[$select->show()];
     $extra = [];
     if ($emailValidator->isValid($email)) {
         $extra['requester'] = $email;
     }
     $extra['tags'] = is_array($tags) ? [] : $tags;
     $extra['priority'] = $priority;
     $extra['type'] = $type;
     $e = new Ticket();
     $e->setSubject($subject);
     $e->setDescription($description);
     $e->setExtraFields($extra);
     $result = $this->client->create($e->getArrayCopy());
     if ($result) {
         $e->exchangeArray((new ObjectProperty())->extract($result->ticket));
         return json_encode($e->getArrayCopy(), JSON_PRETTY_PRINT);
     }
     return 0;
 }
示例#3
0
 public function select($promptText, array $options, $allowEmpty = false)
 {
     $prompt = new SelectPrompt($promptText, $options, $allowEmpty);
     $prompt->setConsole($this->console);
     return $prompt->show();
 }
示例#4
0
 /**
  * Write a customizable prompt
  *
  * @param $message
  * @param $options
  *
  * @return string
  */
 public function writeSelectPrompt($message, &$options)
 {
     $this->writeLine();
     // translate options
     foreach ($options as $optionKey => $optionValue) {
         $options[$optionKey] = $this->translator->translate($optionValue);
     }
     // write prompt badge
     $this->writeBadge('badge_pick', Color::RED);
     // output prompt
     $prompt = new Select($this->translator->translate($message), $options, false, false);
     $answer = $prompt->show();
     $this->writeLine();
     return strtolower($answer);
 }