Source of file Confirm.php
Size: 2,426 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Console/Prompt/Confirm.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Console\Prompt; class Confirm extends Char { /** * @var string */ protected $promptText = 'Are you sure?'; /** * @var string */ protected $allowedChars = 'yn'; /** * @var string */ protected $yesChar = 'y'; /** * @var string */ protected $noChar = 'n'; /** * @var bool */ protected $ignoreCase = true; /** * Ask the user for a single key stroke * * @param string $promptText The prompt text to display in console * @param string $yesChar The "yes" key (defaults to Y) * @param string $noChar The "no" key (defaults to N) */ public function __construct( $promptText = 'Are you sure?', $yesChar = 'y', $noChar = 'n' ) { if ($promptText !== null) { $this->setPromptText($promptText); } if ($yesChar !== null) { $this->setYesChar($yesChar); } if ($noChar !== null) { $this->setNoChar($noChar); } } /** * Show the confirmation message and return result. * * @return bool */ public function show() { $char = parent::show(); if ($this->ignoreCase) { $response = strtolower($char) === strtolower($this->yesChar); } else { $response = $char === $this->yesChar; } return $this->lastResponse = $response; } /** * @param string $noChar */ public function setNoChar($noChar) { $this->noChar = $noChar; $this->setAllowedChars($this->yesChar . $this->noChar); } /** * @return string */ public function getNoChar() { return $this->noChar; } /** * @param string $yesChar */ public function setYesChar($yesChar) { $this->yesChar = $yesChar; $this->setAllowedChars($this->yesChar . $this->noChar); } /** * @return string */ public function getYesChar() { return $this->yesChar; } } |