3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Console\Prompt
;
12 class Confirm
extends Char
17 protected $promptText = 'Are you sure?';
22 protected $allowedChars = 'yn';
27 protected $yesChar = 'y';
32 protected $noChar = 'n';
37 protected $ignoreCase = true;
40 * Ask the user for a single key stroke
42 * @param string $promptText The prompt text to display in console
43 * @param string $yesChar The "yes" key (defaults to Y)
44 * @param string $noChar The "no" key (defaults to N)
46 public function __construct(
47 $promptText = 'Are you sure?',
51 if ($promptText !== null) {
52 $this->setPromptText($promptText);
55 if ($yesChar !== null) {
56 $this->setYesChar($yesChar);
59 if ($noChar !== null) {
60 $this->setNoChar($noChar);
65 * Show the confirmation message and return result.
69 public function show()
71 $char = parent
::show();
72 if ($this->ignoreCase
) {
73 $response = strtolower($char) === strtolower($this->yesChar
);
75 $response = $char === $this->yesChar
;
77 return $this->lastResponse
= $response;
81 * @param string $noChar
83 public function setNoChar($noChar)
85 $this->noChar
= $noChar;
86 $this->setAllowedChars($this->yesChar
. $this->noChar
);
92 public function getNoChar()
98 * @param string $yesChar
100 public function setYesChar($yesChar)
102 $this->yesChar
= $yesChar;
103 $this->setAllowedChars($this->yesChar
. $this->noChar
);
109 public function getYesChar()
111 return $this->yesChar
;