From 9f35f834cbbd571fb622e56e45246df9d29ac683 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Fri, 26 Jan 2018 20:25:58 +0200 Subject: [PATCH] accept dot notation in session::exists --- src/Illuminate/Session/Store.php | 7 +++++-- tests/Session/SessionStoreTest.php | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Session/Store.php b/src/Illuminate/Session/Store.php index 0f4f20c9391e..99bf82b37e6f 100755 --- a/src/Illuminate/Session/Store.php +++ b/src/Illuminate/Session/Store.php @@ -3,6 +3,7 @@ namespace Illuminate\Session; use Closure; +use stdClass; use Illuminate\Support\Arr; use Illuminate\Support\Str; use SessionHandlerInterface; @@ -174,8 +175,10 @@ public function all() */ public function exists($key) { - return ! collect(is_array($key) ? $key : func_get_args())->contains(function ($key) { - return ! Arr::exists($this->attributes, $key); + $placeholder = new stdClass(); + + return ! collect(is_array($key) ? $key : func_get_args())->contains(function ($key) use ($placeholder) { + return $this->get($key, $placeholder) === $placeholder; }); } diff --git a/tests/Session/SessionStoreTest.php b/tests/Session/SessionStoreTest.php index 14192bb9b0e7..812842412b88 100644 --- a/tests/Session/SessionStoreTest.php +++ b/tests/Session/SessionStoreTest.php @@ -324,11 +324,14 @@ public function testKeyExists() $session->put('foo', 'bar'); $this->assertTrue($session->exists('foo')); $session->put('baz', null); + $session->put('hulk', ['one' => true]); $this->assertFalse($session->has('baz')); $this->assertTrue($session->exists('baz')); $this->assertFalse($session->exists('bogus')); $this->assertTrue($session->exists(['foo', 'baz'])); $this->assertFalse($session->exists(['foo', 'baz', 'bogus'])); + $this->assertTrue($session->exists(['hulk.one'])); + $this->assertFalse($session->exists(['hulk.two'])); } public function testRememberMethodCallsPutAndReturnsDefault()