pollen-solutions/cookie
Composer 安装命令:
composer require pollen-solutions/cookie
包简介
Pollen Solutions - Cookie Component - HTTP Request cookie manager
README 文档
README
Pollen Solutions Cookie Component is HTTP Request cookie manager.
Installation
composer require pollen-solutions/cookie
Basic Usage
use Pollen\Cookie\CookieJar; $cookieJar = new CookieJar(); $cookieJar->make('cookie.test.1', ['value' => 'test1']); $cookieJar->make( 'cookie.test.2', [ 'name' => 'cookie_test_2', 'salt' => '_' . md5('cookie.test.2.salt'), 'value' => [ 'test2-value1', 'test2-value2' ], 'encrypted' => true, 'prefix' => 'testprefix_', 'lifetime' => 3600, //'path' => 'site-base_path', //'domain' => 'site-domaine.ltd', 'secure' => false, 'httpOnly' => false, 'raw' => true, 'sameSite' => 'strict', ] ); // Get the cookie instances. $cookie1 = $cookieJar->get('cookie.test.1'); $cookie2 = $cookieJar->get('cookie.test.2'); var_dump((string)$cookie1); var_dump((string)$cookie2); exit;
Send Cookie
PSR-7 environnement
use Laminas\Diactoros\Response; use Laminas\HttpHandlerRunner\Emitter\SapiEmitter; /** @var \Pollen\Cookie\CookieJarInterface $cookieJar */ $cookie = $cookieJar->make('cookie.test', ['value' => 'test']); $response = new Response(); $response = $response->withAddedHeader('Set-Cookie', (string)$cookie); (new SapiEmitter())->emit($response); exit;
Pollen Solutions Http environnement
use Pollen\Http\Response as HttpResponse; /** @var \Pollen\Cookie\CookieJarInterface $cookieJar */ $cookie = $cookieJar->make('cookie.test', ['value' => 'test']); $httpResponse = new HttpResponse(); $httpResponse->headers->setCookie($cookie); $httpResponse->send();
Get HTTP Request cookie value
use Pollen\Cookie\CookieInterface; use Pollen\Http\Request as HttpRequest; // In this example, we consider : // - Global $cookieJar as an implemented instance of CookieJar. // - An HTTP Response was already sent with cookie1 and cookie2. @see "Send Cookie" above. /** @var \Pollen\Cookie\CookieJarInterface $cookieJar */ $cookie1 = $cookieJar->get('cookie1'); $cookie1 = $cookieJar->get('cookie2'); $httpValue1 = $cookie1->httpValue(); $httpValue2 = $cookie2->httpValue(HttpRequest::createFromGlobals()); var_dump($httpValue1, $httpValue2);
Check HTTP Request cookie value
use Pollen\Http\Request as HttpRequest; // In this example, we consider : // - Global $cookieJar as an implemented instance of CookieJar. // - An HTTP Response was already sent with cookie.test with the value 'test'. @see "Send Cookie" above. /** @var \Pollen\Cookie\CookieJarInterface $cookieJar */ $cookie = $cookieJar->make('cookie.test', ['value' => 'test']); var_dump($cookie->checkRequestValue());
Queued Cookie and QueuedCookiesMiddleware (Pollen Routing example)
use Pollen\Cookie\CookieJar; use Pollen\Cookie\Middleware\QueuedCookiesMiddleware; use Pollen\Http\Request; use Pollen\Http\Response; use Pollen\Http\ResponseInterface; use Pollen\Routing\Router; // Create the Request object $request = Request::createFromGlobals(); // CookieJar instantiation $cookieJar = (new CookieJar())->setDefaults($request->getBasePath()); // CookieJar hydratation $cookie = $cookieJar->make('cookie.test', ['value' => 'test2'])->queue(); // Router instantiation $router = new Router(); // Setting QueuedCookiesMiddleware $router->middleware(new QueuedCookiesMiddleware($cookieJar)); // Map a route $router->map('GET', '/', function (): ResponseInterface { return new Response('<h1>Hello, World!</h1>'); }); // Catch HTTP Response $response = $router->handleRequest($request); // Send the response to the browser $router->sendResponse($response); // Trigger the terminate event $router->terminateEvent($request, $response);
pollen-solutions/cookie 适用场景与选型建议
pollen-solutions/cookie 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「component」 「cookie」 「pollen-solutions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pollen-solutions/cookie 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pollen-solutions/cookie 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pollen-solutions/cookie 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add a configurable cookie consent banner to the website.
FSi DataSource Component
Priveate for SkeekS CMS
Popup component for Nette Framework
Cookie Consent is a lightweight JavaScript plugin for alerting users about the use of cookies on your website.
Pollen Validation Component - Validation values tools.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2021-08-13