agent foundation
This commit is contained in:
34
lib/Http/CookieStore.php
Normal file
34
lib/Http/CookieStore.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Http;
|
||||
|
||||
class CookieStore implements CookieStoreInterface
|
||||
{
|
||||
public function get(string $name): string
|
||||
{
|
||||
return (string) ($_COOKIE[$name] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function set(string $name, string $value, array $options = []): void
|
||||
{
|
||||
setcookie($name, $value, $options);
|
||||
$_COOKIE[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function remove(string $name, array $options = []): void
|
||||
{
|
||||
$removeOptions = ['expires' => time() - 3600, 'path' => '/'];
|
||||
foreach ($options as $key => $value) {
|
||||
$removeOptions[$key] = $value;
|
||||
}
|
||||
|
||||
setcookie($name, '', $removeOptions);
|
||||
unset($_COOKIE[$name]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user