WpOrg\Requests
Cookie::__construct()
Create a new cookie object
Method of the class: Cookie{}
No Hooks.
Return
null
. Nothing (null).
Usage
$Cookie = new Cookie(); $Cookie->__construct( $name, $value, $attributes, $flags, $reference_time );
- $name(string) (required)
- The name of the cookie.
- $value(string) (required)
- The value for the cookie.
- $attributes(array|\WpOrg\Requests\Utility\CaseInsensitiveDictionary)
- Associative array of attribute data
Default: [] - $flags(array)
- The flags for the cookie. Valid keys are 'creation', 'last-access', 'persistent' and 'host-only'.
Default: [] - $reference_time(int|null)
- Reference time for relative calculations.
Default: null
Cookie::__construct() Cookie:: construct code WP 6.6.2
public function __construct($name, $value, $attributes = [], $flags = [], $reference_time = null) { if (is_string($name) === false) { throw InvalidArgument::create(1, '$name', 'string', gettype($name)); } if (is_string($value) === false) { throw InvalidArgument::create(2, '$value', 'string', gettype($value)); } if (InputValidator::has_array_access($attributes) === false || InputValidator::is_iterable($attributes) === false) { throw InvalidArgument::create(3, '$attributes', 'array|ArrayAccess&Traversable', gettype($attributes)); } if (is_array($flags) === false) { throw InvalidArgument::create(4, '$flags', 'array', gettype($flags)); } if ($reference_time !== null && is_int($reference_time) === false) { throw InvalidArgument::create(5, '$reference_time', 'integer|null', gettype($reference_time)); } $this->name = $name; $this->value = $value; $this->attributes = $attributes; $default_flags = [ 'creation' => time(), 'last-access' => time(), 'persistent' => false, 'host-only' => true, ]; $this->flags = array_merge($default_flags, $flags); $this->reference_time = time(); if ($reference_time !== null) { $this->reference_time = $reference_time; } $this->normalize(); }