From 138d08c04bac599a4f305c12a4ec84825051221d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 2 May 2012 08:09:23 -0500 Subject: [PATCH] added Requst::json method. --- laravel/documentation/changes.md | 1 + laravel/request.php | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/laravel/documentation/changes.md b/laravel/documentation/changes.md index ad76b6d9..3dc6b568 100644 --- a/laravel/documentation/changes.md +++ b/laravel/documentation/changes.md @@ -67,6 +67,7 @@ - Allow a `starter` Closure to be defined in `bundles.php` to be run on Bundle::start. - Allow the registration of custom database drivers. - New, driver based authentication system. +- Added Request::json() method for working with applications using Backbone.js or similar. ## Upgrading From 3.1 diff --git a/laravel/request.php b/laravel/request.php index 8b90dba5..39d0c0f5 100644 --- a/laravel/request.php +++ b/laravel/request.php @@ -9,6 +9,13 @@ class Request { */ public static $route; + /** + * The JSON payload for applications using Backbone.js or similar. + * + * @var object + */ + public static $json; + /** * The Symfony HttpFoundation Request instance. * @@ -72,6 +79,18 @@ class Request { return static::foundation()->headers->all(); } + /** + * Get the JSON payload for the request. + * + * @return object + */ + public static function json() + { + if ( ! is_null(static::$json)) return static::$json; + + return static::$json = json_decode(static::foundation()->getContent()); + } + /** * Get an item from the $_SERVER array. * @@ -232,7 +251,7 @@ class Request { { // Essentially we just want to loop through each environment pattern // and determine if the current URI matches the pattern and if so - // we'll simply return the environment for that URI pattern. + // we will simply return the environment for that URI pattern. foreach ($patterns as $pattern) { if (Str::is($pattern, $uri))