]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | declare(strict_types=1); | |
4 | ||
5 | namespace Shaarli\Security; | |
6 | ||
7 | class CookieManager | |
8 | { | |
9 | /** @var string Name of the cookie set after logging in **/ | |
10 | public const STAY_SIGNED_IN = 'shaarli_staySignedIn'; | |
11 | ||
12 | /** @var mixed $_COOKIE set by reference */ | |
13 | protected $cookies; | |
14 | ||
15 | public function __construct(array &$cookies) | |
16 | { | |
17 | $this->cookies = $cookies; | |
18 | } | |
19 | ||
20 | public function setCookieParameter(string $key, string $value, int $expires, string $path): self | |
21 | { | |
22 | $this->cookies[$key] = $value; | |
23 | ||
24 | setcookie($key, $value, $expires, $path); | |
25 | ||
26 | return $this; | |
27 | } | |
28 | ||
29 | public function getCookieParameter(string $key, string $default = null): ?string | |
30 | { | |
31 | return $this->cookies[$key] ?? $default; | |
32 | } | |
33 | } |