lithium\storage\session\adapter\Cookie::write()
Write a value to the cookie store.
Parameters
-
string
$key
Key of the item to be stored.
-
mixed
$value
The value to be stored.
-
array
$options
Options array.
Returns
\ClosureFunction returning boolean true
on successful write, false
otherwise.
Source
public function write($key, $value = null, array $options = array()) {
$expire = (!isset($options['expire']) && empty($this->_config['expire']));
$config = $this->_config;
$cookieClass = __CLASS__;
if ($expire && $key !== $config['name']) {
return null;
}
$expires = (isset($options['expire'])) ? $options['expire'] : $config['expire'];
return function($self, $params) use (&$config, &$expires, $cookieClass) {
$key = $params['key'];
$value = $params['value'];
$key = array($key => $value);
if (is_array($value)) {
$key = Set::flatten($key);
}
foreach ($key as $name => $val) {
$name = $cookieClass::keyFormat($name, $config);
$result = setcookie($name, $val, strtotime($expires), $config['path'],
$config['domain'], $config['secure'], $config['httponly']
);
if (!$result) {
throw new RuntimeException("There was an error setting {$name} cookie.");
}
}
return true;
};
}