From fd547dc34623b91429a6e835a73fa971d6abe195 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 12 May 2023 18:56:23 +0000 Subject: [PATCH] - Cookie were not working correctly previously, now fixed --- src/Cookie.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Cookie.php b/src/Cookie.php index 4dc38e3..3a3b7d7 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -47,7 +47,7 @@ class Cookie { return false; } - $expires = ( $expires === 0 ) ? 0 : time() + (int) $expires; + $expires = ! $expires ? 0 : time() + (int) $expires; $_COOKIE[$name] = $value; @@ -80,10 +80,14 @@ class Cookie { } if ( $this->secureHash && ! $skipHash ) { + if (strpos($_COOKIE[$key], '|') === false) { + throw new Exception\CookieInvalidValueException("A cookie value was found which contains no secure hash while a key was provided."); + } + list($hash, $value) = explode('|', $_COOKIE[$key], 2); if (! $this->isSecure($hash, $value)) { - throw new Exception\CookieInvalidSecureHashException(); + throw new Exception\CookieInvalidSecureHashException("Invalid cookie hash value given."); } return $value; @@ -126,4 +130,24 @@ class Cookie { case 2: return $this->set(...$arguments); } } + + public function __set($key, $value) + { + return static::set($key, $value); + } + + public function __get($key) + { + return static::get($key); + } + + public function __isset($key) + { + return array_key_exists($key, $_SESSION); + } + + public function __unset($key) + { + $this->delete($key); + } }