Stdin.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_Controller
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /**
  21. * Zend_XmlRpc_Request
  22. */
  23. require_once 'Zend/XmlRpc/Request.php';
  24. /**
  25. * XmlRpc Request object -- Request via STDIN
  26. *
  27. * Extends {@link Zend_XmlRpc_Request} to accept a request via STDIN. Request is
  28. * built at construction time using data from STDIN; if no data is available, the
  29. * request is declared a fault.
  30. *
  31. * @category Zend
  32. * @package Zend_XmlRpc
  33. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @version $Id$
  36. */
  37. class Zend_XmlRpc_Request_Stdin extends Zend_XmlRpc_Request
  38. {
  39. /**
  40. * Raw XML as received via request
  41. * @var string
  42. */
  43. protected $_xml;
  44. /**
  45. * Constructor
  46. *
  47. * Attempts to read from php://stdin to get raw POST request; if an error
  48. * occurs in doing so, or if the XML is invalid, the request is declared a
  49. * fault.
  50. *
  51. * @return void
  52. */
  53. public function __construct()
  54. {
  55. $fh = fopen('php://stdin', 'r');
  56. if (!$fh) {
  57. $this->_fault = new Zend_XmlRpc_Server_Exception(630);
  58. return;
  59. }
  60. $xml = '';
  61. while (!feof($fh)) {
  62. $xml .= fgets($fh);
  63. }
  64. fclose($fh);
  65. $this->_xml = $xml;
  66. $this->loadXml($xml);
  67. }
  68. /**
  69. * Retrieve the raw XML request
  70. *
  71. * @return string
  72. */
  73. public function getRawRequest()
  74. {
  75. return $this->_xml;
  76. }
  77. }