Skip to content

Commit

Permalink
accept dot notation in session::exists (#22935)
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid authored and taylorotwell committed Jan 29, 2018
1 parent c89439e commit 862bb83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Illuminate/Session/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Session;

use Closure;
use stdClass;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use SessionHandlerInterface;
Expand Down Expand Up @@ -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;
});
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Session/SessionStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 862bb83

Please sign in to comment.