• Full name: \App\Infrastructure\Services\NativePhpCookies
  • This class is marked as final and can't be subclassed
  • This class is a Final class

Methods

factory

public static factory(): self
  • This method is static.

token

Generates a random token which is then hashed.

public token(int $length = 20): string

Parameters:

Parameter Type Description
$length int

set

Sets a regular cookie

public set(mixed $key, mixed $value, int|null $expires = null): bool

Parameters:

Parameter Type Description
$key mixed
$value mixed
$expires int|null

Throws:


get

Retrieves a regular cookie if it is set.

public get(string $key): string

Parameters:

Parameter Type Description
$key string

Return Value:

Returns cookie if valid


setSecureCookie

Set a secure cookie that is saved to the server.

public setSecureCookie(array $data): bool

Parameters:

Parameter Type Description
$data array

Throws:


getSecureCookie

public getSecureCookie(mixed $key): mixed

Parameters:

Parameter Type Description
$key mixed

remove

Unset the cookie

public remove(mixed $key): bool

Parameters:

Parameter Type Description
$key mixed

Throws:


buildCookie

Generates a hardened cookie string with digest.

public buildCookie(mixed $data, mixed $expires): string

Parameters:

Parameter Type Description
$data mixed Cookie value: e.g. random token or hash
$expires mixed

getCookieVars

Extracts data from the cookie string.

public getCookieVars(string $key, mixed $str): string

Parameters:

Parameter Type Description
$key string
$str mixed

getCookieData

Extracts the data from the cookie string.

public getCookieData(mixed $key): string

This does not verify the cookie! This is just so you can get the token.

Parameters:

Parameter Type Description
$key mixed

Return Value:

Cookie data var


verifySecureCookie

Verifies the expiry and MAC for the cookie

public verifySecureCookie(string $key): bool

Parameters:

Parameter Type Description
$key string String from the client