Download the PHP package drewlabs/cookie without Composer
On this page you can find all versions of the php package drewlabs/cookie. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download drewlabs/cookie
More information about drewlabs/cookie
Files in drewlabs/cookie
Package cookie
Short Description OOP implementation for Request & Response Cookies
License MIT
Informations about the package cookie
Cookie Library
The drewlabs/cookie
library provide a cookie an Object Oriented component for building and parsing cookies. The library also provides various immutable methods on the Cookie
instance to update cookie instance once created.
Usage
The library provides developers with a factory class for creating cookie instances. Using cookie factory
class to create cookies follow the syntaxes below:
Using the factory
class developers can create cookie instance from raw cookie string:
Note using the factory class is the recommended way to create cookie instance, but you can use Cookie
class constructor to create cookie
instances. The constructor takes the same parameters as the Factory::create()
method. Consult the documentation reference for more information about supported parameters.
Basic Cookie API
After cookie
instances are created, you can modify their value by creating modified instance of the cookie. To prevent OOP issue related to internal state changes, the cookie
API does not directly modify their internal state... instead, it provide method for creating modified copy of the the source instance. Here is a list of methods for updating cookie
instances values:
-
withValue
-
withDomain
The
withDomain
method allow you update the domain for which cookie was generated. -
withPath
The
withPath
method updates the url path on which cookie might be applied. -
withHttpOnly
withHttpOnly
update the cookie to be only send through http header and not be modified by any frontend code. It tell browsers to enforce cookie rules and protect cookie againt frontend attacks. -
withSecure
withSecure
enforce cookie rules, by forcing browsers to send cookie though a secure connection. __toString()
cookie
insances API also provides a__toString()
method that allows you to convertcookie
object to it string representation that can be used as value toSet-Cookie
header.