Esempio n. 1
0
 /**
  * json response
  * you can pass an array of data wich will be converted to json
  *
  * @param array 			$data
  * @param int			$status
  * @param bool 			$beautify	should the json output be formatted?
  * @return CCResponse
  */
 public static function json($data = array(), $status = 200, $beautify = true)
 {
     if (!is_array($data)) {
         throw new CCException("CCResponse::json - first argument has to be an array.");
     }
     $response = new static(CCJson::encode($data, $beautify), $status);
     $response->header('Content-Type', 'text/json');
     return $response;
 }
Esempio n. 2
0
 public static function init()
 {
     try {
         File::get(COMPONENTS . 'request/headers.' . EXT);
     } catch (Exception $e) {
         die($e->getMessage());
     }
     static::$header = Request\Header::newInstance();
 }
Esempio n. 3
0
 /**
  * Create a new download response instance.
  *
  * <code>
  *		// Create a download response to a given file
  *		return Response::download('path/to/file.jpg');
  *
  *		// Create a download response with a given file name
  *		return Response::download('path/to/file.jpg', 'your_file.jpg');
  * </code>
  *
  * @param  string    $path
  * @param  string    $name
  * @param  array     $headers
  * @return Response
  */
 public static function download($path, $name = null, $headers = array())
 {
     if (is_null($name)) {
         $name = basename($path);
     }
     // We'll set some sensible default headers, but merge the array given to
     // us so that the developer has the chance to override any of these
     // default headers with header values of their own liking.
     $headers = array_merge(array('Content-Description' => 'File Transfer', 'Content-Type' => File::mime(File::extension($path)), 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => File::size($path)), $headers);
     // Once we create the response, we need to set the content disposition
     // header on the response based on the file's name. We'll pass this
     // off to the HttpFoundation and let it create the header text.
     $response = new static(File::get($path), 200, $headers);
     $d = $response->disposition($name);
     return $response->header('Content-Disposition', $d);
 }
Esempio n. 4
0
 /**
  * Create the object with initial data
  * 
  * @param array $data [optional]
  * @return \Koldy\Json
  * @link http://koldy.net/docs/json#usage
  */
 public static function create(array $data = array())
 {
     $self = new static();
     $self->data = $data;
     return $self->header('Content-Type', 'application/json');
 }
Esempio n. 5
0
 public static function download($path, $name = null, $headers = array())
 {
     if (is_null($name)) {
         $name = basename($path);
     }
     $headers = array_merge(array('Content-Description' => 'File Transfer', 'Content-Type' => File::mime(File::extension($path)), 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => File::size($path)), $headers);
     $response = new static(File::get($path), 200, $headers);
     $d = $response->disposition($name);
     return $response->header('Content-Disposition', $d);
 }
 /**
  * Reset collection variables
  */
 private function reset()
 {
     static::$header = static::$total;
     static::$limit = 100;
     static::$total = false;
 }