A simple php library to manage cookies on PSR7 object
- PHP 7.3 +
- Composer
The recommended way to install is via Composer:
composer require phpatom/cookies
composer test
./vendor/bin/phpcs
# create a new router
use Atom\Cookies\Cookie;
use Atom\Cookies\CookieConfig;
$myCookie = Cookie::create("foo","bar")
->withDomain("mydomain.com")
->withPath("/")
->thatExpiresOn("2 days");
$myCookie->applyTo($response); // ResponseInterface
// Cookie default config
CookieConfig::configure()
->withDomain("foo.com")
->withHttpOnly(true);
//will use default config
$myCookie = new Cookie("foo","bar");
echo $myCookie->getDomain(); // foo.com
echo $myCookie->isHttpOnly(); // true
$cookies = Cookies::of($request);
echo $cookies->get("key"); //value
echo $cookies->get("badkey",'defaultValue'); // defaultValue
var_dump($cookies->getCookies("badkey")); // RequestCookie;
echo $cookies->has("key"); //value boolean
//also works with responses
$cookies = Cookies::of($response);
var_dump($cookies->getCookie("badkey")); // RequestCookie;Cookie
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
- @dani-gouken - Idea & Initial work