/**
  * Send the response content
  *
  * Sets the composed ApiProblem's flag for including the stack trace in the
  * detail based on the display exceptions flag, and then sends content.
  *
  * @param SendResponseEvent $e
  * @return self
  *
  * @throws \Zend\Config\Exception\RuntimeException
  */
 public function sendContent(SendResponseEvent $e)
 {
     $response = $e->getResponse();
     if (!$response instanceof ApiProblemResponse) {
         return $this;
     }
     $response->getApiProblem()->setDetailIncludesStackTrace($this->displayExceptions());
     /** @var Request $request */
     $request = $this->getMvcEvent()->getRequest();
     /** @var Accept $accept */
     $accept = $request->getHeader('Accept');
     if ($accept instanceof Accept && $accept->hasMediaType('text/xml')) {
         $arrayResponse = $response->getApiProblem()->toArray();
         $xmlWriter = new XmlWriter();
         if (array_key_exists('trace', $arrayResponse)) {
             array_walk($arrayResponse['trace'], function (&$item) {
                 unset($item['args']);
             });
         }
         if (array_key_exists('exception_stack', $arrayResponse)) {
             array_walk($arrayResponse['exception_stack'], function (&$item) {
                 array_walk($item['trace'], function (&$trace) {
                     unset($trace['args']);
                 });
             });
         }
         $output = $xmlWriter->processConfig($arrayResponse);
         echo $output;
         $e->setContentSent();
         return $this;
     }
     return parent::sendHeaders($e);
 }
Example #2
0
 /**
  * Send content
  *
  * @param  SendResponseEvent $event
  * @return ConsoleResponseSender
  */
 public function sendContent(SendResponseEvent $event)
 {
     if ($event->contentSent()) {
         return $this;
     }
     $response = $event->getResponse();
     echo $response->getContent();
     $event->setContentSent();
     return $this;
 }
 /**
  * Send the stream
  *
  * @param  SendResponseEvent $event
  * @return SimpleStreamResponseSender
  */
 public function sendStream(SendResponseEvent $event)
 {
     if ($event->contentSent()) {
         return $this;
     }
     $response = $event->getResponse();
     $stream = $response->getStream();
     fpassthru($stream);
     $event->setContentSent();
 }
 /**
  * Send content
  *
  * @param  SendResponseEvent $event
  * @return $this
  */
 public function sendContent(SendResponseEvent $event)
 {
     if ($event->contentSent()) {
         return $this;
     }
     $response = $event->getResponse();
     $tidy = new \tidy();
     $tidy->parseString($response->getContent(), $this->config);
     //$tidy->cleanRepair();
     echo $tidy;
     $event->setContentSent();
     return $this;
 }
 public function testContentSentAndHeadersSent()
 {
     $mockResponse = $this->getMockForAbstractClass('Zend\\Stdlib\\ResponseInterface');
     $mockResponse2 = $this->getMockForAbstractClass('Zend\\Stdlib\\ResponseInterface');
     $event = new SendResponseEvent();
     $event->setResponse($mockResponse);
     $this->assertFalse($event->headersSent());
     $this->assertFalse($event->contentSent());
     $event->setHeadersSent();
     $event->setContentSent();
     $this->assertTrue($event->headersSent());
     $this->assertTrue($event->contentSent());
     $event->setResponse($mockResponse2);
     $this->assertFalse($event->headersSent());
     $this->assertFalse($event->contentSent());
 }