Skip to content

Commit

Permalink
feat: add support for eien
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Oct 15, 2022
1 parent 18132c4 commit 4308c18
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class Cookie
public static function setDefaults(array $defaults)
{
static::$options = array_merge(
static::$options, $defaults
static::$options,
$defaults
);
}

Expand All @@ -56,7 +57,7 @@ public static function set($key, $value = '', array $options = [])
if (class_exists('Leaf\Eien\Server') && PHP_SAPI === 'cli') {
\Leaf\Config::set('response.cookies', array_merge(
\Leaf\Config::get('response.cookies'),
[$key, $value, $options['expires'] ?? (time() + (60 * 60 * 24 * 7))],
[$key, $value, $options['expires'] ?? (time() + 604800)],
));

return;
Expand Down Expand Up @@ -90,21 +91,21 @@ public static function simpleCookie(string $name, string $value, string $expires
if (class_exists('Leaf\Eien\Server') && PHP_SAPI === 'cli') {
\Leaf\Config::set('response.cookies', array_merge(
\Leaf\Config::get('response.cookies'),
[$name, $value, $expires ?? (time() + (60 * 60 * 24 * 7))],
[$name, $value, $expires ?? (time() + 604800)],
));

return;
}

self::set($name, $value, ['expires' => $expires ?? (time() + (60 * 60 * 24 * 7))]);
self::set($name, $value, ['expires' => $expires ?? (time() + 604800)]);
}

/**
* Get all set cookies
*/
public static function all(): array
{
return $_COOKIE;
{
return $_COOKIE ?? [];
}

/**
Expand All @@ -122,6 +123,13 @@ public static function unset($key)
{
if (is_array($key)) {
foreach ($key as $name) {
if (class_exists('Leaf\Eien\Server') && PHP_SAPI === 'cli') {
\Leaf\Config::set('response.cookies', array_merge(
\Leaf\Config::get('response.cookies'),
[$key, '', time() - 604800],
));
}

self::unset($name);
}
} else {
Expand Down

0 comments on commit 4308c18

Please sign in to comment.