- Two bugfixes made within the Cookie class
This commit is contained in:
parent
fd547dc346
commit
9bf167f782
|
@ -75,6 +75,8 @@ class Cookie {
|
|||
*/
|
||||
public function get(string $key, $default = null, $skipHash = false)
|
||||
{
|
||||
$key = $this->normalizeKey($key);
|
||||
|
||||
if ( ! $this->has($key) ) {
|
||||
return $default;
|
||||
}
|
||||
|
@ -98,6 +100,8 @@ class Cookie {
|
|||
|
||||
public function has($key) : bool
|
||||
{
|
||||
$key = $this->normalizeKey($key);
|
||||
|
||||
return array_key_exists($key, $_COOKIE ?? []);
|
||||
}
|
||||
|
||||
|
@ -108,14 +112,16 @@ class Cookie {
|
|||
* @param string URL domain
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete(string $name, ?string $path = null, ?string $domain = null) {
|
||||
if ( ! $this->has($name) ) {
|
||||
public function delete(string $key, ?string $path = null, ?string $domain = null) {
|
||||
$key = $this->normalizeKey($key);
|
||||
|
||||
if ( ! $this->has($key) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unset( $_COOKIE[$name] );
|
||||
unset( $_COOKIE[$key] );
|
||||
|
||||
return $this->set($name, '', -86400, $path ?: ( $this->options['path'] ?? "" ), $domain ?: ( $this->options['domain'] ?? "" ), $this->options['secure'] ?? false, $this->options['httponly'] ?? false, null, false, true);
|
||||
return $this->set($key, '', -86400, $path ?: ( $this->options['path'] ?? "" ), $domain ?: ( $this->options['domain'] ?? "" ), $this->options['secure'] ?? false, $this->options['httponly'] ?? false, null, false, true);
|
||||
}
|
||||
|
||||
public function isSecure($hash, $value) : bool
|
||||
|
@ -143,11 +149,16 @@ class Cookie {
|
|||
|
||||
public function __isset($key)
|
||||
{
|
||||
return array_key_exists($key, $_SESSION);
|
||||
return array_key_exists($key, $_COOKIE);
|
||||
}
|
||||
|
||||
public function __unset($key)
|
||||
{
|
||||
$this->delete($key);
|
||||
}
|
||||
|
||||
protected function normalizeKey(string $key) : string
|
||||
{
|
||||
return str_replace(['.', ' ',], '_', $key);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue