wellrested/cookies
Composer 安装命令:
composer require wellrested/cookies
包简介
Helper classes for creating cookie headers
README 文档
README
This package provides CookieFactory, a class that facilitates creating Set-cookie headers.
To install, add wellrested/cookies to your project's composer.json.
{
"require": {
"wellrested/cookies": "~1.0"
}
}
Example
Use a CookieFactory to create the values for Set-cookie headers.
<?php use WellRESTed\Cookies\CookieFactory; $cookieFactory = new CookieFactory(); $cookie = $cookieFactory->create('name', 'value'); // name=value
Use these with the PSR-7 ResponseInterface->withAddedHeader to add cookies to a response.
$response = $response ->withAddedHeader('Set-cookie', $cookieFactory->create('name', 'value')) ->withAddedHeader('Set-cookie', $cookieFactory->create('another', 'something-else')));
To configure a CookieFactory to provide Domain, Path, Secure, and HttpOnly, pass these to the contructor.
$cookieFactory = new CookieFactory( 'www.example.com', // Domain '/', // Path true, // Secure true // HttpOnly ); $cookie = $cookieFactory->create('name', 'value'); // name=value; Domain=www.example.com; Path=/; Secure; HttpOnly
Expires and Max-Age
By default, create() will make session cookies that expire when the user closes the browser. To create a persistant cookie, provide the expiration as the third argument. This argument can several forms:
Numeric values are read as seconds for Max-Age.
$cookie = $cookieFactory->create('name', 'value', 3600); // name=value; Max-Age=3600
Use a DateTime instance to set a specific expiration time. Note that CookieFactory will convert this DateTime to an HTTP-date in the format <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT in accordance with RFC7321.
$cookie = $cookieFactory->create('name', 'value', new DateTime('31-Dec-2018 23:00:00 EST')); // name=value; Expires=Tue, 01 Jan 2019 04:00:00 GMT
You may also provide a string which will be used as-is for the expiration. When you provide a string, you are responsible for formatting the date.
$cookie = $cookieFactory->create('name', 'value', new DateTime('Tue, 01 Jan 2019 04:00:00 GMT')); // name=value; Expires=Tue, 01 Jan 2019 04:00:00 GMT
Removing Cookies
To remove a cookie, use the remove method to create a Set-cookie header that sets the value for the cookie to an empty string and sets the expiration to a date in the past.
$cookie = $cookieFactory->remove('name'); // name=; Expires=Thu, 01 Jan 1970 00:00:00 GMT
Development
To setup a local development enviroment, close this repositoy and run:
docker-compose build docker-compose run --rm php composer install
To run unit tests, run:
docker-compose run --rm php phpunit
wellrested/cookies 适用场景与选型建议
wellrested/cookies 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「rest」 「api」 「restful」 「cookie」 「psr-7」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wellrested/cookies 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wellrested/cookies 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wellrested/cookies 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
http客户端
Easily add Excepct-CT header to your project
Build mini web servers in PHP for testing
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-11