3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 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
;
13 use Zend\Console\Adapter\AdapterInterface
as ConsoleAdapter
;
14 use Zend\Console\Console
;
15 use Zend\Console\Exception
;
17 abstract class AbstractPrompt
implements PromptInterface
27 protected $lastResponse;
30 * Return last answer to this prompt.
34 public function getLastResponse()
36 return $this->lastResponse
;
40 * Return console adapter to use when showing prompt.
42 * @return ConsoleAdapter
44 public function getConsole()
46 if (!$this->console
) {
47 $this->console
= Console
::getInstance();
50 return $this->console
;
54 * Set console adapter to use when showing prompt.
56 * @param ConsoleAdapter $adapter
58 public function setConsole(ConsoleAdapter
$adapter)
60 $this->console
= $adapter;
64 * Create an instance of this prompt, show it and return response.
66 * This is a convenience method for creating statically creating prompts, i.e.:
68 * $name = Zend\Console\Prompt\Line::prompt("Enter your name: ");
71 * @throws Exception\BadMethodCallException
73 public static function prompt()
75 if (get_called_class() === __CLASS__
) {
76 throw new Exception\
BadMethodCallException(
77 'Cannot call prompt() on AbstractPrompt class. Use one of the Zend\Console\Prompt\ subclasses.'
81 $refl = new ReflectionClass(get_called_class());
82 $instance = $refl->newInstanceArgs(func_get_args());
83 return $instance->show();