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

closure Function returning data in the session if successful, `false` otherwise.

Source

						public static function read($key = null, array $options = array()) {
		if (!static::isStarted() && !static::_start()) {
			throw new RuntimeException("Could not start session.");
		}
		return function($self, $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);
		};
	}