From 468391525a31731af90f2a4ccadba425e3dbdabd Mon Sep 17 00:00:00 2001 From: Drak Date: Wed, 8 Feb 2012 15:31:38 +0545 Subject: [PATCH] [HttpFoundation] Free bags from session storage and move classes to their own namespaces. --- CHANGELOG-2.1.md | 2 +- UPGRADE-2.1.md | 8 +- .../HttpFoundation/DbalSessionStorage.php | 8 +- .../Resources/config/session.xml | 22 +--- .../Templating/Helper/SessionHelper.php | 2 +- .../Templating/Helper/SessionHelperTest.php | 4 +- .../EventListener/WebDebugToolbarListener.php | 2 +- .../HttpFoundation/AttributeBagInterface.php | 24 ---- .../Component/HttpFoundation/Session.php | 40 +++++-- .../{ => SessionAttribute}/AttributeBag.php | 20 +++- .../AttributeBagInterface.php} | 13 +-- .../NamespacedAttributeBag.php | 5 +- .../HttpFoundation/SessionBagInterface.php | 14 +++ .../{ => SessionFlash}/AutoExpireFlashBag.php | 28 ++++- .../{ => SessionFlash}/FlashBag.php | 25 +++- .../{ => SessionFlash}/FlashBagInterface.php | 4 +- .../HttpFoundation/SessionInterface.php | 57 ++++++++- .../SessionStorage/AbstractSessionStorage.php | 110 +++++++++--------- .../SessionStorage/MemcacheSessionStorage.php | 9 +- .../MemcachedSessionStorage.php | 9 +- .../MockArraySessionStorage.php | 51 ++++---- .../SessionStorage/MockFileSessionStorage.php | 18 +-- .../NativeFileSessionStorage.php | 9 +- .../NativeMemcacheSessionStorage.php | 9 +- .../NativeMemcachedSessionStorage.php | 9 +- .../NativeSqliteSessionStorage.php | 9 +- .../SessionStorage/NullSessionStorage.php | 3 - .../SessionStorage/PdoSessionStorage.php | 9 +- .../SessionSaveHandlerInterface.php | 8 +- .../SessionStorageInterface.php | 15 +-- .../Component/HttpFoundation/RequestTest.php | 6 +- .../AttributeBagTest.php | 2 +- .../NamespacedAttributeBagTest.php | 2 +- .../AutoExpireFlashBagTest.php | 6 +- .../{ => SessionFlash}/FlashBagTest.php | 6 +- .../AbstractSessionStorageTest.php | 28 +++-- .../MockArraySessionStorageTest.php | 32 +++-- .../MockFileSessionStorageTest.php | 32 ++--- .../NativeFileSessionStorageTest.php | 18 +-- .../NativeMemcacheSessionStorageTest.php | 22 +--- .../NativeMemcachedSessionStorageTest.php | 26 +---- .../NativeSqliteSessionStorageTest.php | 22 +--- .../SessionStorage/NullSessionStorageTest.php | 8 -- .../Component/HttpFoundation/SessionTest.php | 12 +- 44 files changed, 385 insertions(+), 383 deletions(-) delete mode 100644 src/Symfony/Component/HttpFoundation/AttributeBagInterface.php rename src/Symfony/Component/HttpFoundation/{ => SessionAttribute}/AttributeBag.php (86%) rename src/Symfony/Component/HttpFoundation/{SessionStorage/AttributeInterface.php => SessionAttribute/AttributeBagInterface.php} (85%) rename src/Symfony/Component/HttpFoundation/{ => SessionAttribute}/NamespacedAttributeBag.php (97%) rename src/Symfony/Component/HttpFoundation/{ => SessionFlash}/AutoExpireFlashBag.php (87%) rename src/Symfony/Component/HttpFoundation/{ => SessionFlash}/FlashBag.php (86%) rename src/Symfony/Component/HttpFoundation/{ => SessionFlash}/FlashBagInterface.php (92%) rename tests/Symfony/Tests/Component/HttpFoundation/{ => SessionAttribute}/AttributeBagTest.php (98%) rename tests/Symfony/Tests/Component/HttpFoundation/{ => SessionAttribute}/NamespacedAttributeBagTest.php (98%) rename tests/Symfony/Tests/Component/HttpFoundation/{ => SessionFlash}/AutoExpireFlashBagTest.php (93%) rename tests/Symfony/Tests/Component/HttpFoundation/{ => SessionFlash}/FlashBagTest.php (94%) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 2a1d994881..6ae768c51f 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -232,7 +232,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c * Flashes are now stored as a bucket of messages per `$type` so there can be multiple messages per type. There are four interface constants for type, `FlashBagInterface::INFO`, `FlashBagInterface::NOTICE`, `FlashBagInterface::WARNING` and `FlashBagInterface::ERROR`. - * Added `FlashBag` (default). Flashes expire when retrieved by `popFlashes()`. + * Added `FlashBag` (default). Flashes expire when retrieved by `pop()` or `popAll()`. This makes the implementation ESI compatible. * Added `AutoExpireFlashBag` to replicate Symfony 2.0.x auto expire behaviour of messages auto expiring after one page page load. Messages must be retrived by `pop()` or `popAll()`. diff --git a/UPGRADE-2.1.md b/UPGRADE-2.1.md index fdfa5c2b96..fea123a526 100644 --- a/UPGRADE-2.1.md +++ b/UPGRADE-2.1.md @@ -259,7 +259,7 @@ UPGRADE FROM 2.0 to 2.1 - If You wanted to process all flash types you could also make use of the `popAllFlashes()` API: + If you wanted to process all flash types you could also make use of the `getFlashes()->all()` API: getFlashes()->all() as $type => $flash): ?>
@@ -270,8 +270,8 @@ UPGRADE FROM 2.0 to 2.1 .. note:: The Flash Message API provides constants which you can optionally use. For example - `Symfony\Component\HttpFoundation\FlashBag::NOTICE`, which can also be abbreviated to - `FlashBag::NOTICE` providing you declare `` + `Symfony\Component\HttpFoundation\SessionFlash\FlashBag::NOTICE`, which can also be abbreviated to + `FlashBag::NOTICE` providing you declare `` at the beginning of the PHP template. Before (Twig): @@ -301,7 +301,7 @@ UPGRADE FROM 2.0 to 2.1 .. note:: You can optionally use constants in Twig templates using `constant()` e.g. - `constant('Symfony\Component\HttpFoundation\FlashBag::NOTICE')`. + `constant('Symfony\Component\HttpFoundation\SessionFlash\FlashBag::NOTICE')`. * Session object diff --git a/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionStorage.php b/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionStorage.php index 3b1e7ef516..8552a09f30 100644 --- a/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionStorage.php +++ b/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionStorage.php @@ -3,8 +3,6 @@ namespace Symfony\Bridge\Doctrine\HttpFoundation; use Doctrine\DBAL\Platforms\MySqlPlatform; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; use Symfony\Component\HttpFoundation\SessionStorage\AbstractSessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\SessionSaveHandlerInterface; use Doctrine\DBAL\Driver\Connection; @@ -32,15 +30,13 @@ class DbalSessionStorage extends AbstractSessionStorage implements SessionSaveHa * @param Connection $con An instance of Connection. * @param string $tableName Table name. * @param array $options Session configuration options - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) */ - public function __construct(Connection $con, $tableName = 'sessions', array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) + public function __construct(Connection $con, $tableName = 'sessions', array $options = array()) { $this->con = $con; $this->tableName = $tableName; - parent::__construct($attributes, $flashes, $options); + parent::__construct($options); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml index a1a746b781..dd1a2b6d3b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml @@ -6,8 +6,8 @@ Symfony\Component\HttpFoundation\Session - Symfony\Component\HttpFoundation\FlashBag - Symfony\Component\HttpFoundation\AttributeBag + Symfony\Component\HttpFoundation\SessionFlash\FlashBag + Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag Symfony\Component\HttpFoundation\SessionStorage\NativeFileSessionStorage Symfony\Component\HttpFoundation\SessionStorage\NullSessionStorage Symfony\Component\HttpFoundation\SessionStorage\NativeMemcacheSessionStorage @@ -25,6 +25,8 @@ + + @@ -35,58 +37,42 @@ %kernel.cache_dir%/sessions %session.storage.options% - - %kernel.cache_dir%/sessions %session.storage.options% - - tcp://127.0.0.1:11211?persistent=0 %session.storage.options% - - 127.0.0.1:11211 %session.storage.options% - - tcp://127.0.0.1:11211?persistent=0 %session.storage.options% - - tcp://127.0.0.1:11211?persistent=0 %session.storage.options% - - %kernel.cache_dir%/sf2_sqlite_sess.db %session.storage.options% - - %session.storage.options% - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php index c861e23e01..983c3cfece 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php @@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Templating\Helper; use Symfony\Component\Templating\Helper\Helper; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\FlashBagInterface; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface; /** * SessionHelper provides read-only access to the session attributes. diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php index b18526f836..bd7c3a962b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php @@ -15,8 +15,8 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session; use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage; use Symfony\Bundle\FrameworkBundle\Templating\Helper\SessionHelper; -use Symfony\Component\HttpFoundation\FlashBag; -use Symfony\Component\HttpFoundation\AttributeBag; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag; class SessionHelperTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php index 9d6c6e766b..d12cee0cb3 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php @@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Bundle\TwigBundle\TwigEngine; -use Symfony\Component\HttpFoundation\AutoExpireFlashBag; +use Symfony\Component\HttpFoundation\SessionFlash\AutoExpireFlashBag; /** * WebDebugToolbarListener injects the Web Debug Toolbar. diff --git a/src/Symfony/Component/HttpFoundation/AttributeBagInterface.php b/src/Symfony/Component/HttpFoundation/AttributeBagInterface.php deleted file mode 100644 index e835533a37..0000000000 --- a/src/Symfony/Component/HttpFoundation/AttributeBagInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpFoundation; - -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\SessionStorage\AttributeInterface; - -/** - * Attributes store. - * - * @author Drak - */ -interface AttributeBagInterface extends SessionBagInterface, AttributeInterface -{ -} diff --git a/src/Symfony/Component/HttpFoundation/Session.php b/src/Symfony/Component/HttpFoundation/Session.php index b6d2f142c9..6d40b880a7 100644 --- a/src/Symfony/Component/HttpFoundation/Session.php +++ b/src/Symfony/Component/HttpFoundation/Session.php @@ -12,7 +12,11 @@ namespace Symfony\Component\HttpFoundation; use Symfony\Component\HttpFoundation\SessionStorage\SessionStorageInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBagInterface; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface; +use Symfony\Component\HttpFoundation\SessionBagInterface; /** * Session. @@ -35,10 +39,14 @@ class Session implements SessionInterface * Constructor. * * @param SessionStorageInterface $storage A SessionStorageInterface instance. + * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) + * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) */ - public function __construct(SessionStorageInterface $storage) + public function __construct(SessionStorageInterface $storage, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) { $this->storage = $storage; + $this->registerBag($attributes ?: new AttributeBag()); + $this->registerBag($flashes ?: new FlashBag()); } /** @@ -64,7 +72,7 @@ class Session implements SessionInterface */ public function has($name) { - return $this->storage->getAttributes()->has($name); + return $this->storage->getBag('attributes')->has($name); } /** @@ -79,7 +87,7 @@ class Session implements SessionInterface */ public function get($name, $default = null) { - return $this->storage->getAttributes()->get($name, $default); + return $this->storage->getBag('attributes')->get($name, $default); } /** @@ -92,7 +100,7 @@ class Session implements SessionInterface */ public function set($name, $value) { - $this->storage->getAttributes()->set($name, $value); + $this->storage->getBag('attributes')->set($name, $value); } /** @@ -104,7 +112,7 @@ class Session implements SessionInterface */ public function all() { - return $this->storage->getAttributes()->all(); + return $this->storage->getBag('attributes')->all(); } /** @@ -116,7 +124,7 @@ class Session implements SessionInterface */ public function replace(array $attributes) { - $this->storage->getAttributes()->replace($attributes); + $this->storage->getBag('attributes')->replace($attributes); } /** @@ -128,7 +136,7 @@ class Session implements SessionInterface */ public function remove($name) { - return $this->storage->getAttributes()->remove($name); + return $this->storage->getBag('attributes')->remove($name); } /** @@ -138,7 +146,7 @@ class Session implements SessionInterface */ public function clear() { - $this->storage->getAttributes()->clear(); + $this->storage->getBag('attributes')->clear(); } /** @@ -218,13 +226,23 @@ class Session implements SessionInterface $this->storage = $storage; } + public function registerBag(SessionBagInterface $bag) + { + $this->storage->registerBag($bag); + } + + public function getBag($name) + { + return $this->storage->getBag($name); + } + /** - * Gets all flash messages. + * Gets the flashbag interface. * * @return FlashBagInterface */ public function getFlashes() { - return $this->storage->getFlashes(); + return $this->getBag('flashes'); } } diff --git a/src/Symfony/Component/HttpFoundation/AttributeBag.php b/src/Symfony/Component/HttpFoundation/SessionAttribute/AttributeBag.php similarity index 86% rename from src/Symfony/Component/HttpFoundation/AttributeBag.php rename to src/Symfony/Component/HttpFoundation/SessionAttribute/AttributeBag.php index 3db1650426..301f2e6628 100644 --- a/src/Symfony/Component/HttpFoundation/AttributeBag.php +++ b/src/Symfony/Component/HttpFoundation/SessionAttribute/AttributeBag.php @@ -9,13 +9,15 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpFoundation; +namespace Symfony\Component\HttpFoundation\SessionAttribute; /** * This class relates to session attribute storage */ class AttributeBag implements AttributeBagInterface { + private $name = 'attributes'; + /** * @var string */ @@ -36,6 +38,19 @@ class AttributeBag implements AttributeBagInterface $this->storageKey = $storageKey; } + /** + * {@inheritdoc} + */ + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + /** * {@inheritdoc} */ @@ -114,6 +129,9 @@ class AttributeBag implements AttributeBagInterface */ public function clear() { + $return = $this->attributes; $this->attributes = array(); + + return $return; } } diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/AttributeInterface.php b/src/Symfony/Component/HttpFoundation/SessionAttribute/AttributeBagInterface.php similarity index 85% rename from src/Symfony/Component/HttpFoundation/SessionStorage/AttributeInterface.php rename to src/Symfony/Component/HttpFoundation/SessionAttribute/AttributeBagInterface.php index 176cb8bc8b..e24603ac7e 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/AttributeInterface.php +++ b/src/Symfony/Component/HttpFoundation/SessionAttribute/AttributeBagInterface.php @@ -9,14 +9,16 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpFoundation\SessionStorage; +namespace Symfony\Component\HttpFoundation\SessionAttribute; + +use Symfony\Component\HttpFoundation\SessionBagInterface; /** - * Interface for the session. + * Attributes store. * * @author Drak */ -interface AttributeInterface +interface AttributeBagInterface extends SessionBagInterface { /** * Checks if an attribute is defined. @@ -65,9 +67,4 @@ interface AttributeInterface * @param string $name */ function remove($name); - - /** - * Clears all attributes. - */ - function clear(); } diff --git a/src/Symfony/Component/HttpFoundation/NamespacedAttributeBag.php b/src/Symfony/Component/HttpFoundation/SessionAttribute/NamespacedAttributeBag.php similarity index 97% rename from src/Symfony/Component/HttpFoundation/NamespacedAttributeBag.php rename to src/Symfony/Component/HttpFoundation/SessionAttribute/NamespacedAttributeBag.php index b175b5f233..74e432fe47 100644 --- a/src/Symfony/Component/HttpFoundation/NamespacedAttributeBag.php +++ b/src/Symfony/Component/HttpFoundation/SessionAttribute/NamespacedAttributeBag.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpFoundation; +namespace Symfony\Component\HttpFoundation\SessionAttribute; /** * This class provides structured storage of session attributes using @@ -110,7 +110,10 @@ class NamespacedAttributeBag extends AttributeBag */ public function clear() { + $return = $this->attributes; $this->attributes = array(); + + return $return; } /** diff --git a/src/Symfony/Component/HttpFoundation/SessionBagInterface.php b/src/Symfony/Component/HttpFoundation/SessionBagInterface.php index 2fd53621dc..a26596369b 100644 --- a/src/Symfony/Component/HttpFoundation/SessionBagInterface.php +++ b/src/Symfony/Component/HttpFoundation/SessionBagInterface.php @@ -18,6 +18,13 @@ namespace Symfony\Component\HttpFoundation; */ interface SessionBagInterface { + /** + * Gets this bag's name + * + * @return string + */ + function getName(); + /** * Initializes the Bag * @@ -31,4 +38,11 @@ interface SessionBagInterface * @return string */ function getStorageKey(); + + /** + * Clears out data from bag. + * + * @return mixed Whatever data was contained. + */ + function clear(); } diff --git a/src/Symfony/Component/HttpFoundation/AutoExpireFlashBag.php b/src/Symfony/Component/HttpFoundation/SessionFlash/AutoExpireFlashBag.php similarity index 87% rename from src/Symfony/Component/HttpFoundation/AutoExpireFlashBag.php rename to src/Symfony/Component/HttpFoundation/SessionFlash/AutoExpireFlashBag.php index 2767e4817a..906ac302ae 100644 --- a/src/Symfony/Component/HttpFoundation/AutoExpireFlashBag.php +++ b/src/Symfony/Component/HttpFoundation/SessionFlash/AutoExpireFlashBag.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpFoundation; +namespace Symfony\Component\HttpFoundation\SessionFlash; /** * AutoExpireFlashBag flash message container. @@ -18,6 +18,8 @@ namespace Symfony\Component\HttpFoundation; */ class AutoExpireFlashBag implements FlashBagInterface { + private $name = 'flashes'; + /** * Flash messages. * @@ -43,6 +45,19 @@ class AutoExpireFlashBag implements FlashBagInterface $this->flashes = array('display' => array(), 'new' => array()); } + /** + * {@inheritdoc} + */ + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + /** * {@inheritdoc} */ @@ -149,4 +164,15 @@ class AutoExpireFlashBag implements FlashBagInterface { return $this->storageKey; } + + /** + * {@inheritdoc} + */ + public function clear() + { + $return = $this->popAll(); + $this->flashes = array('display' => array(), 'new' => array()); + + return $return; + } } diff --git a/src/Symfony/Component/HttpFoundation/FlashBag.php b/src/Symfony/Component/HttpFoundation/SessionFlash/FlashBag.php similarity index 86% rename from src/Symfony/Component/HttpFoundation/FlashBag.php rename to src/Symfony/Component/HttpFoundation/SessionFlash/FlashBag.php index 31ccce4447..9dcb731a02 100644 --- a/src/Symfony/Component/HttpFoundation/FlashBag.php +++ b/src/Symfony/Component/HttpFoundation/SessionFlash/FlashBag.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpFoundation; +namespace Symfony\Component\HttpFoundation\SessionFlash; /** * FlashBag flash message container. @@ -18,6 +18,8 @@ namespace Symfony\Component\HttpFoundation; */ class FlashBag implements FlashBagInterface { + private $name = 'flashes'; + /** * Flash messages. * @@ -42,6 +44,19 @@ class FlashBag implements FlashBagInterface $this->storageKey = $storageKey; } + /** + * {@inheritdoc} + */ + public function getName() + { + return $this->name; + } + + public function setName($name) + { + $this->name = $name; + } + /** * {@inheritdoc} */ @@ -135,4 +150,12 @@ class FlashBag implements FlashBagInterface { return $this->storageKey; } + + /** + * {@inheritdoc} + */ + public function clear() + { + return $this->popAll(); + } } diff --git a/src/Symfony/Component/HttpFoundation/FlashBagInterface.php b/src/Symfony/Component/HttpFoundation/SessionFlash/FlashBagInterface.php similarity index 92% rename from src/Symfony/Component/HttpFoundation/FlashBagInterface.php rename to src/Symfony/Component/HttpFoundation/SessionFlash/FlashBagInterface.php index c8dd96f14f..41e8dde577 100644 --- a/src/Symfony/Component/HttpFoundation/FlashBagInterface.php +++ b/src/Symfony/Component/HttpFoundation/SessionFlash/FlashBagInterface.php @@ -9,7 +9,9 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\HttpFoundation; +namespace Symfony\Component\HttpFoundation\SessionFlash; + +use Symfony\Component\HttpFoundation\SessionBagInterface; /** * FlashBagInterface. diff --git a/src/Symfony/Component/HttpFoundation/SessionInterface.php b/src/Symfony/Component/HttpFoundation/SessionInterface.php index 9cbadbe2c0..dc15518341 100644 --- a/src/Symfony/Component/HttpFoundation/SessionInterface.php +++ b/src/Symfony/Component/HttpFoundation/SessionInterface.php @@ -12,14 +12,14 @@ namespace Symfony\Component\HttpFoundation; use Symfony\Component\HttpFoundation\SessionStorage\AttributeInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface; /** * Interface for the session. * * @author Drak */ -interface SessionInterface extends AttributeInterface, \Serializable +interface SessionInterface extends \Serializable { /** * Starts the session storage. @@ -56,6 +56,59 @@ interface SessionInterface extends AttributeInterface, \Serializable */ function save(); + /** + * Checks if an attribute is defined. + * + * @param string $name The attribute name + * + * @return Boolean true if the attribute is defined, false otherwise + */ + function has($name); + + /** + * Returns an attribute. + * + * @param string $name The attribute name + * @param mixed $default The default value if not found. + * + * @return mixed + */ + function get($name, $default = null); + + /** + * Sets an attribute. + * + * @param string $name + * @param mixed $value + */ + function set($name, $value); + + /** + * Returns attributes. + * + * @return array Attributes + */ + function all(); + + /** + * Sets attributes. + * + * @param array $attributes Attributes + */ + function replace(array $attributes); + + /** + * Removes an attribute. + * + * @param string $name + */ + function remove($name); + + /** + * Clears all attributes. + */ + function clear(); + /** * Gets the flashbag interface. * diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/AbstractSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/AbstractSessionStorage.php index 7301f42110..8382d3a3ff 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/AbstractSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/AbstractSessionStorage.php @@ -11,10 +11,10 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\FlashBag; -use Symfony\Component\HttpFoundation\FlashBagInterface; -use Symfony\Component\HttpFoundation\AttributeBag; -use Symfony\Component\HttpFoundation\AttributeBagInterface; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBagInterface; use Symfony\Component\HttpFoundation\SessionBagInterface; /** @@ -25,14 +25,11 @@ use Symfony\Component\HttpFoundation\SessionBagInterface; abstract class AbstractSessionStorage implements SessionStorageInterface { /** - * @var \Symfony\Component\HttpFoundation\FlashBagInterface + * Array of SessionBagInterface + * + * @var array */ - protected $flashBag; - - /** - * @var \Symfony\Component\HttpFoundation\AttributeBagInterface - */ - protected $attributeBag; + protected $bags; /** * @var array @@ -87,43 +84,15 @@ abstract class AbstractSessionStorage implements SessionStorageInterface * upload_progress.min-freq, "1" * url_rewriter.tags, "a=href,area=href,frame=src,form=,fieldset=" * - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) * @param array $options Session configuration options. */ - public function __construct(AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null, array $options = array()) + public function __construct(array $options = array()) { - $this->attributeBag = $attributes ?: new AttributeBag(); - $this->flashBag = $flashes ?: new FlashBag(); $this->setOptions($options); $this->registerSaveHandlers(); $this->registerShutdownFunction(); } - /** - * {@inheritdoc} - */ - public function getFlashes() - { - if ($this->options['auto_start'] && !$this->started) { - $this->start(); - } - - return $this->flashBag; - } - - /** - * {@inheritdoc} - */ - public function getAttributes() - { - if ($this->options['auto_start'] && !$this->started) { - $this->start(); - } - - return $this->attributeBag; - } - /** * {@inheritdoc} */ @@ -194,8 +163,9 @@ abstract class AbstractSessionStorage implements SessionStorageInterface public function clear() { // clear out the bags - $this->attributeBag->clear(); - $this->flashBag->popAll(); + foreach ($this->bags as $bag) { + $bag->clear(); + } // clear out the session $_SESSION = array(); @@ -204,6 +174,38 @@ abstract class AbstractSessionStorage implements SessionStorageInterface $this->loadSession(); } + /** + * Register a SessionBagInterface for use. + * + * @param SessionBagInterface $bag + */ + public function registerBag(SessionBagInterface $bag) + { + $this->bags[$bag->getName()] = $bag; + } + + /** + * Gets a bag by name. + * + * @param string $name + * + * @return SessionBagInterface + * + * @throws \InvalidArgumentException + */ + public function getBag($name) + { + if (!isset($this->bags[$name])) { + throw new \InvalidArgumentException(sprintf('The SessionBagInterface %s is not registered.', $name)); + } + + if ($this->options['auto_start'] && !$this->started) { + $this->start(); + } + + return $this->bags[$name]; + } + /** * Sets session.* ini variables. * @@ -326,22 +328,16 @@ abstract class AbstractSessionStorage implements SessionStorageInterface * PHP takes the return value from the sessionRead() handler, unserializes it * and populates $_SESSION with the result automatically. */ - protected function loadSession() + protected function loadSession(array &$session = null) { - $this->link($this->attributeBag, $_SESSION); - $this->link($this->flashBag, $_SESSION); - } + if (null === $session) { + $session = &$_SESSION; + } - /** - * Link a bag to the session. - * - * @param SessionBagInterface $bag - * @param array &$array - */ - protected function link(SessionBagInterface $bag, array &$array) - { - $key = $bag->getStorageKey(); - $array[$key] = isset($array[$key]) ? $array[$key] : array(); - $bag->initialize($array[$key]); + foreach ($this->bags as $bag) { + $key = $bag->getStorageKey(); + $session[$key] = isset($session[$key]) ? $session[$key] : array(); + $bag->initialize($session[$key]); + } } } diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/MemcacheSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/MemcacheSessionStorage.php index 91424a68cf..6836247ad3 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/MemcacheSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/MemcacheSessionStorage.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; - /** * MemcacheSessionStorage. * @@ -48,12 +45,10 @@ class MemcacheSessionStorage extends AbstractSessionStorage implements SessionSa * @param \Memcache $memcache A \Memcache instance * @param array $memcacheOptions An associative array of Memcachge options * @param array $options Session configuration options. - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) * * @see AbstractSessionStorage::__construct() */ - public function __construct(\Memcache $memcache, array $memcacheOptions = array(), array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) + public function __construct(\Memcache $memcache, array $memcacheOptions = array(), array $options = array()) { $this->memcache = $memcache; @@ -72,7 +67,7 @@ class MemcacheSessionStorage extends AbstractSessionStorage implements SessionSa $this->memcacheOptions = $memcacheOptions; - parent::__construct($attributes, $flashes, $options); + parent::__construct($options); } protected function addServer(array $server) diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/MemcachedSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/MemcachedSessionStorage.php index 4d72f062f1..7a9c6ecb9a 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/MemcachedSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/MemcachedSessionStorage.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; - /** * MemcachedSessionStorage. * @@ -41,12 +38,10 @@ class MemcachedSessionStorage extends AbstractSessionStorage implements SessionS * @param \Memcached $memcached A \Memcached instance * @param array $memcachedOptions An associative array of Memcached options * @param array $options Session configuration options. - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) * * @see AbstractSessionStorage::__construct() */ - public function __construct(\Memcached $memcache, array $memcachedOptions = array(), array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) + public function __construct(\Memcached $memcache, array $memcachedOptions = array(), array $options = array()) { $this->memcached = $memcached; @@ -66,7 +61,7 @@ class MemcachedSessionStorage extends AbstractSessionStorage implements SessionS $this->memcacheOptions = $memcachedOptions; - parent::__construct($attributes, $flashes, $options); + parent::__construct($options); } /** diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/MockArraySessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/MockArraySessionStorage.php index 45734dec31..96206f5847 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/MockArraySessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/MockArraySessionStorage.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; - /** * MockArraySessionStorage mocks the session for unit tests. * @@ -36,31 +33,11 @@ class MockArraySessionStorage extends AbstractSessionStorage /** * @var array */ - private $attributes = array(); + private $sessionData = array(); - /** - * @var array - */ - private $flashes = array(); - - /** - * Injects array of attributes to simulate retrieval of existing session. - * - * @param array $array - */ - public function setAttributes(array $array) + public function setSessionData(array $array) { - $this->attributes = $array; - } - - /** - * Injects array of flashes to simulate retrieval of existing session. - * - * @param array $array - */ - public function setFlashes(array $array) - { - $this->flashes = $array; + $this->sessionData = $array; } /** @@ -73,14 +50,15 @@ class MockArraySessionStorage extends AbstractSessionStorage } $this->started = true; - $this->attributeBag->initialize($this->attributes); - $this->flashBag->initialize($this->flashes); + $this->loadSession($this->sessionData); + $this->sessionId = $this->generateSessionId(); session_id($this->sessionId); return true; } + /** * {@inheritdoc} */ @@ -117,6 +95,23 @@ class MockArraySessionStorage extends AbstractSessionStorage $this->closed = false; } + /** + * {@inheritdoc} + */ + public function clear() + { + // clear out the bags + foreach ($this->bags as $bag) { + $bag->clear(); + } + + // clear out the session + $this->sessionData = array(); + + // reconnect the bags to the session + $this->loadSession($this->sessionData); + } + /** * Generates a session ID. * diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/MockFileSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/MockFileSessionStorage.php index 7bc7b141d0..366002fee7 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/MockFileSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/MockFileSessionStorage.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; - /** * MockFileSessionStorage is used to mock sessions for * functional testing when done in a single PHP process. @@ -25,11 +22,6 @@ use Symfony\Component\HttpFoundation\FlashBagInterface; */ class MockFileSessionStorage extends MockArraySessionStorage { - /** - * @var array - */ - private $sessionData = array(); - /** * @var string */ @@ -40,12 +32,10 @@ class MockFileSessionStorage extends MockArraySessionStorage * * @param string $savePath Path of directory to save session files. * @param array $options Session options. - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) * * @see AbstractSessionStorage::__construct() */ - public function __construct($savePath = null, array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) + public function __construct($savePath = null, array $options = array()) { if (null === $savePath) { $savePath = sys_get_temp_dir(); @@ -57,7 +47,7 @@ class MockFileSessionStorage extends MockArraySessionStorage $this->savePath = $savePath; - parent::__construct($attributes, $flashes, $options); + parent::__construct($options); } /** @@ -141,8 +131,6 @@ class MockFileSessionStorage extends MockArraySessionStorage $filePath = $this->getFilePath(); $this->sessionData = is_readable($filePath) && is_file($filePath) ? unserialize(file_get_contents($filePath)) : array(); - $this->link($this->attributeBag, $this->sessionData); - $this->link($this->flashBag, $this->sessionData); + $this->loadSession($this->sessionData); } - } diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/NativeFileSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/NativeFileSessionStorage.php index f77763143f..25c36ad7fc 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/NativeFileSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/NativeFileSessionStorage.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; - /** * NativeFileSessionStorage. * @@ -33,12 +30,10 @@ class NativeFileSessionStorage extends AbstractSessionStorage * * @param string $savePath Path of directory to save session files. * @param array $options Session configuration options. - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) * * @see AbstractSessionStorage::__construct() */ - public function __construct($savePath = null, array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) + public function __construct($savePath = null, array $options = array()) { if (null === $savePath) { $savePath = sys_get_temp_dir(); @@ -50,7 +45,7 @@ class NativeFileSessionStorage extends AbstractSessionStorage $this->savePath = $savePath; - parent::__construct($attributes, $flashes, $options); + parent::__construct($options); } /** diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/NativeMemcacheSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/NativeMemcacheSessionStorage.php index a869eeaacc..338f4c2011 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/NativeMemcacheSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/NativeMemcacheSessionStorage.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; - /** * NativeMemcacheSessionStorage. * @@ -33,19 +30,17 @@ class NativeMemcacheSessionStorage extends AbstractSessionStorage * * @param string $savePath Path of memcache server. * @param array $options Session configuration options. - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) * * @see AbstractSessionStorage::__construct() */ - public function __construct($savePath = 'tcp://127.0.0.1:11211?persistent=0', array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) + public function __construct($savePath = 'tcp://127.0.0.1:11211?persistent=0', array $options = array()) { if (!extension_loaded('memcache')) { throw new \RuntimeException('PHP does not have "memcache" session module registered'); } $this->savePath = $savePath; - parent::__construct($attributes, $flashes, $options); + parent::__construct($options); } /** diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/NativeMemcachedSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/NativeMemcachedSessionStorage.php index 28635d6caf..446e5c197a 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/NativeMemcachedSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/NativeMemcachedSessionStorage.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; - /** * NativeMemcachedSessionStorage. * @@ -33,19 +30,17 @@ class NativeMemcachedSessionStorage extends AbstractSessionStorage * * @param string $savePath Comma separated list of servers: e.g. memcache1.example.com:11211,memcache2.example.com:11211 * @param array $options Session configuration options. - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for defaul FlashBag) * * @see AbstractSessionStorage::__construct() */ - public function __construct($savePath = '127.0.0.1:11211', array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) + public function __construct($savePath = '127.0.0.1:11211', array $options = array()) { if (!extension_loaded('memcached')) { throw new \RuntimeException('PHP does not have "memcached" session module registered'); } $this->savePath = $savePath; - parent::__construct($attributes, $flashes, $options); + parent::__construct($options); } /** diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/NativeSqliteSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/NativeSqliteSessionStorage.php index bdcaeeb6b4..3acf2e7056 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/NativeSqliteSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/NativeSqliteSessionStorage.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; - /** * NativeSqliteSessionStorage. * @@ -33,19 +30,17 @@ class NativeSqliteSessionStorage extends AbstractSessionStorage * * @param string $dbPath Path to SQLite database file. * @param array $options Session configuration options. - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for defaul FlashBag) * * @see AbstractSessionStorage::__construct() */ - public function __construct($dbPath, array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) + public function __construct($dbPath, array $options = array()) { if (!extension_loaded('sqlite')) { throw new \RuntimeException('PHP does not have "sqlite" session module registered'); } $this->dbPath = $dbPath; - parent::__construct($attributes, $flashes, $options); + parent::__construct($options); } /** diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/NullSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/NullSessionStorage.php index 1ba5d5b898..4539cb72ad 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/NullSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/NullSessionStorage.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; - /** * NullSessionStorage. * diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php index 4f1c037153..3b36a1fcef 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\AttributeBagInterface; -use Symfony\Component\HttpFoundation\FlashBagInterface; - /** * PdoSessionStorage. * @@ -44,14 +41,12 @@ class PdoSessionStorage extends AbstractSessionStorage implements SessionSaveHan * @param \PDO $pdo A \PDO instance * @param array $dbOptions An associative array of DB options * @param array $options Session configuration options - * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) - * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for defaul FlashBag) * * @throws \InvalidArgumentException When "db_table" option is not provided * * @see AbstractSessionStorage::__construct() */ - public function __construct(\PDO $pdo, array $dbOptions = array(), array $options = array(), AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) + public function __construct(\PDO $pdo, array $dbOptions = array(), array $options = array()) { if (!array_key_exists('db_table', $dbOptions)) { throw new \InvalidArgumentException('You must provide the "db_table" option for a PdoSessionStorage.'); @@ -64,7 +59,7 @@ class PdoSessionStorage extends AbstractSessionStorage implements SessionSaveHan 'db_time_col' => 'sess_time', ), $dbOptions); - parent::__construct($attributes, $flashes, $options); + parent::__construct($options); } /** diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/SessionSaveHandlerInterface.php b/src/Symfony/Component/HttpFoundation/SessionStorage/SessionSaveHandlerInterface.php index 774bfa946a..6c6929fb37 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/SessionSaveHandlerInterface.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/SessionSaveHandlerInterface.php @@ -27,7 +27,7 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; * automatically when PHP starts, but these can be overriden using * this command if you need anything other than PHP's default handling. * - * When the session starts, PHP will call the sessionRead() handler + * When the session starts, PHP will call the readSession() handler * which should return a string extactly as stored (which will have * been encoded by PHP using a special session serializer session_decode() * which is different to the serialize() function. PHP will then populate @@ -38,16 +38,16 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; * be stored. * * When a session is specifically destroyed, PHP will call the - * sessionDestroy() handler with the session ID. This happens when the + * sessionSession() handler with the session ID. This happens when the * session is regenerated for example and th handler MUST delete the * session by ID from the persistent storage immediately. * - * PHP will call sessionGc() from time to time to expire any session + * PHP will call sessionSession() from time to time to expire any session * records according to the set max lifetime of a session. This routine * should delete all records from persistent storage which were last * accessed longer than the $lifetime. * - * PHP sessionOpen() and sessionClose() are pretty much redundant and + * PHP openSession() and closeSession() are pretty much redundant and * can return true. * * @author Drak diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/SessionStorageInterface.php b/src/Symfony/Component/HttpFoundation/SessionStorage/SessionStorageInterface.php index 8624e52ec6..bb76d15f74 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/SessionStorageInterface.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/SessionStorageInterface.php @@ -11,8 +11,7 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; -use Symfony\Component\HttpFoundation\FlashBagInterface; -use Symfony\Component\HttpFoundation\AttributeBagInterface; +use Symfony\Component\HttpFoundation\SessionBagInterface; /** * SessionStorageInterface. @@ -78,16 +77,14 @@ interface SessionStorageInterface function clear(); /** - * Gets the FlashBagInterface driver. + * Gets a SessionBagInterface by name. * - * @return FlashBagInterface + * @return SessionBagInterface */ - function getFlashes(); + function getBag($name); /** - * Gets the AttributeBagInterface driver. - * - * @return AttributeBagInterface + * Registers a SessionBagInterface for use. */ - function getAttributes(); + function registerBag(SessionBagInterface $bag); } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php index f392b7e666..0023817aef 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php @@ -15,8 +15,6 @@ namespace Symfony\Tests\Component\HttpFoundation; use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage; use Symfony\Component\HttpFoundation\Session; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\FlashBag; -use Symfony\Component\HttpFoundation\AttributeBag; class RequestTest extends \PHPUnit_Framework_TestCase { @@ -848,7 +846,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase $request = new Request; $this->assertFalse($request->hasSession()); - $request->setSession(new Session(new MockArraySessionStorage(new AttributeBag(), new FlashBag()))); + $request->setSession(new Session(new MockArraySessionStorage())); $this->assertTrue($request->hasSession()); } @@ -859,7 +857,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase $this->assertFalse($request->hasPreviousSession()); $request->cookies->set(session_name(), 'foo'); $this->assertFalse($request->hasPreviousSession()); - $request->setSession(new Session(new MockArraySessionStorage(new AttributeBag(), new FlashBag()))); + $request->setSession(new Session(new MockArraySessionStorage())); $this->assertTrue($request->hasPreviousSession()); } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/AttributeBagTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionAttribute/AttributeBagTest.php similarity index 98% rename from tests/Symfony/Tests/Component/HttpFoundation/AttributeBagTest.php rename to tests/Symfony/Tests/Component/HttpFoundation/SessionAttribute/AttributeBagTest.php index 60e13794e0..4d35f35602 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/AttributeBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionAttribute/AttributeBagTest.php @@ -1,7 +1,7 @@ registerBag(new AttributeBag); + + return $storage; } - public function testGetFlashBag() + public function testBag() { $storage = $this->getStorage(); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes()); + $bag = new FlashBag(); + $storage->registerBag($bag); + $this->assertSame($bag, $storage->getBag($bag->getName())); } - public function testGetAttributeBag() + /** + * @expectedException \InvalidArgumentException + */ + public function testRegisterBagException() { $storage = $this->getStorage(); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes()); + $storage->getBag('non_existing'); } public function testGetId() @@ -85,10 +95,10 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase $storage = $this->getStorage(); $storage->start(); $id = $storage->getId(); - $storage->getAttributes()->set('lucky', 7); + $storage->getBag('attributes')->set('lucky', 7); $storage->regenerate(); $this->assertNotEquals($id, $storage->getId()); - $this->assertEquals(7, $storage->getAttributes()->get('lucky')); + $this->assertEquals(7, $storage->getBag('attributes')->get('lucky')); } @@ -97,10 +107,10 @@ class AbstractSessionStorageTest extends \PHPUnit_Framework_TestCase $storage = $this->getStorage(); $storage->start(); $id = $storage->getId(); - $storage->getAttributes()->set('legs', 11); + $storage->getBag('attributes')->set('legs', 11); $storage->regenerate(true); $this->assertNotEquals($id, $storage->getId()); - $this->assertEquals(11, $storage->getAttributes()->get('legs')); + $this->assertEquals(11, $storage->getBag('attributes')->get('legs')); } public function testCustomSaveHandlers() diff --git a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/MockArraySessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/MockArraySessionStorageTest.php index 441d7b91c3..c3c1959735 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/MockArraySessionStorageTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/MockArraySessionStorageTest.php @@ -3,8 +3,8 @@ namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage; -use Symfony\Component\HttpFoundation\AttributeBag; -use Symfony\Component\HttpFoundation\FlashBag; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; /** @@ -29,17 +29,27 @@ class MockArraySessionStorageTest extends \PHPUnit_Framework_TestCase */ private $flashes; + private $data; + protected function setUp() { - $this->attributes = array('foo' => 'bar'); - $this->flashes = array('notice' => 'hello'); - $this->storage = new MockArraySessionStorage(new AttributeBag(), new FlashBag()); - $this->storage->setFlashes($this->flashes); - $this->storage->setAttributes($this->attributes); + $this->attributes = new AttributeBag(); + $this->flashes = new FlashBag(); + + $this->data = array( + $this->attributes->getStorageKey() => array('foo' => 'bar'), + $this->flashes->getStorageKey() => array('notice' => 'hello'), + ); + + $this->storage = new MockArraySessionStorage(); + $this->storage->registerBag($this->flashes); + $this->storage->registerBag($this->attributes); + $this->storage->setSessionData($this->data); } protected function tearDown() { + $this->data = null; $this->flashes = null; $this->attributes = null; $this->storage = null; @@ -61,14 +71,14 @@ class MockArraySessionStorageTest extends \PHPUnit_Framework_TestCase $id = $this->storage->getId(); $this->storage->regenerate(); $this->assertNotEquals($id, $this->storage->getId()); - $this->assertEquals($this->attributes, $this->storage->getAttributes()->all()); - $this->assertEquals($this->flashes, $this->storage->getFlashes()->all()); + $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all()); + $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->all()); $id = $this->storage->getId(); $this->storage->regenerate(true); $this->assertNotEquals($id, $this->storage->getId()); - $this->assertEquals($this->attributes, $this->storage->getAttributes()->all()); - $this->assertEquals($this->flashes, $this->storage->getFlashes()->all()); + $this->assertEquals(array('foo' => 'bar'), $this->storage->getBag('attributes')->all()); + $this->assertEquals(array('notice' => 'hello'), $this->storage->getBag('flashes')->all()); } public function testGetId() diff --git a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/MockFileSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/MockFileSessionStorageTest.php index f0ba864b31..469410100b 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/MockFileSessionStorageTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/MockFileSessionStorageTest.php @@ -3,6 +3,8 @@ namespace Symfony\Test\Component\HttpFoundation\SessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\MockFileSessionStorage; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag; /** * Test class for MockFileSessionStorage. @@ -50,11 +52,11 @@ class MockFileSessionStorageTest extends \PHPUnit_Framework_TestCase public function testRegenerate() { $this->storage->start(); - $this->storage->getAttributes()->set('regenerate', 1234); + $this->storage->getBag('attributes')->set('regenerate', 1234); $this->storage->regenerate(); - $this->assertEquals(1234, $this->storage->getAttributes()->get('regenerate')); + $this->assertEquals(1234, $this->storage->getBag('attributes')->get('regenerate')); $this->storage->regenerate(true); - $this->assertEquals(1234, $this->storage->getAttributes()->get('regenerate')); + $this->assertEquals(1234, $this->storage->getBag('attributes')->get('regenerate')); } public function testGetId() @@ -67,33 +69,37 @@ class MockFileSessionStorageTest extends \PHPUnit_Framework_TestCase public function testSave() { $this->storage->start(); - $this->assertNotEquals('108', $this->storage->getAttributes()->get('new')); - $this->assertFalse($this->storage->getFlashes()->has('newkey')); - $this->storage->getAttributes()->set('new', '108'); - $this->storage->getFlashes()->set('newkey', 'test'); + $this->assertNotEquals('108', $this->storage->getBag('attributes')->get('new')); + $this->assertFalse($this->storage->getBag('flashes')->has('newkey')); + $this->storage->getBag('attributes')->set('new', '108'); + $this->storage->getBag('flashes')->set('newkey', 'test'); $this->storage->save(); $storage = $this->getStorage(); $storage->start(); - $this->assertEquals('108', $storage->getAttributes()->get('new')); - $this->assertTrue($storage->getFlashes()->has('newkey')); - $this->assertEquals('test', $storage->getFlashes()->get('newkey')); + $this->assertEquals('108', $storage->getBag('attributes')->get('new')); + $this->assertTrue($storage->getBag('flashes')->has('newkey')); + $this->assertEquals('test', $storage->getBag('flashes')->get('newkey')); } public function testMultipleInstances() { $storage1 = $this->getStorage(); $storage1->start(); - $storage1->getAttributes()->set('foo', 'bar'); + $storage1->getBag('attributes')->set('foo', 'bar'); $storage1->save(); $storage2 = $this->getStorage(); $storage2->start(); - $this->assertEquals('bar', $storage2->getAttributes()->get('foo'), 'values persist between instances'); + $this->assertEquals('bar', $storage2->getBag('attributes')->get('foo'), 'values persist between instances'); } private function getStorage(array $options = array()) { - return new MockFileSessionStorage($this->sessionDir, $options); + $storage = new MockFileSessionStorage($this->sessionDir, $options); + $storage->registerBag(new FlashBag); + $storage->registerBag(new AttributeBag); + + return $storage; } } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeFileSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeFileSessionStorageTest.php index 0bb4dd6cfc..8b32840e25 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeFileSessionStorageTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeFileSessionStorageTest.php @@ -3,8 +3,8 @@ namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\NativeFileSessionStorage; -use Symfony\Component\HttpFoundation\AttributeBag; -use Symfony\Component\HttpFoundation\FlashBag; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; /** * Test class for NativeFileSessionStorage. @@ -15,23 +15,11 @@ use Symfony\Component\HttpFoundation\FlashBag; */ class NativeFileSessionStorageTest extends \PHPUnit_Framework_TestCase { - public function testConstructDefaults() - { - $storage = new NativeFileSessionStorage(); - $this->assertEquals('files', ini_get('session.save_handler')); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes()); - } - public function testSaveHandlers() { - $attributeBag = new AttributeBag(); - $flashBag = new FlashBag(); - $storage = new NativeFileSessionStorage(sys_get_temp_dir(), array('name' => 'TESTING'), $attributeBag, $flashBag); + $storage = new NativeFileSessionStorage(sys_get_temp_dir(), array('name' => 'TESTING')); $this->assertEquals('files', ini_get('session.save_handler')); $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path')); $this->assertEquals('TESTING', ini_get('session.name')); - $this->assertSame($attributeBag, $storage->getAttributes()); - $this->assertSame($flashBag, $storage->getFlashes()); } } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeMemcacheSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeMemcacheSessionStorageTest.php index 8f498f2e44..38019e2508 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeMemcacheSessionStorageTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeMemcacheSessionStorageTest.php @@ -3,8 +3,8 @@ namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\NativeMemcacheSessionStorage; -use Symfony\Component\HttpFoundation\AttributeBag; -use Symfony\Component\HttpFoundation\FlashBag; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; /** * Test class for NativeMemcacheSessionStorage. @@ -15,31 +15,15 @@ use Symfony\Component\HttpFoundation\FlashBag; */ class NativeMemcacheSessionStorageTest extends \PHPUnit_Framework_TestCase { - public function testConstructDefaults() - { - if (!extension_loaded('memcache')) { - $this->markTestSkipped('Skipped tests SQLite extension is not present'); - } - - $storage = new NativeMemcacheSessionStorage('tcp://127.0.0.1:11211?persistent=0'); - $this->assertEquals('memcache', ini_get('session.save_handler')); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes()); - } - public function testSaveHandlers() { if (!extension_loaded('memcache')) { $this->markTestSkipped('Skipped tests SQLite extension is not present'); } - $attributeBag = new AttributeBag(); - $flashBag = new FlashBag(); - $storage = new NativeMemcacheSessionStorage('tcp://127.0.0.1:11211?persistent=0', array('name' => 'TESTING'), $attributeBag, $flashBag); + $storage = new NativeMemcacheSessionStorage('tcp://127.0.0.1:11211?persistent=0', array('name' => 'TESTING')); $this->assertEquals('memcache', ini_get('session.save_handler')); $this->assertEquals('tcp://127.0.0.1:11211?persistent=0', ini_get('session.save_path')); $this->assertEquals('TESTING', ini_get('session.name')); - $this->assertSame($attributeBag, $storage->getAttributes()); - $this->assertSame($flashBag, $storage->getFlashes()); } } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeMemcachedSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeMemcachedSessionStorageTest.php index 1559a117ab..fe3307a1fd 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeMemcachedSessionStorageTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeMemcachedSessionStorageTest.php @@ -3,8 +3,8 @@ namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\NativeMemcachedSessionStorage; -use Symfony\Component\HttpFoundation\AttributeBag; -use Symfony\Component\HttpFoundation\FlashBag; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; /** * Test class for NativeMemcachedSessionStorage. @@ -15,40 +15,20 @@ use Symfony\Component\HttpFoundation\FlashBag; */ class NativeMemcachedSessionStorageTest extends \PHPUnit_Framework_TestCase { - public function testConstructDefaults() - { - if (!extension_loaded('memcached')) { - $this->markTestSkipped('Skipped tests SQLite extension is not present'); - } - - // test takes too long if memcached server is not running - ini_set('memcached.sess_locking', '0'); - - $storage = new NativeMemcachedSessionStorage('127.0.0.1:11211'); - $this->assertEquals('memcached', ini_get('session.save_handler')); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes()); - } - public function testSaveHandlers() { if (!extension_loaded('memcached')) { $this->markTestSkipped('Skipped tests SQLite extension is not present'); } - $attributeBag = new AttributeBag(); - $flashBag = new FlashBag(); - // test takes too long if memcached server is not running ini_set('memcached.sess_locking', '0'); - $storage = new NativeMemcachedSessionStorage('127.0.0.1:11211', array('name' => 'TESTING'), $attributeBag, $flashBag); + $storage = new NativeMemcachedSessionStorage('127.0.0.1:11211', array('name' => 'TESTING')); $this->assertEquals('memcached', ini_get('session.save_handler')); $this->assertEquals('127.0.0.1:11211', ini_get('session.save_path')); $this->assertEquals('TESTING', ini_get('session.name')); - $this->assertSame($attributeBag, $storage->getAttributes()); - $this->assertSame($flashBag, $storage->getFlashes()); } } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeSqliteSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeSqliteSessionStorageTest.php index 51d1b64ebe..455f1392d7 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeSqliteSessionStorageTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NativeSqliteSessionStorageTest.php @@ -3,8 +3,8 @@ namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; use Symfony\Component\HttpFoundation\SessionStorage\NativeSqliteSessionStorage; -use Symfony\Component\HttpFoundation\AttributeBag; -use Symfony\Component\HttpFoundation\FlashBag; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; /** * Test class for NativeSqliteSessionStorage. @@ -15,32 +15,16 @@ use Symfony\Component\HttpFoundation\FlashBag; */ class NativeSqliteSessionStorageTest extends \PHPUnit_Framework_TestCase { - public function testConstructDefaults() - { - if (!extension_loaded('sqlite')) { - $this->markTestSkipped('Skipped tests SQLite extension is not present'); - } - - $storage = new NativeSqliteSessionStorage(sys_get_temp_dir().'/sqlite.db'); - $this->assertEquals('sqlite', ini_get('session.save_handler')); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes()); - } - public function testSaveHandlers() { if (!extension_loaded('sqlite')) { $this->markTestSkipped('Skipped tests SQLite extension is not present'); } - $attributeBag = new AttributeBag(); - $flashBag = new FlashBag(); - $storage = new NativeSqliteSessionStorage(sys_get_temp_dir().'/sqlite.db', array('name' => 'TESTING'), $attributeBag, $flashBag); + $storage = new NativeSqliteSessionStorage(sys_get_temp_dir().'/sqlite.db', array('name' => 'TESTING')); $this->assertEquals('sqlite', ini_get('session.save_handler')); $this->assertEquals(sys_get_temp_dir().'/sqlite.db', ini_get('session.save_path')); $this->assertEquals('TESTING', ini_get('session.name')); - $this->assertSame($attributeBag, $storage->getAttributes()); - $this->assertSame($flashBag, $storage->getFlashes()); } } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NullSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NullSessionStorageTest.php index 6bc94def52..26782337c8 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NullSessionStorageTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/NullSessionStorageTest.php @@ -13,14 +13,6 @@ use Symfony\Component\HttpFoundation\Session; */ class NullSessionStorageTest extends \PHPUnit_Framework_TestCase { - public function testConstructDefaults() - { - $storage = new NullSessionStorage(); - $this->assertEquals('user', ini_get('session.save_handler')); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\AttributeBagInterface', $storage->getAttributes()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\FlashBagInterface', $storage->getFlashes()); - } - public function testSaveHandlers() { $storage = new NullSessionStorage(); diff --git a/tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php index 3066319463..7f86b89b0b 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php @@ -12,10 +12,10 @@ namespace Symfony\Tests\Component\HttpFoundation; use Symfony\Component\HttpFoundation\Session; -use Symfony\Component\HttpFoundation\FlashBag; -use Symfony\Component\HttpFoundation\FlashBagInterface; -use Symfony\Component\HttpFoundation\AttributeBag; -use Symfony\Component\HttpFoundation\AttributeBagInterface; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBag; +use Symfony\Component\HttpFoundation\SessionFlash\FlashBagInterface; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBag; +use Symfony\Component\HttpFoundation\SessionAttribute\AttributeBagInterface; use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage; /** @@ -39,8 +39,8 @@ class SessionTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->storage = new MockArraySessionStorage(new AttributeBag(), new FlashBag()); - $this->session = new Session($this->storage); + $this->storage = new MockArraySessionStorage(); + $this->session = new Session($this->storage, new AttributeBag(), new FlashBag()); } protected function tearDown()