fromServerRequest
Learn how to create a storage from a PSR-7 server request.
This static method creates a storage from a PSR-7 server request, reading the cookies from the request.
Use it when integrating with a framework that exposes the incoming request as a PSR-7 object.
Signature
This method has the following signature:
public static function fromServerRequest(ServerRequest $request, ?CookieConfiguration $configuration = null, ?int $now = null): selfThis method returns a new instance initialized with the client ID and user token read from the request’s cookies.
Example
Here is a basic example of how to use this method:
<?phpuse Croct\Plug\CookieStorage;
$storage = CookieStorage::fromServerRequest($request);Parameters
The following list describes the supported parameters:
- requestServerRequest
The PSR-7 server request to read the cookies 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