|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Tool |
|
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 * @version $Id: InputHandler.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
20 */ |
|
21 |
|
22 /** |
|
23 * @category Zend |
|
24 * @package Zend_Tool |
|
25 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
26 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
27 */ |
|
28 class Zend_Tool_Framework_Client_Interactive_InputHandler |
|
29 { |
|
30 |
|
31 /** |
|
32 * @var Zend_Tool_Framework_Client_Interactive_InputInterface |
|
33 */ |
|
34 protected $_client = null; |
|
35 |
|
36 protected $_inputRequest = null; |
|
37 |
|
38 public function setClient(Zend_Tool_Framework_Client_Interactive_InputInterface $client) |
|
39 { |
|
40 $this->_client = $client; |
|
41 return $this; |
|
42 } |
|
43 |
|
44 public function setInputRequest($inputRequest) |
|
45 { |
|
46 if (is_string($inputRequest)) { |
|
47 require_once 'Zend/Tool/Framework/Client/Interactive/InputRequest.php'; |
|
48 $inputRequest = new Zend_Tool_Framework_Client_Interactive_InputRequest($inputRequest); |
|
49 } elseif (!$inputRequest instanceof Zend_Tool_Framework_Client_Interactive_InputRequest) { |
|
50 require_once 'Zend/Tool/Framework/Client/Exception.php'; |
|
51 throw new Zend_Tool_Framework_Client_Exception('promptInteractive() requires either a string or an instance of Zend_Tool_Framework_Client_Interactive_InputRequest.'); |
|
52 } |
|
53 |
|
54 $this->_inputRequest = $inputRequest; |
|
55 return $this; |
|
56 } |
|
57 |
|
58 public function handle() |
|
59 { |
|
60 $inputResponse = $this->_client->handleInteractiveInputRequest($this->_inputRequest); |
|
61 |
|
62 if (is_string($inputResponse)) { |
|
63 require_once 'Zend/Tool/Framework/Client/Interactive/InputResponse.php'; |
|
64 $inputResponse = new Zend_Tool_Framework_Client_Interactive_InputResponse($inputResponse); |
|
65 } elseif (!$inputResponse instanceof Zend_Tool_Framework_Client_Interactive_InputResponse) { |
|
66 require_once 'Zend/Tool/Framework/Client/Exception.php'; |
|
67 throw new Zend_Tool_Framework_Client_Exception('The registered $_interactiveCallback for the client must either return a string or an instance of Zend_Tool_Framework_Client_Interactive_InputResponse.'); |
|
68 } |
|
69 |
|
70 return $inputResponse; |
|
71 } |
|
72 |
|
73 |
|
74 } |