Skip to content

Latest commit

 

History

History
65 lines (54 loc) · 2.74 KB

cookie-HttpCookieHandler.md

File metadata and controls

65 lines (54 loc) · 2.74 KB

Cookie / HttpCookieHandler

im\http\HttpCookieHandler


Description

An implementation of the im\http\CookieHandler interface

Synopsis

class HttpCookieHandler implements im\http\CookieHandler {

    // Inherited Constants
    public int F_LAX = 0x01
    public int F_STRICT = 0x03
    public int F_SECURE = 0x08
    public int F_NOSCRIPT = 0x10

    // Methods
    public __construct(null|string $prefix = NULL, null|string $path = NULL, null|string $domain = NULL)
    public writeToResponse(im\http\msg\ResponseBuilder $response): void
    public readFromRequest(im\http\msg\Request $request): void
    public set(string $name, string $value, int $expires = 0, null|string $path = NULL, int $flags = 0): void
    public get(string $name): null|string
    public remove(string $name): void
    public has(string $name): bool
}

Constants

Name Description
HttpCookieHandler :: F_LAX Set SameSite to Lax mode
HttpCookieHandler :: F_STRICT Set SameSite to Strict mode
HttpCookieHandler :: F_SECURE Set the Secure flag on this cookie
HttpCookieHandler :: F_NOSCRIPT Set the HttpOnly flag on this cookie

Methods

Name Description
HttpCookieHandler :: __construct
HttpCookieHandler :: writeToResponse Write all cookies to the headers of a response object
HttpCookieHandler :: readFromRequest Extract cookies from the headers of a request object
HttpCookieHandler :: set Add a new cookie
HttpCookieHandler :: get Get the value of a cookie
HttpCookieHandler :: remove Delete a cookie set by this handle
HttpCookieHandler :: has Check if a cookie exists

Example 1

$request = new ServerRequestBuilder();
$handler = new CookieHandler();

// Extract cookies from the request
$handler->readFromRequest($request);

// Set a new cookie
$handler->set("some_name", "Some Value", 3600 * 24, null, CookieHandler::F_SECURE);

// Remove a cookie
$handler->remove("another_name");

// Write this information into the response headers
$response = new HttpResponseBuilder();
$handler->writeToResponse($response);