lithium\storage\session\adapter\Cookie::read()
Read a value from the cookie.
Parameters
-
null|string
$key
Key of the entry to be read. If $key is null, returns all cookie key/value pairs that have been set.
-
array
$options
Options array. Not used in this adapter.
Returns
\ClosureFunction returning data in the session if successful, null
otherwise.
Source
public function read($key = null, array $options = []) {
return function($params) {
$key = $params['key'];
if (!$key) {
if (isset($_COOKIE[$this->_config['name']])) {
return $_COOKIE[$this->_config['name']];
}
return [];
}
if (strpos($key, '.') !== false) {
$key = explode('.', $key);
if (isset($_COOKIE[$this->_config['name']])) {
$result = $_COOKIE[$this->_config['name']];
} else {
$result = [];
}
foreach ($key as $k) {
if (!isset($result[$k])) {
return null;
}
$result = $result[$k];
}
return $result;
}
if (isset($_COOKIE[$this->_config['name']][$key])) {
return $_COOKIE[$this->_config['name']][$key];
}
};
}