ytake/hack-cookie

HHVM和Hack Cookies用于facebook/hack-http-request-response-interfaces。

资助包维护!
ytake

安装: 4

依赖项: 0

建议者: 0

安全: 0

星级: 1

关注者: 3

分支: 3

公开问题: 0

语言:Hack

0.1.1 2020-07-14 04:40 UTC

This package is auto-updated.

Last update: 2024-09-14 13:48:56 UTC


README

Build Status

管理facebook/hack-http-request-response-interfaces的Cookies。

仅支持Hack库。需要HHVM >= 4.41.0

安装

$> composer require ytake/hack-cookie

基本用法

请求Cookies

use type Ytake\HackCookie\Cookie;

$cookie = Cookie::create('theme', 'blue');

获取请求Cookies

use type Ytake\HackCookie\RequestCookies;
use type Ytake\Hungrr\{Request, Uri};
use namespace HH\Lib\IO;

$request = new Request(Message\HTTPMethod::GET, new Uri('/'), IO\request_input);

$cookie = RequestCookies::get($request, 'theme');
$cookie = RequestCookies::get($request, 'theme', 'default-theme');

设置请求Cookies

use type Ytake\HackCookie\RequestCookies;
use type Ytake\Hungrr\{Request, Uri};
use namespace HH\Lib\IO;

$request = new Request(Message\HTTPMethod::GET, new Uri('/'), IO\request_input);

$request = RequestCookies::set($request, Cookie::create('theme', 'blue'));

修改请求Cookies

use type Ytake\HackCookie\{Cookie, Cookies, RequestCookies};
use type Ytake\Hungrr\{Request, Uri};
use namespace HH\Lib\IO;

$modify = (Cookie $cookie) ==> { 
  return $cookie->getValue()
    |> $cookie->withValue($$);
}
$request = new Request(Message\HTTPMethod::GET, new Uri('/'), IO\request_input);
$request = RequestCookies::modify($request, 'theme', $modify);

响应Cookies

use type Ytake\HackCookie\{SameSite, SetCookie};

SetCookie::create('lu')
  ->withValue('Rg3vHJZnehYLjVg7qi3bZjzg')
  ->withExpires(new \DateTime('Tue, 15-Jan-2020 21:47:38 GMT'))
  ->withMaxAge(500)
  ->withPath('/')
  ->withDomain('.example.com')
  ->withSecure(true)
  ->withHttpOnly(true)
  ->withSameSite(SameSite::LAX);

等等。