hansott/psr7-cookies

🍪 为 PSR-7 消息制作 cookies

支持包维护!
hansott

4.0.0 2024-01-08 11:06 UTC

This package is auto-updated.

Last update: 2024-09-08 12:32:09 UTC


README

Latest Version on Packagist Supported PHP versions Total Downloads Software License

安装

通过 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

贡献

请参阅 CONTRIBUTINGCONDUCT 以获取详细信息。

安全

如果您发现任何安全相关的问题,请通过电子邮件 hans at iott consulting 而不是使用问题跟踪器。

致谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件