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