Download the PHP package wellrested/cookies without Composer
On this page you can find all versions of the php package wellrested/cookies. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wellrested/cookies
More information about wellrested/cookies
Files in wellrested/cookies
Package cookies
Short Description Helper classes for creating cookie headers
License MIT
Homepage https://www.wellrested.org
Informations about the package cookies
WellRESTed Cookies
This package provides CookieFactory
, a class that facilitates creating Set-cookie
headers.
To install, add wellrested/cookies
to your project's composer.json
.
Example
Use a CookieFactory
to create the values for Set-cookie
headers.
Use these with the PSR-7 ResponseInterface->withAddedHeader
to add cookies to a response.
To configure a CookieFactory
to provide Domain
, Path
, Secure
, and HttpOnly
, pass these to the contructor.
Expires and Max-Age
By default, create()
will make session cookies that expire when the user closes the browser. To create a persistant cookie, provide the expiration as the third argument. This argument can several forms:
Numeric values are read as seconds for Max-Age
.
Use a DateTime
instance to set a specific expiration time. Note that CookieFactory
will convert this DateTime
to an HTTP-date
in the format <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT
in accordance with RFC7321.
You may also provide a string which will be used as-is for the expiration. When you provide a string, you are responsible for formatting the date.
Removing Cookies
To remove a cookie, use the remove
method to create a Set-cookie
header that sets the value for the cookie to an empty string and sets the expiration to a date in the past.
Development
To setup a local development enviroment, close this repositoy and run:
To run unit tests, run: