4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpFoundation\Session\Storage;
14 use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
19 * @author Fabien Potencier <fabien@symfony.com>
20 * @author Drak <drak@zikula.org>
22 interface SessionStorageInterface
27 * @return bool True if started
29 * @throws \RuntimeException if something goes wrong starting the session
31 public function start();
34 * Checks if the session is started.
36 * @return bool True if started, false otherwise
38 public function isStarted();
41 * Returns the session ID.
43 * @return string The session ID or empty
45 public function getId();
48 * Sets the session ID.
52 public function setId($id);
55 * Returns the session name.
57 * @return mixed The session name
59 public function getName();
62 * Sets the session name.
66 public function setName($name);
69 * Regenerates id that represents this storage.
71 * This method must invoke session_regenerate_id($destroy) unless
72 * this interface is used for a storage object designed for unit
73 * or functional testing where a real PHP session would interfere
76 * Note regenerate+destroy should not clear the session data in memory
77 * only delete the session data from persistent storage.
79 * Care: When regenerating the session ID no locking is involved in PHP's
80 * session design. See https://bugs.php.net/bug.php?id=61470 for a discussion.
81 * So you must make sure the regenerated session is saved BEFORE sending the
82 * headers with the new ID. Symfony's HttpKernel offers a listener for this.
83 * See Symfony\Component\HttpKernel\EventListener\SaveSessionListener.
84 * Otherwise session data could get lost again for concurrent requests with the
85 * new ID. One result could be that you get logged out after just logging in.
87 * @param bool $destroy Destroy session when regenerating?
88 * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value
89 * will leave the system settings unchanged, 0 sets the cookie
90 * to expire with browser session. Time is in seconds, and is
91 * not a Unix timestamp.
93 * @return bool True if session regenerated, false if error
95 * @throws \RuntimeException If an error occurs while regenerating this storage
97 public function regenerate($destroy = false, $lifetime = null);
100 * Force the session to be saved and closed.
102 * This method must invoke session_write_close() unless this interface is
103 * used for a storage object design for unit or functional testing where
104 * a real PHP session would interfere with testing, in which case
105 * it should actually persist the session data if required.
107 * @throws \RuntimeException if the session is saved without being started, or if the session
110 public function save();
113 * Clear all session data in memory.
115 public function clear();
118 * Gets a SessionBagInterface by name.
120 * @param string $name
122 * @return SessionBagInterface
124 * @throws \InvalidArgumentException If the bag does not exist
126 public function getBag($name);
129 * Registers a SessionBagInterface for use.
131 public function registerBag(SessionBagInterface $bag);
134 * @return MetadataBag
136 public function getMetadataBag();