Skip to content

Commit

Permalink
feat: use new config API
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Aug 19, 2024
1 parent 3807ba8 commit c6e68cd
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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'),
\Leaf\Config::getStatic('response.cookies'),
[$key => [$value, $options['expires'] ?? (time() + 604800)]],
));

Expand Down Expand Up @@ -88,16 +88,7 @@ public static function set($key, $value = '', array $options = [])
*/
public static function simpleCookie(string $name, string $value, string $expires = null)
{
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() + 604800)]],
));

return;
}

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

/**
Expand Down Expand Up @@ -125,7 +116,7 @@ public static function unset($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'),
\Leaf\Config::getStatic('response.cookies'),
[$key => ['', time() - 604800]],
));
}
Expand Down

0 comments on commit c6e68cd

Please sign in to comment.