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;
14 use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
17 * Interface for the session.
19 * @author Drak <drak@zikula.org>
21 interface SessionInterface
24 * Starts the session storage.
26 * @return bool True if session started
28 * @throws \RuntimeException If session fails to start.
30 public function start();
33 * Returns the session ID.
35 * @return string The session ID
37 public function getId();
40 * Sets the session ID.
44 public function setId($id);
47 * Returns the session name.
49 * @return mixed The session name
51 public function getName();
54 * Sets the session name.
58 public function setName($name);
61 * Invalidates the current session.
63 * Clears all session attributes and flashes and regenerates the
64 * session and deletes the old session from persistence.
66 * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value
67 * will leave the system settings unchanged, 0 sets the cookie
68 * to expire with browser session. Time is in seconds, and is
69 * not a Unix timestamp.
71 * @return bool True if session invalidated, false if error
73 public function invalidate($lifetime = null);
76 * Migrates the current session to a new session id while maintaining all
79 * @param bool $destroy Whether to delete the old session or leave it to garbage collection
80 * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value
81 * will leave the system settings unchanged, 0 sets the cookie
82 * to expire with browser session. Time is in seconds, and is
83 * not a Unix timestamp.
85 * @return bool True if session migrated, false if error
87 public function migrate($destroy = false, $lifetime = null);
90 * Force the session to be saved and closed.
92 * This method is generally not required for real sessions as
93 * the session will be automatically saved at the end of
96 public function save();
99 * Checks if an attribute is defined.
101 * @param string $name The attribute name
103 * @return bool true if the attribute is defined, false otherwise
105 public function has($name);
108 * Returns an attribute.
110 * @param string $name The attribute name
111 * @param mixed $default The default value if not found
115 public function get($name, $default = null);
120 * @param string $name
121 * @param mixed $value
123 public function set($name, $value);
126 * Returns attributes.
128 * @return array Attributes
130 public function all();
135 * @param array $attributes Attributes
137 public function replace(array $attributes);
140 * Removes an attribute.
142 * @param string $name
144 * @return mixed The removed value or null when it does not exist
146 public function remove($name);
149 * Clears all attributes.
151 public function clear();
154 * Checks if the session was started.
158 public function isStarted();
161 * Registers a SessionBagInterface with the session.
163 * @param SessionBagInterface $bag
165 public function registerBag(SessionBagInterface $bag);
168 * Gets a bag instance by name.
170 * @param string $name
172 * @return SessionBagInterface
174 public function getBag($name);
179 * @return MetadataBag
181 public function getMetadataBag();