lithium\storage\session\adapter\Php::read()
Read a value from the session.
Parameters
-
null|string
$key
Key of the entry to be read. If no key is passed, all current session data is returned.
-
array
$options
Options array. Not used for this adapter method.
Returns
\ClosureFunction returning data in the session if successful, false
otherwise.
Source
public function read($key = null, array $options = []) {
if (!$this->isStarted() && !$this->_start()) {
throw new RuntimeException('Could not start session.');
}
return function($params) {
$key = $params['key'];
if (!$key) {
return $_SESSION;
}
if (strpos($key, '.') === false) {
return isset($_SESSION[$key]) ? $_SESSION[$key] : null;
}
$filter = function($keys, $data) use (&$filter) {
$key = array_shift($keys);
if (isset($data[$key])) {
return (empty($keys)) ? $data[$key] : $filter($keys, $data[$key]);
}
};
return $filter(explode('.', $key), $_SESSION);
};
}