drewlabs / http-cookie
HTTP Cookie 实现库
v0.2.0
2023-08-01 12:26 UTC
Requires
- php: ^7.1|^8.0
Requires (Dev)
- phpunit/phpunit: >=6.0
This package is auto-updated.
Last update: 2024-09-03 14:54:03 UTC
README
提供 HTTP Cookie 对象实现。它提供了一个工厂类和一个代理类来创建 Cookie 实例。
用法
要创建一个 Cookie 实例,只需使用工厂类或工厂代理类
use Drewlabs\Cookies\Factory; $factory = new Factory; $cookie = $factory->create('sessionid', random_int(10000, 100000) . time()); // CookieInterface // API $cookie->getName(); // sessionid -> Returns the cookie name $cookie->getValue(); // -> Returns cookie value $cookie->isHttpOnly(); // Check if the cookie is http only $cookie->isSecure(); // Check if the cookie is secure // etc...
使用工厂代理类
use Drewlabs\Cookies\FactoryProxy as Factory; $cookie = Factory::create('sessionid', random_int(10000, 100000) . time()); // CookieInterface
注意 提供的 Cookie 实例是一个 Stringable
实例,它允许开发者轻松地将 Cookie 实例转换为 HTTP Cookie 字符串
use Drewlabs\Cookies\FactoryProxy as Factory; $cookie = Factory::create('sessionid', random_int(10000, 100000) . time()); // CookieInterface printf("%s\n", (string)$cookie); // sessionid=428461690891271; Path=/; Secure; HttpOnly; SameSite=Lax