hansott / psr7-cookies
🍪 bakes cookies for PSR-7 messages
Fund package maintenance!
hansott
Installs: 2 144 381
Dependents: 18
Suggesters: 1
Security: 0
Stars: 40
Watchers: 2
Forks: 4
Open Issues: 4
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
Install
Via Composer
$ composer require hansott/psr7-cookies
Usage
Add cookie to Psr\Http\Message\ResponseInterface
<?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);
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email hans at iott consulting instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.