class EncryptCookies

Properties

protected array<int, string> $except

The names of the cookies that should not be encrypted.

static protected array<int, string> $neverEncrypt

The globally ignored cookies that should not be encrypted.

static protected array<int, string> $onlyEncrypt

The cookies that should be encrypted (opt-in mode).

static protected bool $serialize

Indicates if cookies should be serialized.

Methods

__construct(Encrypter $encrypter)

Create a new middleware instance.

void
disableFor(array|string $name)

Disable encryption for the given cookie name(s).

Response
handle(Request $request, Closure $next)

Handle an incoming request.

decrypt(Request $request)

Decrypt the cookies on the request.

array|string|null
validateValue(string $key, array|string $value)

Validate and remove the cookie value prefix from the value.

array
validateArray(string $key, array $value)

Validate and remove the cookie value prefix from all values of an array.

array|string
decryptCookie(string $name, array|string $cookie)

Decrypt the given cookie and return the value.

array
decryptArray(array $cookie)

Decrypt an array based cookie.

Response
encrypt(Response $response)

Encrypt the cookies on an outgoing response.

Cookie
duplicate(Cookie $cookie, mixed $value)

Duplicate a cookie with a new value.

bool
isDisabled(string $name)

Determine whether encryption has been disabled for the given cookie.

static void
except(array|string $cookies)

Indicate that the given cookies should never be encrypted.

static void
only(array|string $cookies)

Indicate that only the given cookies should be encrypted.

static bool
serialized(string $name)

Determine if the cookie contents should be serialized.

static void
flushState()

Flush all static state.

Details

at line 50
__construct(Encrypter $encrypter)

Create a new middleware instance.

Parameters

Encrypter $encrypter

at line 61
void disableFor(array|string $name)

Disable encryption for the given cookie name(s).

Boot-only. The list persists for the worker's lifetime and applies to every subsequent request.

Parameters

array|string $name

Return Value

void

at line 69
Response handle(Request $request, Closure $next)

Handle an incoming request.

Parameters

Request $request
Closure $next

Return Value

Response

at line 77
protected Request decrypt(Request $request)

Decrypt the cookies on the request.

Parameters

Request $request

Return Value

Request

at line 101
protected array|string|null validateValue(string $key, array|string $value)

Validate and remove the cookie value prefix from the value.

Parameters

string $key
array|string $value

Return Value

array|string|null

at line 111
protected array validateArray(string $key, array $value)

Validate and remove the cookie value prefix from all values of an array.

Parameters

string $key
array $value

Return Value

array

at line 125
protected array|string decryptCookie(string $name, array|string $cookie)

Decrypt the given cookie and return the value.

Parameters

string $name
array|string $cookie

Return Value

array|string

at line 135
protected array decryptArray(array $cookie)

Decrypt an array based cookie.

Parameters

array $cookie

Return Value

array

at line 155
protected Response encrypt(Response $response)

Encrypt the cookies on an outgoing response.

Parameters

Response $response

Return Value

Response

at line 177
protected Cookie duplicate(Cookie $cookie, mixed $value)

Duplicate a cookie with a new value.

Parameters

Cookie $cookie
mixed $value

Return Value

Cookie

at line 185
bool isDisabled(string $name)

Determine whether encryption has been disabled for the given cookie.

Parameters

string $name

Return Value

bool

at line 200
static void except(array|string $cookies)

Indicate that the given cookies should never be encrypted.

Boot-only. The list persists in a static property for the worker lifetime and applies to every subsequent request.

Parameters

array|string $cookies

Return Value

void

at line 216
static void only(array|string $cookies)

Indicate that only the given cookies should be encrypted.

When set, all other cookies pass through unencrypted. Takes precedence over except() and the $except property.

Boot-only. The list persists in a static property for the worker lifetime and applies to every subsequent request.

Parameters

array|string $cookies

Return Value

void

at line 226
static bool serialized(string $name)

Determine if the cookie contents should be serialized.

Parameters

string $name

Return Value

bool

at line 234
static void flushState()

Flush all static state.

Return Value

void