From 5d67672d66153be8554873c08279352e2bdfa9cb Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 22 Sep 2011 00:25:48 -0500 Subject: [PATCH] add comments to response class. --- laravel/response.php | 64 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/laravel/response.php b/laravel/response.php index c1533e18..95a41042 100644 --- a/laravel/response.php +++ b/laravel/response.php @@ -7,28 +7,28 @@ class Response { * * @var mixed */ - public $content; + protected $content; /** * The HTTP status code of the response. * * @var int */ - public $status; + protected $status; /** * The response headers. * * @var array */ - public $headers = array(); + protected $headers = array(); /** * HTTP status codes. * * @var array */ - private $statuses = array( + protected $statuses = array( 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', @@ -95,6 +95,17 @@ public function __construct($content, $status = 200, $headers = array()) /** * Create a new response instance. * + * + * // Create a response instance with string content + * return Response::make(json_encode($user)); + * + * // Create a response instance with a given status + * return Response::make('Not Found', 404); + * + * // Create a response with some custom headers + * return Respone::make(json_encode($user), 200, array('content-type' => 'application/json')); + * + * * @param mixed $content * @param int $status * @param array $headers @@ -108,6 +119,14 @@ public static function make($content, $status = 200, $headers = array()) /** * Create a new response instance containing a view. * + * + * // Create a response instance with a view + * return Response::view('home.index'); + * + * // Create a response instance with a view and data + * return Response::view('home.index', array('name' => 'Taylor')); + * + * * @param string $view * @param array $data * @return Response @@ -120,6 +139,14 @@ public static function view($view, $data = array()) /** * Create a new response instance containing a named view. * + * + * // Create a response with the "layout" named view + * return Response::with('layout'); + * + * // Create a response with the "layout" named view and data + * return Response::with('layout', array('name' => 'Taylor')); + * + * * @param string $name * @param array $data * @return Response @@ -136,6 +163,14 @@ public static function with($name, $data = array()) * * Note: The specified error code should correspond to a view in your views/error directory. * + * + * // Create a 404 response + * return Response::error('404'); + * + * // Create a 404 response with data + * return Response::error('404', array('message' => 'Not Found')); + * + * * @param int $code * @param array $data * @return Response @@ -148,6 +183,14 @@ public static function error($code, $data = array()) /** * Create a new download response instance. * + * + * // 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'); + * + * * @param string $path * @param string $name * @param array $headers @@ -219,6 +262,11 @@ public function send_headers() /** * Add a header to the response. * + * + * // Add a header to a response instance + * return Response::make('foo')->header('content-type', 'application/json'); + * + * * @param string $name * @param string $value * @return Response @@ -243,6 +291,14 @@ public function status($status) /** * Magic Method for handling the dynamic creation of Responses containing named views. + * + * + * // Create a response instance with the "layout" named view + * return Response::with_layout(); + * + * // Create a response instance with a named view and data + * return Response::with_layout(array('name' => 'Taylor')); + * */ public static function __callStatic($method, $parameters) {