Exemplo n.º 1
0
 /**
  * Send the response
  *
  * This method is overridden, it's purpose is to disable the exit call and instead
  * just return the error level for unit testing
  *
  * @param SendResponseEvent $event
  * @return int
  */
 public function __invoke(SendResponseEvent $event)
 {
     $response = $event->getResponse();
     if ($response instanceof Response) {
         $this->sendContent($event);
         $errorLevel = (int) $response->getMetadata('errorLevel', 0);
         $event->stopPropagation(true);
         return $errorLevel;
     }
 }
 /**
  * Send php environment response
  *
  * @param  SendResponseEvent $event
  * @return PhpEnvironmentResponseSender
  */
 public function __invoke(SendResponseEvent $event)
 {
     $response = $event->getResponse();
     if (!$response instanceof Response) {
         return $this;
     }
     $this->sendHeaders($event)->sendContent($event);
     $event->stopPropagation(true);
     return $this;
 }
 /**
  * @param SendResponseEvent $event
  * @return $this
  */
 public function __invoke(SendResponseEvent $event)
 {
     $response = $event->getResponse();
     if (!class_exists('tidy') || !$response instanceof Response || $response->getHeaders()->count() > 0 || $this->xmlHttpRequest) {
         return $this;
     }
     $this->sendHeaders($event)->sendContent($event);
     $event->stopPropagation(true);
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Send HTTP headers
  *
  * @param  SendResponseEvent $event
  * @return self
  */
 public function sendHeaders(SendResponseEvent $event)
 {
     if (headers_sent() || $event->headersSent()) {
         return $this;
     }
     $response = $event->getResponse();
     foreach ($response->getHeaders() as $header) {
         if ($header instanceof MultipleHeaderInterface) {
             header($header->toString(), false);
             continue;
         }
         header($header->toString());
     }
     $status = $response->renderStatusLine();
     header($status);
     $event->setHeadersSent();
     return $this;
 }
 /**
  * Send HTTP response headers
  *
  * If an application response is composed, and is an HTTP response, merges
  * its headers with the ApiProblemResponse headers prior to sending them.
  *
  * @param  SendResponseEvent $e
  * @return self
  *
  * @throws \Zend\Http\Exception\InvalidArgumentException
  */
 public function sendHeaders(SendResponseEvent $e)
 {
     $response = $e->getResponse();
     if (!$response instanceof ApiProblemResponse) {
         return $this;
     }
     /** @var Request $request */
     $request = $this->getMvcEvent()->getRequest();
     /** @var Accept $accept */
     $accept = $request->getHeader('Accept');
     if ($accept instanceof Accept && $accept->hasMediaType('text/xml')) {
         $headers = $response->getHeaders();
         if ($headers->has('content-type')) {
             $contentTypeHeader = $headers->get('content-type');
             $headers->removeHeader($contentTypeHeader);
         }
         $headers->addHeaderLine('content-type', 'text/xml');
         if ($this->applicationResponse instanceof HttpResponse) {
             $this->mergeHeaders($this->applicationResponse, $response);
         }
     }
     return parent::sendHeaders($e);
 }