Inheritance: extends Webiny\Component\Http\Response, use trait Webiny\Component\StdLib\StdLibTrait
Ejemplo n.º 1
0
 public function testContentType()
 {
     $jr = new JsonResponse('');
     $this->assertSame('application/json', $jr->getContentType());
 }
Ejemplo n.º 2
0
 /**
  * Sends the output to browser.
  */
 public function sendOutput()
 {
     // check environment to see what and how to do the output
     $prettyPrint = false;
     if ($this->env == 'development') {
         $prettyPrint = true;
         unset($this->outputArray['debug']);
     }
     // if there is an error, we always dump the content
     if (!empty($this->outputArray['errorReport'])) {
         unset($this->outputArray['data']);
     }
     // build response
     if (empty($this->outputArray)) {
         $response = $this->httpResponse();
     } else {
         $response = new JsonResponse($this->outputArray, $this->debugHeaders, $prettyPrint);
     }
     // set proper status code to the response
     $response->setStatusCode($this->statusCode, $this->message);
     // check the expires header
     if ($this->expiresIn > 0) {
         $expiration = $this->dateTime()->add('PT' . $this->expiresIn . 'S');
         $response->cacheControl()->setAsCache($expiration);
     }
     // send it to the browser
     $response->send();
 }