fromArray

Learn how to create a storage from an array of cookies.

This static method creates a storage from an array of cookies, reading the client ID and user token from the given name-value pairs.

Use it when you already have the cookies as an array, such as when integrating with a framework that exposes them that way.

Signature

This method has the following signature:

public static function fromArray(array $cookies, ?CookieConfiguration $configuration = null, ?int $now = null): self

This method returns a new instance initialized with the client ID and user token read from the given cookies.

Example

Here is a basic example of how to use this method:

<?phpuse Croct\Plug\CookieStorage;
$storage = CookieStorage::fromArray($_COOKIE);

Parameters

The following list describes the supported parameters:

cookies
array<string,string>

The cookie name-value pairs to read the client ID and user token from.

configuration(optional)

The cookie configuration, such as the cookie names and domain. The default is null, which uses the standard configuration.

Default:null
now(optional)
integer

The current time as a Unix timestamp in seconds, used to compute the cookie expiration. The default is null, which uses the current time.

Default:null