Download src/Presentation/Cookies/UserCookie.php from pnacorp/AIKEEDO: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Presentation/Cookies/UserCookie.php
- Command line
-
hf download hf://pnacorp/AIKEEDO/src/Presentation/Cookies/UserCookie.php
-
curl -L -o UserCookie.php https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Presentation/Cookies/UserCookie.php
1.14 kB
| declare(strict_types=1); | |
| namespace Presentation\Cookies; | |
| use DateTime; | |
| use InvalidArgumentException; | |
| use Psr\Http\Message\ServerRequestInterface; | |
| class UserCookie extends Cookie | |
| { | |
| private const NAME = 'user'; | |
| /** | |
| * @param string $value | |
| * @return void | |
| * @throws InvalidArgumentException | |
| */ | |
| public function __construct(string $value) | |
| { | |
| parent::__construct( | |
| self::NAME, | |
| $value, | |
| new DateTime('@' . (time() + 86400 * 30)), | |
| '/', | |
| secure: env('ENVIRONMENT') == 'demo', | |
| sameSite: env('ENVIRONMENT') == 'demo' ? 'none' : null | |
| ); | |
| } | |
| /** | |
| * Create an instance of this object with the | |
| * cookies values from the request | |
| * | |
| * @param ServerRequestInterface $req | |
| * @return null|UserCookie | |
| */ | |
| public static function createFromRequest( | |
| ServerRequestInterface $req | |
| ): ?UserCookie { | |
| $cookies = $req->getCookieParams(); | |
| if (isset($cookies[self::NAME])) { | |
| return new UserCookie($cookies[self::NAME]); | |
| } | |
| return null; | |
| } | |
| } | |