Cookie
extends BaseConfig
in package
Class BaseConfig
Not intended to be used on its own, this class will attempt to automatically populate the child class' properties with values from the environment.
These can be set within the .env file.
Table of Contents
- $domain : string
- -------------------------------------------------------------------------- Cookie Domain --------------------------------------------------------------------------
- $expires : DateTimeInterface|int|string
- -------------------------------------------------------------------------- Cookie Expires Timestamp --------------------------------------------------------------------------
- $httponly : bool
- -------------------------------------------------------------------------- Cookie HTTPOnly --------------------------------------------------------------------------
- $path : string
- -------------------------------------------------------------------------- Cookie Path --------------------------------------------------------------------------
- $prefix : string
- -------------------------------------------------------------------------- Cookie Prefix --------------------------------------------------------------------------
- $raw : bool
- -------------------------------------------------------------------------- Cookie Raw --------------------------------------------------------------------------
- $registrars : array<string|int, mixed>
- An optional array of classes that will act as Registrars for rapidly setting config class properties.
- $samesite : string
- -------------------------------------------------------------------------- Cookie SameSite --------------------------------------------------------------------------
- $secure : bool
- -------------------------------------------------------------------------- Cookie Secure --------------------------------------------------------------------------
- $didDiscovery : bool
- Has module discovery happened yet?
- $moduleConfig : Modules
- The modules configuration.
- __construct() : mixed
- Will attempt to get environment variables with names that match the properties of the child class.
- getEnvValue() : mixed
- Retrieve an environment-specific configuration setting
- initEnvValue() : mixed
- Initialization an environment-specific configuration setting
- registerProperties() : mixed
- Provides external libraries a simple way to register one or more options into a config file.
Properties
$domain
-------------------------------------------------------------------------- Cookie Domain --------------------------------------------------------------------------
public
string
$domain
= ''
Set to .your-domain.com
for site-wide cookies.
$expires
-------------------------------------------------------------------------- Cookie Expires Timestamp --------------------------------------------------------------------------
public
DateTimeInterface|int|string
$expires
= 0
Default expires timestamp for cookies. Setting this to 0
will mean the
cookie will not have the Expires
attribute and will behave as a session
cookie.
$httponly
-------------------------------------------------------------------------- Cookie HTTPOnly --------------------------------------------------------------------------
public
bool
$httponly
= true
Cookie will only be accessible via HTTP(S) (no JavaScript).
$path
-------------------------------------------------------------------------- Cookie Path --------------------------------------------------------------------------
public
string
$path
= '/'
Typically will be a forward slash.
$prefix
-------------------------------------------------------------------------- Cookie Prefix --------------------------------------------------------------------------
public
string
$prefix
= ''
Set a cookie name prefix if you need to avoid collisions.
$raw
-------------------------------------------------------------------------- Cookie Raw --------------------------------------------------------------------------
public
bool
$raw
= false
This flag allows setting a "raw" cookie, i.e., its name and value are
not URL encoded using rawurlencode()
.
If this is set to true
, cookie names should be compliant of RFC 2616's
list of allowed characters.
Tags
$registrars
An optional array of classes that will act as Registrars for rapidly setting config class properties.
public
static array<string|int, mixed>
$registrars
= []
$samesite
-------------------------------------------------------------------------- Cookie SameSite --------------------------------------------------------------------------
public
string
$samesite
= 'Lax'
Configure cookie SameSite setting. Allowed values are:
- None
- Lax
- Strict
- ''
Alternatively, you can use the constant names:
-
Cookie::SAMESITE_NONE
-
Cookie::SAMESITE_LAX
-
Cookie::SAMESITE_STRICT
Defaults to Lax
for compatibility with modern browsers. Setting ''
(empty string) means default SameSite attribute set by browsers (Lax
)
will be set on cookies. If set to None
, $secure
must also be set.
$secure
-------------------------------------------------------------------------- Cookie Secure --------------------------------------------------------------------------
public
bool
$secure
= false
Cookie will only be set if a secure HTTPS connection exists.
$didDiscovery
Has module discovery happened yet?
protected
static bool
$didDiscovery
= false
$moduleConfig
The modules configuration.
protected
static Modules
$moduleConfig
Methods
__construct()
Will attempt to get environment variables with names that match the properties of the child class.
public
__construct() : mixed
The "shortPrefix" is the lowercase-only config class name.
Return values
mixed —getEnvValue()
Retrieve an environment-specific configuration setting
protected
getEnvValue(string $property, string $prefix, string $shortPrefix) : mixed
Parameters
- $property : string
- $prefix : string
- $shortPrefix : string
Return values
mixed —initEnvValue()
Initialization an environment-specific configuration setting
protected
initEnvValue(mixed &$property, string $name, string $prefix, string $shortPrefix) : mixed
Parameters
- $property : mixed
- $name : string
- $prefix : string
- $shortPrefix : string
Return values
mixed —registerProperties()
Provides external libraries a simple way to register one or more options into a config file.
protected
registerProperties() : mixed