Exemplo n.º 1
0
 /**
  * Render response and send it to the client
  */
 public function send()
 {
     if ($this->response instanceof StreamedResponse) {
         $this->response->setCallback(function () {
             $this->renderDeferred();
             flush();
         });
     } else {
         ob_start();
         $this->renderDeferred();
         $json = ob_get_contents();
         ob_end_clean();
         if (Util\Debug::isActivated()) {
             $json = Util\JSON::format($json);
         }
         $this->response->setContent($json);
     }
     return $this->response;
 }
Exemplo n.º 2
0
 /**
  * Render response and send it to the client
  */
 public function send()
 {
     if ($this->response instanceof StreamedResponse) {
         $this->response->setCallback(function () {
             // callback happens outside Router->handle() and requires explicit exception handling
             try {
                 $this->renderDeferred();
             } catch (\Exception $e) {
                 $this->renderStreamedException($e);
             }
             flush();
         });
     } else {
         ob_start();
         $this->renderDeferred();
         $json = ob_get_contents();
         ob_end_clean();
         if (Util\Debug::isActivated()) {
             $json = Util\JSON::format($json);
         }
         $this->response->setContent($json);
     }
     return $this->response;
 }
Exemplo n.º 3
0
 /**
  * Render response and send it to the client
  */
 public function send()
 {
     // use StreamedResponse unless pretty-printing is required
     if (Util\Debug::isActivated()) {
         $this->add(Util\Debug::getInstance());
     } else {
         $this->response = new StreamedResponse();
     }
     // JSONP
     if ($this->padding) {
         $this->response->headers->set('Content-Type', 'application/javascript');
     } else {
         $this->response->headers->set('Content-Type', 'application/json');
         // enable CORS if not JSONP
         $this->response->headers->set('Access-Control-Allow-Origin', '*');
     }
     if ($this->response instanceof StreamedResponse) {
         $this->response->setCallback(function () {
             $this->renderDeferred();
             flush();
         });
     } else {
         ob_start();
         $this->renderDeferred();
         $json = ob_get_contents();
         ob_end_clean();
         // padded response is js, not json
         if (Util\Debug::isActivated() && !$this->padding) {
             $json = Util\JSON::format($json);
         }
         $this->response->setContent($json);
     }
     return $this->response;
 }