From ff5b6315bcf4ebdf897bf9d0e08cff9d8423ce43 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 10 Dec 2011 21:56:42 -0600 Subject: [PATCH] added array access to session::Get --- changelog.md | 1 + laravel/session/payload.php | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index b3064ae1..0babba12 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ # Laravel Change Log ## Version 2.0.5 +- Feature: Added array access to session::get. - Fix: Remove orderings before running pagination queries. - Fix: Session flush now correctly prepares empty data. - Fix: DB::raw now works on Eloquent properties. diff --git a/laravel/session/payload.php b/laravel/session/payload.php index ce13a9bd..232a854d 100644 --- a/laravel/session/payload.php +++ b/laravel/session/payload.php @@ -142,17 +142,23 @@ public function has($key) */ public function get($key, $default = null) { - if (isset($this->session['data'][$key])) + $session = $this->session['data']; + + // We check for the item in the general session data first, and if it + // does not exist in that data, we will attempt to find it in the new + // and old flash data. If none of those arrays contain the requested + // item, we will just return the default value. + if ( ! is_null($value = Arr::get($session, $key))) { - return $this->session['data'][$key]; + return $value; } - elseif (isset($this->session['data'][':new:'][$key])) + elseif ( ! is_null($value = Arr::get($session[':new:'], $key))) { - return $this->session['data'][':new:'][$key]; + return $value; } - elseif (isset($this->session['data'][':old:'][$key])) + elseif ( ! is_null($value = Arr::get($session[':old:'], $key))) { - return $this->session['data'][':old:'][$key]; + return $value; } return ($default instanceof Closure) ? call_user_func($default) : $default;