From 6161cacb108b7d28d1fb91fe556bc05fea2884fb Mon Sep 17 00:00:00 2001 From: SuperToma Date: Fri, 1 Jun 2018 18:12:30 +0200 Subject: [PATCH 1/2] Fix #61. Serialize data in session : object saved in session return __PHP_Incomplete_Class_Name --- src/Storage/SessionStorage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Storage/SessionStorage.php b/src/Storage/SessionStorage.php index 92e9997..155d9d8 100644 --- a/src/Storage/SessionStorage.php +++ b/src/Storage/SessionStorage.php @@ -27,7 +27,7 @@ public function set($key, $value) $this->validateKey($key); $name = $this->getStorageKeyId($key); - $_SESSION[$name] = $value; + $_SESSION[$name] = serialize($value); } /** @@ -38,7 +38,7 @@ public function get($key) $this->validateKey($key); $name = $this->getStorageKeyId($key); - return isset($_SESSION[$name]) ? $_SESSION[$name] : null; + return isset($_SESSION[$name]) ? unserialize($_SESSION[$name]) : null; } /** From da366273725c85cbfa9e99bcc098058508781a31 Mon Sep 17 00:00:00 2001 From: SuperToma Date: Mon, 4 Jun 2018 11:41:02 +0200 Subject: [PATCH 2/2] #61 : Fix tests --- tests/Storage/SessionStorageTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Storage/SessionStorageTest.php b/tests/Storage/SessionStorageTest.php index 826ba09..5d01e00 100644 --- a/tests/Storage/SessionStorageTest.php +++ b/tests/Storage/SessionStorageTest.php @@ -26,7 +26,7 @@ public function setUp() public function testSet() { $this->storage->set('code', 'foobar'); - $this->assertEquals($_SESSION[$this->prefix.'code'], 'foobar'); + $this->assertEquals($_SESSION[$this->prefix.'code'], serialize('foobar')); } /** @@ -43,10 +43,9 @@ public function testGet() $result = $this->storage->get('state'); $this->assertNull($result); - $expected = 'foobar'; - $_SESSION[$this->prefix.'code'] = $expected; + $_SESSION[$this->prefix.'code'] = serialize('foobar'); $result = $this->storage->get('code'); - $this->assertEquals($expected, $result); + $this->assertEquals('foobar', $result); } public function testClear()