InputHandler.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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-2014 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Tool
  24. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  25. * @license http://framework.zend.com/license/new-bsd New BSD License
  26. */
  27. class Zend_Tool_Framework_Client_Interactive_InputHandler
  28. {
  29. /**
  30. * @var Zend_Tool_Framework_Client_Interactive_InputInterface
  31. */
  32. protected $_client = null;
  33. protected $_inputRequest = null;
  34. public function setClient(Zend_Tool_Framework_Client_Interactive_InputInterface $client)
  35. {
  36. $this->_client = $client;
  37. return $this;
  38. }
  39. public function setInputRequest($inputRequest)
  40. {
  41. if (is_string($inputRequest)) {
  42. require_once 'Zend/Tool/Framework/Client/Interactive/InputRequest.php';
  43. $inputRequest = new Zend_Tool_Framework_Client_Interactive_InputRequest($inputRequest);
  44. } elseif (!$inputRequest instanceof Zend_Tool_Framework_Client_Interactive_InputRequest) {
  45. require_once 'Zend/Tool/Framework/Client/Exception.php';
  46. throw new Zend_Tool_Framework_Client_Exception('promptInteractive() requires either a string or an instance of Zend_Tool_Framework_Client_Interactive_InputRequest.');
  47. }
  48. $this->_inputRequest = $inputRequest;
  49. return $this;
  50. }
  51. public function handle()
  52. {
  53. $inputResponse = $this->_client->handleInteractiveInputRequest($this->_inputRequest);
  54. if (is_string($inputResponse)) {
  55. require_once 'Zend/Tool/Framework/Client/Interactive/InputResponse.php';
  56. $inputResponse = new Zend_Tool_Framework_Client_Interactive_InputResponse($inputResponse);
  57. } elseif (!$inputResponse instanceof Zend_Tool_Framework_Client_Interactive_InputResponse) {
  58. require_once 'Zend/Tool/Framework/Client/Exception.php';
  59. 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.');
  60. }
  61. return $inputResponse;
  62. }
  63. }