Skip to content
Snippets Groups Projects
Commit a0601711 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Reformat SimpleSAML_SessionHandler.

parent 13a2ca61
No related branches found
No related tags found
No related merge requests found
<?php <?php
/** /**
* This file is part of SimpleSAMLphp. See the file COPYING in the * This file is part of SimpleSAMLphp. See the file COPYING in the
* root of the distribution for licence information. * root of the distribution for licence information.
...@@ -9,157 +10,165 @@ ...@@ -9,157 +10,165 @@
* the class method getSessionHandler(). * the class method getSessionHandler().
* *
* @author Olav Morken, UNINETT AS. <andreas.solberg@uninett.no> * @author Olav Morken, UNINETT AS. <andreas.solberg@uninett.no>
* @package simpleSAMLphp * @package SimpleSAMLphp
*/ */
abstract class SimpleSAML_SessionHandler { abstract class SimpleSAML_SessionHandler
{
/**
* This static variable contains a reference to the current /**
* instance of the session handler. This variable will be NULL if * This static variable contains a reference to the current
* we haven't instantiated a session handler yet. * instance of the session handler. This variable will be NULL if
* * we haven't instantiated a session handler yet.
* @var SimpleSAML_SessionHandler *
*/ * @var SimpleSAML_SessionHandler
private static $sessionHandler = NULL; */
private static $sessionHandler = null;
/** /**
* This function retrieves the current instance of the session handler. * This function retrieves the current instance of the session handler.
* The session handler will be instantiated if this is the first call * The session handler will be instantiated if this is the first call
* to this fuunction. * to this function.
* *
* @return SimpleSAML_SessionHandler The current session handler. * @return SimpleSAML_SessionHandler The current session handler.
*/ */
public static function getSessionHandler() { public static function getSessionHandler()
if(self::$sessionHandler === NULL) { {
self::createSessionHandler(); if (self::$sessionHandler === null) {
} self::createSessionHandler();
}
return self::$sessionHandler;
} return self::$sessionHandler;
}
/**
* This constructor is included in case it is needed in the the /**
* future. Including it now allows us to write parent::__construct() in * This constructor is included in case it is needed in the the
* the subclasses of this class. * future. Including it now allows us to write parent::__construct() in
*/ * the subclasses of this class.
protected function __construct() { */
} protected function __construct()
{
}
/**
* Create and set new session id.
* /**
* @return string The new session id. * Create and set new session id.
*/ *
abstract public function newSessionId(); * @return string The new session id.
*/
abstract public function newSessionId();
/**
* Retrieve the session id of saved in the session cookie.
* /**
* @return string The session id saved in the cookie. * Retrieve the session id of saved in the session cookie.
*/ *
abstract public function getCookieSessionId(); * @return string The session id saved in the cookie.
*/
abstract public function getCookieSessionId();
/**
* Retrieve the session cookie name.
* /**
* @return string The session cookie name. * Retrieve the session cookie name.
*/ *
abstract public function getSessionCookieName(); * @return string The session cookie name.
*/
abstract public function getSessionCookieName();
/**
* Save the session.
* /**
* @param SimpleSAML_Session $session The session object we should save. * Save the session.
*/ *
abstract public function saveSession(SimpleSAML_Session $session); * @param SimpleSAML_Session $session The session object we should save.
*/
abstract public function saveSession(SimpleSAML_Session $session);
/**
* Load the session.
* /**
* @param string|NULL $sessionId The ID of the session we should load, or null to use the default. * Load the session.
* @return SimpleSAML_Session|null The session object, or null if it doesn't exist. *
*/ * @param string|NULL $sessionId The ID of the session we should load, or null to use the default.
abstract public function loadSession($sessionId = NULL); *
* @return SimpleSAML_Session|null The session object, or null if it doesn't exist.
*/
/** abstract public function loadSession($sessionId = null);
* Initialize the session handler.
*
* This function creates an instance of the session handler which is /**
* selected in the 'session.handler' configuration directive. If no * Initialize the session handler.
* session handler is selected, then we will fall back to the default *
* PHP session handler. * This function creates an instance of the session handler which is
*/ * selected in the 'session.handler' configuration directive. If no
private static function createSessionHandler() { * session handler is selected, then we will fall back to the default
* PHP session handler.
$store = SimpleSAML_Store::getInstance(); */
if ($store === FALSE) { private static function createSessionHandler()
self::$sessionHandler = new SimpleSAML_SessionHandlerPHP(); {
} else {
self::$sessionHandler = new SimpleSAML_SessionHandlerStore($store); $store = SimpleSAML_Store::getInstance();
} if ($store === false) {
} self::$sessionHandler = new SimpleSAML_SessionHandlerPHP();
} else {
self::$sessionHandler = new SimpleSAML_SessionHandlerStore($store);
/** }
* Check whether the session cookie is set. }
*
* This function will only return false if is is certain that the cookie isn't set.
* /**
* @return bool True if it was set, false if not. * Check whether the session cookie is set.
*/ *
public function hasSessionCookie() { * This function will only return false if is is certain that the cookie isn't set.
*
return TRUE; * @return bool True if it was set, false if not.
} */
public function hasSessionCookie()
{
/**
* Get the cookie parameters that should be used for session cookies. return true;
* }
* @return array An array with the cookie parameters.
* @link http://www.php.net/manual/en/function.session-get-cookie-params.php
*/ /**
public function getCookieParams() { * Get the cookie parameters that should be used for session cookies.
*
$config = SimpleSAML_Configuration::getInstance(); * @return array An array with the cookie parameters.
* @link http://www.php.net/manual/en/function.session-get-cookie-params.php
return array( */
'lifetime' => $config->getInteger('session.cookie.lifetime', 0), public function getCookieParams()
'path' => $config->getString('session.cookie.path', '/'), {
'domain' => $config->getString('session.cookie.domain', NULL),
'secure' => $config->getBoolean('session.cookie.secure', FALSE), $config = SimpleSAML_Configuration::getInstance();
'httponly' => TRUE,
); return array(
} 'lifetime' => $config->getInteger('session.cookie.lifetime', 0),
'path' => $config->getString('session.cookie.path', '/'),
'domain' => $config->getString('session.cookie.domain', null),
/** 'secure' => $config->getBoolean('session.cookie.secure', false),
* Set a session cookie. 'httponly' => true,
* );
* @param string $name The name of the session cookie. }
* @param string|null $value The value of the cookie. Set to null to delete the cookie.
*/
public function setCookie($name, $value, array $params = NULL) { /**
assert('is_string($name)'); * Set a session cookie.
assert('is_string($value) || is_null($value)'); *
* @param string $name The name of the session cookie.
if ($params !== NULL) { * @param string|null $value The value of the cookie. Set to null to delete the cookie.
$params = array_merge($this->getCookieParams(), $params); * @param array|null $params Additional params to use for the session cookie.
} else { */
$params = $this->getCookieParams(); public function setCookie($name, $value, array $params = null)
} {
assert('is_string($name)');
\SimpleSAML\Utils\HTTP::setCookie($name, $value, $params); assert('is_string($value) || is_null($value)');
}
if ($params !== null) {
$params = array_merge($this->getCookieParams(), $params);
} else {
$params = $this->getCookieParams();
}
\SimpleSAML\Utils\HTTP::setCookie($name, $value, $params);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment