diff options
author | Nathan Haug <nate@quicksketch.org> | 2011-10-30 16:32:37 -0700 |
---|---|---|
committer | Nathaniel <catch@35733.no-reply.drupal.org> | 2011-11-01 12:48:40 +0900 |
commit | 06fb770bd340e5a18555e0da55a4dd6ba22f76ba (patch) | |
tree | e814bc08d51db3af473ae5be565219c0249b7870 /includes/Symfony/Component/HttpFoundation/SessionStorage | |
parent | 906a6db34707d27120dddd43a23f26f24153255d (diff) | |
download | drupal-06fb770bd340e5a18555e0da55a4dd6ba22f76ba.tar.gz drupal-06fb770bd340e5a18555e0da55a4dd6ba22f76ba.zip |
Issue #22336 by quicksketch, scor, boombatower, and rfay. Move all core Drupal files under a core subdirectory.
Diffstat (limited to 'includes/Symfony/Component/HttpFoundation/SessionStorage')
5 files changed, 0 insertions, 772 deletions
diff --git a/includes/Symfony/Component/HttpFoundation/SessionStorage/ArraySessionStorage.php b/includes/Symfony/Component/HttpFoundation/SessionStorage/ArraySessionStorage.php deleted file mode 100644 index 62aac40982a..00000000000 --- a/includes/Symfony/Component/HttpFoundation/SessionStorage/ArraySessionStorage.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -/* - * This file is part of the Symfony package. - * - * (c) Fabien Potencier <fabien@symfony.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpFoundation\SessionStorage; - -/** - * ArraySessionStorage mocks the session for unit tests. - * - * When doing functional testing, you should use FilesystemSessionStorage instead. - * - * @author Fabien Potencier <fabien@symfony.com> - * @author Bulat Shakirzyanov <mallluhuct@gmail.com> - */ - -class ArraySessionStorage implements SessionStorageInterface -{ - private $data = array(); - - public function read($key, $default = null) - { - return array_key_exists($key, $this->data) ? $this->data[$key] : $default; - } - - public function regenerate($destroy = false) - { - if ($destroy) { - $this->data = array(); - } - - return true; - } - - public function remove($key) - { - unset($this->data[$key]); - } - - public function start() - { - } - - public function getId() - { - } - - public function write($key, $data) - { - $this->data[$key] = $data; - } -} diff --git a/includes/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php b/includes/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php deleted file mode 100644 index 87abd01bcde..00000000000 --- a/includes/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php +++ /dev/null @@ -1,174 +0,0 @@ -<?php - -/* - * This file is part of the Symfony package. - * - * (c) Fabien Potencier <fabien@symfony.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpFoundation\SessionStorage; - -/** - * FilesystemSessionStorage simulates sessions for functional tests. - * - * This storage does not start the session (session_start()) - * as it is not "available" when running tests on the command line. - * - * @author Fabien Potencier <fabien@symfony.com> - * - * @api - */ -class FilesystemSessionStorage extends NativeSessionStorage -{ - private $path; - private $data; - private $started; - - /** - * Constructor. - */ - public function __construct($path, array $options = array()) - { - $this->path = $path; - $this->started = false; - - parent::__construct($options); - } - - /** - * Starts the session. - * - * @api - */ - public function start() - { - if ($this->started) { - return; - } - - session_set_cookie_params( - $this->options['lifetime'], - $this->options['path'], - $this->options['domain'], - $this->options['secure'], - $this->options['httponly'] - ); - - if (!ini_get('session.use_cookies') && isset($this->options['id']) && $this->options['id'] && $this->options['id'] != session_id()) { - session_id($this->options['id']); - } - - if (!session_id()) { - session_id(hash('md5', uniqid(mt_rand(), true))); - } - - $file = $this->path.'/'.session_id().'.session'; - - $this->data = file_exists($file) ? unserialize(file_get_contents($file)) : array(); - $this->started = true; - } - - /** - * Returns the session ID - * - * @return mixed The session ID - * - * @throws \RuntimeException If the session was not started yet - * - * @api - */ - public function getId() - { - if (!$this->started) { - throw new \RuntimeException('The session must be started before reading its ID'); - } - - return session_id(); - } - - /** - * Reads data from this storage. - * - * The preferred format for a key is directory style so naming conflicts can be avoided. - * - * @param string $key A unique key identifying your data - * - * @return mixed Data associated with the key - * - * @throws \RuntimeException If an error occurs while reading data from this storage - * - * @api - */ - public function read($key, $default = null) - { - return array_key_exists($key, $this->data) ? $this->data[$key] : $default; - } - - /** - * Removes data from this storage. - * - * The preferred format for a key is directory style so naming conflicts can be avoided. - * - * @param string $key A unique key identifying your data - * - * @return mixed Data associated with the key - * - * @throws \RuntimeException If an error occurs while removing data from this storage - * - * @api - */ - public function remove($key) - { - $retval = $this->data[$key]; - - unset($this->data[$key]); - - return $retval; - } - - /** - * Writes data to this storage. - * - * The preferred format for a key is directory style so naming conflicts can be avoided. - * - * @param string $key A unique key identifying your data - * @param mixed $data Data associated with your key - * - * @throws \RuntimeException If an error occurs while writing to this storage - * - * @api - */ - public function write($key, $data) - { - $this->data[$key] = $data; - - if (!is_dir($this->path)) { - mkdir($this->path, 0777, true); - } - - file_put_contents($this->path.'/'.session_id().'.session', serialize($this->data)); - } - - /** - * Regenerates id that represents this storage. - * - * @param Boolean $destroy Destroy session when regenerating? - * - * @return Boolean True if session regenerated, false if error - * - * @throws \RuntimeException If an error occurs while regenerating this storage - * - * @api - */ - public function regenerate($destroy = false) - { - if ($destroy) { - $this->data = array(); - } - - return true; - } -} diff --git a/includes/Symfony/Component/HttpFoundation/SessionStorage/NativeSessionStorage.php b/includes/Symfony/Component/HttpFoundation/SessionStorage/NativeSessionStorage.php deleted file mode 100644 index b759f7411a0..00000000000 --- a/includes/Symfony/Component/HttpFoundation/SessionStorage/NativeSessionStorage.php +++ /dev/null @@ -1,180 +0,0 @@ -<?php - -/* - * This file is part of the Symfony package. - * - * (c) Fabien Potencier <fabien@symfony.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpFoundation\SessionStorage; - -/** - * NativeSessionStorage. - * - * @author Fabien Potencier <fabien@symfony.com> - * - * @api - */ -class NativeSessionStorage implements SessionStorageInterface -{ - static protected $sessionIdRegenerated = false; - static protected $sessionStarted = false; - - protected $options; - - /** - * Available options: - * - * * name: The cookie name (null [omitted] by default) - * * id: The session id (null [omitted] by default) - * * lifetime: Cookie lifetime - * * path: Cookie path - * * domain: Cookie domain - * * secure: Cookie secure - * * httponly: Cookie http only - * - * The default values for most options are those returned by the session_get_cookie_params() function - * - * @param array $options An associative array of session options - */ - public function __construct(array $options = array()) - { - $cookieDefaults = session_get_cookie_params(); - - $this->options = array_merge(array( - 'lifetime' => $cookieDefaults['lifetime'], - 'path' => $cookieDefaults['path'], - 'domain' => $cookieDefaults['domain'], - 'secure' => $cookieDefaults['secure'], - 'httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false, - ), $options); - - // Skip setting new session name if user don't want it - if (isset($this->options['name'])) { - session_name($this->options['name']); - } - } - - /** - * Starts the session. - * - * @api - */ - public function start() - { - if (self::$sessionStarted) { - return; - } - - session_set_cookie_params( - $this->options['lifetime'], - $this->options['path'], - $this->options['domain'], - $this->options['secure'], - $this->options['httponly'] - ); - - // disable native cache limiter as this is managed by HeaderBag directly - session_cache_limiter(false); - - if (!ini_get('session.use_cookies') && isset($this->options['id']) && $this->options['id'] && $this->options['id'] != session_id()) { - session_id($this->options['id']); - } - - session_start(); - - self::$sessionStarted = true; - } - - /** - * {@inheritDoc} - * - * @api - */ - public function getId() - { - if (!self::$sessionStarted) { - throw new \RuntimeException('The session must be started before reading its ID'); - } - - return session_id(); - } - - /** - * Reads data from this storage. - * - * The preferred format for a key is directory style so naming conflicts can be avoided. - * - * @param string $key A unique key identifying your data - * @param string $default Default value - * - * @return mixed Data associated with the key - * - * @api - */ - public function read($key, $default = null) - { - return array_key_exists($key, $_SESSION) ? $_SESSION[$key] : $default; - } - - /** - * Removes data from this storage. - * - * The preferred format for a key is directory style so naming conflicts can be avoided. - * - * @param string $key A unique key identifying your data - * - * @return mixed Data associated with the key - * - * @api - */ - public function remove($key) - { - $retval = null; - - if (isset($_SESSION[$key])) { - $retval = $_SESSION[$key]; - unset($_SESSION[$key]); - } - - return $retval; - } - - /** - * Writes data to this storage. - * - * The preferred format for a key is directory style so naming conflicts can be avoided. - * - * @param string $key A unique key identifying your data - * @param mixed $data Data associated with your key - * - * @api - */ - public function write($key, $data) - { - $_SESSION[$key] = $data; - } - - /** - * Regenerates id that represents this storage. - * - * @param Boolean $destroy Destroy session when regenerating? - * - * @return Boolean True if session regenerated, false if error - * - * @api - */ - public function regenerate($destroy = false) - { - if (self::$sessionIdRegenerated) { - return; - } - - session_regenerate_id($destroy); - - self::$sessionIdRegenerated = true; - } -} diff --git a/includes/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php b/includes/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php deleted file mode 100644 index 78f90b8ec95..00000000000 --- a/includes/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php +++ /dev/null @@ -1,263 +0,0 @@ -<?php - -/* - * This file is part of the Symfony package. - * - * (c) Fabien Potencier <fabien@symfony.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpFoundation\SessionStorage; - -/** - * PdoSessionStorage. - * - * @author Fabien Potencier <fabien@symfony.com> - * @author Michael Williams <michael.williams@funsational.com> - */ -class PdoSessionStorage extends NativeSessionStorage -{ - private $db; - private $dbOptions; - - /** - * Constructor. - * - * @param \PDO $db A PDO instance - * @param array $options An associative array of session options - * @param array $dbOptions An associative array of DB options - * - * @throws \InvalidArgumentException When "db_table" option is not provided - * - * @see NativeSessionStorage::__construct() - */ - public function __construct(\PDO $db, array $options = array(), array $dbOptions = array()) - { - if (!array_key_exists('db_table', $dbOptions)) { - throw new \InvalidArgumentException('You must provide the "db_table" option for a PdoSessionStorage.'); - } - - $this->db = $db; - $this->dbOptions = array_merge(array( - 'db_id_col' => 'sess_id', - 'db_data_col' => 'sess_data', - 'db_time_col' => 'sess_time', - ), $dbOptions); - - parent::__construct($options); - } - - /** - * Starts the session. - */ - public function start() - { - if (self::$sessionStarted) { - return; - } - - // use this object as the session handler - session_set_save_handler( - array($this, 'sessionOpen'), - array($this, 'sessionClose'), - array($this, 'sessionRead'), - array($this, 'sessionWrite'), - array($this, 'sessionDestroy'), - array($this, 'sessionGC') - ); - - parent::start(); - } - - /** - * Opens a session. - * - * @param string $path (ignored) - * @param string $name (ignored) - * - * @return Boolean true, if the session was opened, otherwise an exception is thrown - */ - public function sessionOpen($path = null, $name = null) - { - return true; - } - - /** - * Closes a session. - * - * @return Boolean true, if the session was closed, otherwise false - */ - public function sessionClose() - { - // do nothing - return true; - } - - /** - * Destroys a session. - * - * @param string $id A session ID - * - * @return Boolean true, if the session was destroyed, otherwise an exception is thrown - * - * @throws \RuntimeException If the session cannot be destroyed - */ - public function sessionDestroy($id) - { - // get table/column - $dbTable = $this->dbOptions['db_table']; - $dbIdCol = $this->dbOptions['db_id_col']; - - // delete the record associated with this id - $sql = "DELETE FROM $dbTable WHERE $dbIdCol = :id"; - - try { - $stmt = $this->db->prepare($sql); - $stmt->bindParam(':id', $id, \PDO::PARAM_STR); - $stmt->execute(); - } catch (\PDOException $e) { - throw new \RuntimeException(sprintf('PDOException was thrown when trying to manipulate session data: %s', $e->getMessage()), 0, $e); - } - - return true; - } - - /** - * Cleans up old sessions. - * - * @param int $lifetime The lifetime of a session - * - * @return Boolean true, if old sessions have been cleaned, otherwise an exception is thrown - * - * @throws \RuntimeException If any old sessions cannot be cleaned - */ - public function sessionGC($lifetime) - { - // get table/column - $dbTable = $this->dbOptions['db_table']; - $dbTimeCol = $this->dbOptions['db_time_col']; - - // delete the record associated with this id - $sql = "DELETE FROM $dbTable WHERE $dbTimeCol < (:time - $lifetime)"; - - try { - $this->db->query($sql); - $stmt = $this->db->prepare($sql); - $stmt->bindValue(':time', time(), \PDO::PARAM_INT); - $stmt->execute(); - } catch (\PDOException $e) { - throw new \RuntimeException(sprintf('PDOException was thrown when trying to manipulate session data: %s', $e->getMessage()), 0, $e); - } - - return true; - } - - /** - * Reads a session. - * - * @param string $id A session ID - * - * @return string The session data if the session was read or created, otherwise an exception is thrown - * - * @throws \RuntimeException If the session cannot be read - */ - public function sessionRead($id) - { - // get table/columns - $dbTable = $this->dbOptions['db_table']; - $dbDataCol = $this->dbOptions['db_data_col']; - $dbIdCol = $this->dbOptions['db_id_col']; - - try { - $sql = "SELECT $dbDataCol FROM $dbTable WHERE $dbIdCol = :id"; - - $stmt = $this->db->prepare($sql); - $stmt->bindParam(':id', $id, \PDO::PARAM_STR, 255); - - $stmt->execute(); - // it is recommended to use fetchAll so that PDO can close the DB cursor - // we anyway expect either no rows, or one row with one column. fetchColumn, seems to be buggy #4777 - $sessionRows = $stmt->fetchAll(\PDO::FETCH_NUM); - - if (count($sessionRows) == 1) { - return $sessionRows[0][0]; - } - - // session does not exist, create it - $this->createNewSession($id); - - return ''; - } catch (\PDOException $e) { - throw new \RuntimeException(sprintf('PDOException was thrown when trying to manipulate session data: %s', $e->getMessage()), 0, $e); - } - } - - /** - * Writes session data. - * - * @param string $id A session ID - * @param string $data A serialized chunk of session data - * - * @return Boolean true, if the session was written, otherwise an exception is thrown - * - * @throws \RuntimeException If the session data cannot be written - */ - public function sessionWrite($id, $data) - { - // get table/column - $dbTable = $this->dbOptions['db_table']; - $dbDataCol = $this->dbOptions['db_data_col']; - $dbIdCol = $this->dbOptions['db_id_col']; - $dbTimeCol = $this->dbOptions['db_time_col']; - - $sql = ('mysql' === $this->db->getAttribute(\PDO::ATTR_DRIVER_NAME)) - ? "INSERT INTO $dbTable ($dbIdCol, $dbDataCol, $dbTimeCol) VALUES (:id, :data, :time) " - ."ON DUPLICATE KEY UPDATE $dbDataCol = VALUES($dbDataCol), $dbTimeCol = CASE WHEN $dbTimeCol = :time THEN (VALUES($dbTimeCol) + 1) ELSE VALUES($dbTimeCol) END" - : "UPDATE $dbTable SET $dbDataCol = :data, $dbTimeCol = :time WHERE $dbIdCol = :id"; - - try { - $stmt = $this->db->prepare($sql); - $stmt->bindParam(':id', $id, \PDO::PARAM_STR); - $stmt->bindParam(':data', $data, \PDO::PARAM_STR); - $stmt->bindValue(':time', time(), \PDO::PARAM_INT); - $stmt->execute(); - - if (!$stmt->rowCount()) { - // No session exists in the database to update. This happens when we have called - // session_regenerate_id() - $this->createNewSession($id, $data); - } - } catch (\PDOException $e) { - throw new \RuntimeException(sprintf('PDOException was thrown when trying to manipulate session data: %s', $e->getMessage()), 0, $e); - } - - return true; - } - - /** - * Creates a new session with the given $id and $data - * - * @param string $id - * @param string $data - */ - private function createNewSession($id, $data = '') - { - // get table/column - $dbTable = $this->dbOptions['db_table']; - $dbDataCol = $this->dbOptions['db_data_col']; - $dbIdCol = $this->dbOptions['db_id_col']; - $dbTimeCol = $this->dbOptions['db_time_col']; - - $sql = "INSERT INTO $dbTable ($dbIdCol, $dbDataCol, $dbTimeCol) VALUES (:id, :data, :time)"; - - $stmt = $this->db->prepare($sql); - $stmt->bindParam(':id', $id, \PDO::PARAM_STR); - $stmt->bindParam(':data', $data, \PDO::PARAM_STR); - $stmt->bindValue(':time', time(), \PDO::PARAM_INT); - $stmt->execute(); - - return true; - } -} diff --git a/includes/Symfony/Component/HttpFoundation/SessionStorage/SessionStorageInterface.php b/includes/Symfony/Component/HttpFoundation/SessionStorage/SessionStorageInterface.php deleted file mode 100644 index b61a2557b27..00000000000 --- a/includes/Symfony/Component/HttpFoundation/SessionStorage/SessionStorageInterface.php +++ /dev/null @@ -1,97 +0,0 @@ -<?php - -/* - * This file is part of the Symfony package. - * - * (c) Fabien Potencier <fabien@symfony.com> - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpFoundation\SessionStorage; - -/** - * SessionStorageInterface. - * - * @author Fabien Potencier <fabien@symfony.com> - * - * @api - */ -interface SessionStorageInterface -{ - /** - * Starts the session. - * - * @api - */ - function start(); - - /** - * Returns the session ID - * - * @return mixed The session ID - * - * @throws \RuntimeException If the session was not started yet - * - * @api - */ - function getId(); - - /** - * Reads data from this storage. - * - * The preferred format for a key is directory style so naming conflicts can be avoided. - * - * @param string $key A unique key identifying your data - * - * @return mixed Data associated with the key - * - * @throws \RuntimeException If an error occurs while reading data from this storage - * - * @api - */ - function read($key); - - /** - * Removes data from this storage. - * - * The preferred format for a key is directory style so naming conflicts can be avoided. - * - * @param string $key A unique key identifying your data - * - * @return mixed Data associated with the key - * - * @throws \RuntimeException If an error occurs while removing data from this storage - * - * @api - */ - function remove($key); - - /** - * Writes data to this storage. - * - * The preferred format for a key is directory style so naming conflicts can be avoided. - * - * @param string $key A unique key identifying your data - * @param mixed $data Data associated with your key - * - * @throws \RuntimeException If an error occurs while writing to this storage - * - * @api - */ - function write($key, $data); - - /** - * Regenerates id that represents this storage. - * - * @param Boolean $destroy Destroy session when regenerating? - * - * @return Boolean True if session regenerated, false if error - * - * @throws \RuntimeException If an error occurs while regenerating this storage - * - * @api - */ - function regenerate($destroy = false); -} |