hansott / psr7-cookies
🍪 为 PSR-7 消息制作 cookies
4.0.0
2024-01-08 11:06 UTC
Requires
- php: ^7.0 || ^8.0
- psr/http-message: ^2.0
Requires (Dev)
- guzzlehttp/psr7: ^2.0
- phpunit/phpunit: ^6.0 || ^7.0 || ^8.0 || ^9.0
- scrutinizer/ocular: ~1.1
README
安装
通过 Composer
$ composer require hansott/psr7-cookies
使用方法
向 Psr\Http\Message\ResponseInterface 添加 cookie
<?php use HansOtt\PSR7Cookies\SetCookie; // Set a cookie with custom values. $cookie = new SetCookie('name', 'value', time() + 3600, '/path', 'domain.tld', $secure, $httpOnly, $sameSite); // Set a cookie to delete a cookie. $cookie = SetCookie::thatDeletesCookie('name'); // Set a cookie that stays forever (5 years) $cookie = SetCookie::thatStaysForever('name', 'value'); // Set a cookie that expires at a given time. $now = new DateTimeImmutable(); $tomorrow = $now->modify('tomorrow'); $cookie = SetCookie::thatExpires('name', 'value', $tomorrow); // Add the cookie to a response $responseWithCookie = $cookie->addToResponse($response);
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CONDUCT 以获取详细信息。
安全
如果您发现任何安全相关的问题,请通过电子邮件 hans at iott consulting 而不是使用问题跟踪器。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。