Example #1
0
File: api.php Project: netbiel/core
 public function after()
 {
     switch ($this->format) {
         case self::FORMAT_JSON:
             $this->request->headers['Content-Type'] = 'application/json';
             $this->request->response = json_encode($this->data);
             break;
         case self::FORMAT_XML:
             $this->request->headers['Content-Type'] = 'application/xml';
             $this->request->response = Arr::xml($this->data);
             break;
     }
 }
Example #2
0
File: api.php Project: anqh/core
 /**
  * Output response.
  */
 public function after()
 {
     switch ($this->format) {
         // Support JSON and JSONP
         case self::FORMAT_JSON:
             $this->response->headers('Content-Type', 'application/json');
             // Check and sanitize JSONP
             $jsonp = Arr::get($_REQUEST, 'callback');
             if ($jsonp && Valid::alpha_dash($jsonp)) {
                 $this->response->body($jsonp . '(' . json_encode($this->data) . ')');
             } else {
                 $this->response->body(json_encode($this->data));
             }
             break;
         case self::FORMAT_XML:
             $this->response->headers('Content-Type', 'application/xml');
             $this->response->body(Arr::xml($this->data));
             break;
     }
 }