コード例 #1
0
ファイル: Select.php プロジェクト: Baft/Zend-Form
 /**
  * Show a list of options and prompt the user to select one of them.
  *
  * @return string       Selected option
  */
 public function show()
 {
     // Show prompt text and available options
     $console = $this->getConsole();
     $console->writeLine($this->promptText);
     foreach ($this->options as $k => $v) {
         $console->writeLine('  ' . $k . ') ' . $v);
     }
     //  Prepare mask
     $mask = implode("", array_keys($this->options));
     if ($this->allowEmpty) {
         $mask .= "\r\n";
     }
     // Prepare other params for parent class
     $this->setAllowedChars($mask);
     $oldPrompt = $this->promptText;
     $oldEcho = $this->echo;
     $this->echo = false;
     $this->promptText = null;
     // Retrieve a single character
     $response = parent::show();
     // Restore old params
     $this->promptText = $oldPrompt;
     $this->echo = $oldEcho;
     // Display selected option if echo is enabled
     if ($this->echo) {
         if (isset($this->options[$response])) {
             $console->writeLine($this->options[$response]);
         } else {
             $console->writeLine();
         }
     }
     $this->lastResponse = $response;
     return $response;
 }
コード例 #2
0
ファイル: CharTest.php プロジェクト: pnaq57/zf2demo
 public function testCanPromptCharWithoutIgnoreCase()
 {
     fwrite($this->adapter->stream, 'FOObar');
     $char = new Char();
     $char->setEcho(false);
     $char->setConsole($this->adapter);
     $char->setIgnoreCase(false);
     ob_start();
     $response = $char->show();
     ob_get_clean();
     $this->assertEquals('b', $response);
 }
コード例 #3
0
ファイル: Select.php プロジェクト: ninahuanca/zf2
 /**
  * Show a list of options and prompt the user to select one of them.
  *
  * @return string       Selected option
  */
 public function show()
 {
     /**
      * Show prompt text and available options
      */
     $console = $this->getConsole();
     $console->writeLine($this->promptText);
     foreach ($this->options as $k => $v) {
         $console->writeLine('  ' . $k . ') ' . $v);
     }
     /**
      * Ask for selection
      */
     $mask = implode("", array_keys($this->options));
     if ($this->allowEmpty) {
         $mask .= "\r\n";
     }
     $this->setAllowedChars($mask);
     $oldPrompt = $this->promptText;
     $this->promptText = 'Pick one option: ';
     $response = parent::show();
     $this->promptText = $oldPrompt;
     return $response;
 }
コード例 #4
0
ファイル: Confirm.php プロジェクト: raZ3l/zf2
 /**
  * Show the confirmation message and return result.
  *
  * @return bool
  */
 public function show()
 {
     $response = parent::show() === $this->yesChar;
     return $this->lastResponse = $response;
 }