/src/application/libraries/Zend/Json/Server/Response/Http.php

https://bitbucket.org/masnug/grc276-blog-laravel · PHP · 81 lines · 30 code · 7 blank · 44 comment · 7 complexity · 3307db768a0d0d6be4ee8cced446f9c7 MD5 · raw file

  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_Json
  17. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Http.php 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /**
  22. * @see Zend_Json_Server_Response
  23. */
  24. require_once 'Zend/Json/Server/Response.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Json
  28. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Json_Server_Response_Http extends Zend_Json_Server_Response
  32. {
  33. /**
  34. * Emit JSON
  35. *
  36. * Send appropriate HTTP headers. If no Id, then return an empty string.
  37. *
  38. * @return string
  39. */
  40. public function toJson()
  41. {
  42. $this->sendHeaders();
  43. if (!$this->isError() && null === $this->getId()) {
  44. return '';
  45. }
  46. return parent::toJson();
  47. }
  48. /**
  49. * Send headers
  50. *
  51. * If headers are already sent, do nothing. If null ID, send HTTP 204
  52. * header. Otherwise, send content type header based on content type of
  53. * service map.
  54. *
  55. * @return void
  56. */
  57. public function sendHeaders()
  58. {
  59. if (headers_sent()) {
  60. return;
  61. }
  62. if (!$this->isError() && (null === $this->getId())) {
  63. header('HTTP/1.1 204 No Content');
  64. return;
  65. }
  66. if (null === ($smd = $this->getServiceMap())) {
  67. return;
  68. }
  69. $contentType = $smd->getContentType();
  70. if (!empty($contentType)) {
  71. header('Content-Type: ' . $contentType);
  72. }
  73. }
  74. }