Constructor

Learn how to initialize a cookie storage directly.

The constructor initializes the storage with the given client ID, user token, and cookie settings.

Typically, you create it with one of its factory methods, but you can construct it directly to apply a custom cookie configuration or to seed the session in tests.

Signature

The constructor has the following signature:

public function __construct(    ?Uuid $clientId = null,    ?Token $userToken = null,    ?CookieConfiguration $configuration = null,    ?int $now = null,)

Example

Here is a basic example of how to create a cookie storage with a custom configuration:

<?phpuse Croct\Plug\CookieConfiguration;use Croct\Plug\CookieStorage;
$storage = new CookieStorage(    configuration: new CookieConfiguration(domain: 'example.com'),);

Parameters

The following list describes the supported parameters:

clientId(optional)
Uuid|null

The visitor’s client ID.

userToken(optional)
Token|null

The visitor’s user token.

configuration(optional)

The cookie names, lifetimes, and attributes. The default is null, which uses the standard configuration.

Default:null
now(optional)
int|null

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