<?php
 namespace Moto\Json\Server\Response; use Zend\Json\Server\Response as JsonResponse; class HttpBatch extends JsonResponse { protected $_queue = array(); public function addResponse($response) { $this->_queue[] = $response; } public function toJson() { $this->sendHeaders(); if (!$this->isError() && !count($this->_queue)) { return ''; } $json = array(); for ($i = 0, $count = count($this->_queue); $i < $count; $i++) { $json[] = $this->_queue[$i]->toJson(); } $json = '[' . implode(',', $json) . ']'; return $json; } public function sendHeaders() { if (headers_sent()) { return; } if (!$this->isError() && !count($this->_queue)) { header('HTTP/1.1 204 No Content'); return; } if (null === ($smd = $this->getServiceMap())) { return; } $contentType = $smd->getContentType(); if (!empty($contentType)) { header('Content-Type: ' . $contentType); } } }