Documentation

No matching pages.

API

Config

Facade

Lifecycle

Class: Cookies

Full name: Azera\Http\Cookies

Cookie jar that manages a collection of Cookie instances for the current request.

Public methods

__construct() ·

public function __construct(Azera\Http\Request|null $request = null): mixed

Parameters

Name Type Default Description
$request Request|null null The request whose cookies this jar reads.

Return value

  • Type: mixed

get() ·

public function get(string $name, mixed $default = null): mixed

Read a cookie value from this jar or the incoming request.

A cookie obtained through cookie() uses its configured value and encryption settings. Otherwise, the request value is returned unchanged. Configure encrypted cookies before calling this method; the jar cannot infer which cookie names require encryption:

$cookies->cookie('auth')->encrypted()->key($key);
$value = $cookies->get('auth');

Parameters

Name Type Default Description
$name string - Cookie name.
$default mixed null Default value when the cookie is absent.

Return value

  • Type: mixed

public function cookie(string $name): Azera\Http\Cookie

Get (or lazily create) a Cookie instance for the given name.

Use this when you need to configure encryption, path, etc. before reading or sending the cookie. The cookie is loaded with the incoming value, so Cookie::value() decrypts it as usual.

Parameters

Name Type Default Description
$name string - Cookie name.

Return value


set() ·

public function set(string $name, mixed $value, int $expires = 0, string $path = '/', string $domain = '', bool $secure = false, bool $httpOnly = true, string $sameSite = ''): Azera\Http\Cookie

Create and register a new Cookie with the given parameters.

The cookie is not sent until applyTo() drains the jar.

Parameters

Name Type Default Description
$name string - Cookie name.
$value mixed - Cookie value.
$expires int 0 Expiration timestamp (0 = session cookie).
$path string '/' URL path scope.
$domain string '' Domain scope.
$secure bool false Send over HTTPS only.
$httpOnly bool true Inaccessible to JavaScript.
$sameSite string '' SameSite attribute: 'Lax', 'Strict' or 'None'.

Return value

  • Type: Cookie
  • Description: The newly created Cookie instance for further configuration.

delete() ·

public function delete(string $name): void

Delete a cookie by making the response carry a past-expiry Set-Cookie.

Works for a cookie that was never registered, and does not depend on setcookie() — a worker is not a SAPI, so setcookie() does nothing there.

Parameters

Name Type Default Description
$name string - Cookie name.

Return value

  • Type: void

clear() ·

public function clear(): void

Drop every queued cookie so this response carries none.

The counterpart to the automatic drain: writing a cookie and then deciding the response should not carry it (a 304, an error path) needs an off switch.

Reading is unaffected — the incoming values live on the Request, not in this jar — so clear() only stops emission.

Return value

  • Type: void

applyTo() ·

public function applyTo(Azera\Http\Response $response): Azera\Http\Response

Write the cookies that changed in this request onto the response.

Only dirty cookies are emitted: a cookie the application merely read must not come back as a Set-Cookie. The dirty flag is cleared afterwards, so calling this twice in one request cannot duplicate a header.

Returns the same instance so a caller can chain it, and so Dispatcher::finalize() can simply return the result.

Parameters

Name Type Default Description
$response Response -

Return value


Back to the Index