Example #1
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;
 }
Example #2
0
 /**
  * Render response and send it to the client
  */
 public function send()
 {
     if (Util\Debug::isActivated()) {
         $this->add(Util\Debug::getInstance());
     }
     $this->response->setContent($this->render());
     return $this->response;
 }
Example #3
0
 /**
  * Constructor
  */
 public function __construct(Request $request)
 {
     parent::__construct($request);
     $this->prepareResponse();
     // use StreamedResponse unless pretty-printing is required
     if (Util\Debug::isActivated()) {
         $this->add(Util\Debug::getInstance());
     } else {
         $this->response = new StreamedResponse();
     }
     // add JSON headers
     $this->response->headers->set('Content-Type', 'application/json');
     $this->response->headers->set('Access-Control-Allow-Origin', '*');
 }
Example #4
0
 /**
  * Render response and send it to the client
  */
 public function send()
 {
     if (Util\Debug::isActivated()) {
         $this->add(Util\Debug::getInstance());
     }
     $this->render();
     $this->response->send();
 }