Skip to content
Browse files

merged branch drak/session_refactor (PR #2853)

Commits
-------

cb6fdb1 [HttpFoundation] removed Session::close()
c59d880 Docblocks.
b8df162 Correct instanceof condition.
8a01dd5 renamed getFlashes() to getFlashBag() to avoid clashes
282d3ae updated CHANGELOG for 2.1
0f6c50a [HttpFoundation] added some method for a better BC
146a502 [FrameworkBundle] added some service aliases to avoid some BC breaks
93d81a1 [HttpFoundation] removed configuration for session storages in session.xml as we cannot provide a way to configure them (like before this PR anyway)
74ccf70 reverted 5b7ef11 (Simplify session storage class names now we have a separate namespace for sessions)
91f4f8a [HttpFoundation] changed default flash bag to auto-expires to keep BC
0494250 removed unused use statements
7878a0a [HttpFoundation] renamed pop() to all() and getAll() to all()
0d2745f [HttpFoundation] Remove constants from FlashBagInterface
dad60ef [HttpFoundation] Add back get defaults and small clean-up.
5b7ef11 [HttpFoundation] Simplify session storage class names now we have a separate namespace for sessions.
27530cb [HttpFoundation] Moved session related classes to own sub-namespace.
4683915 [HttpFoundation] Free bags from session storage and move classes to their own namespaces.
d64939a [DoctrineBridge] Refactored driver for changed interface.
f9951a3 Fixed formatting.
398acc9 [HttpFoundation] Reworked flashes to maintain same behaviour as in Symfony 2.0
f98f9ae [HttpFoundation] Refactor for DRY code.
9dd4dbe Documentation, changelogs and coding standards.
1ed6ee3 [DoctribeBridge][SecurityBundle][WebProfiler] Refactor code for HttpFoundation changes.
7aaf024 [FrameworkBundle] Refactored code for changes to HttpFoundation component.
669bc96 [HttpFoundation] Added pure Memcache, Memcached and Null storage drivers.
e185c8d [HttpFoundation] Refactored component for session workflow.
85b5c43 [HttpFoundation] Added drivers for PHP native session save handlers, files, sqlite, memcache and memcached.
57ef984 [HttpFoundation] Added unit and functional testing session storage objects.
3a263dc [HttpFoundation] Introduced session storage base class and interfaces.
c969423 [HttpFoundation] Added FlashBagInterface and concrete implementation.
39288bc [HttpFoundation] Added AttributesInterface and AttributesBagInterface and concrete implementations.

Discussion
----------

[2.1][HttpFoundation] Refactor session handling and flash messages

Bug fix: yes
Feature addition: yes
Backwards compatibility break: yes
Symfony2 tests pass: yes
Fixes the following tickets: #2607, #2591, #2717, #2773
References the following tickets: #2592, #2543, #2541, #2510, #2714, #2684
Todo: -

__Introduction__

This extensive PR is a refactor with minimal BC breaks of the `[HttpFoundation]` component's session management which fixes several issues in the current implementation.  This PR includes all necessary changes to other bundles and components is documented in the `CHANGELOG-2.1` and `UPGRADING-2.1`.

__Summary of Changes__

__Session:__
  - Session object now implements `SessionInterface`

__Attributes:__
  - Attributes now handled by `AttributeBagInterface`
  - Added two AttributeBag implementations: `AttributeBag` replicates the current Symfony2 attributes behaviour, and the second, `NamespacedAttributeBag` introduces structured namespaced representation using '/' in the key.  Both are BC.  `FrameworkBundle` defaults to the old behaviour.

__Flash messages:__
  - Flash messages now handled by `FlashBagInterface`
  - Introduced `FlashBag` which changes the way flash messages expire, they now expire on use rather than automatically, useful for ESI.
  - Introduced `AutoExpireFlashBag` (default) which replicates the old automatic expiry behaviour of flash messages.

__Session Storage:__
  - Introduced a base object, `AbstractSessionStorage` for session storage drivers
  - Introduced a `SessionSaveHandlerInterface` when using custom session save handlers
  - Introduced a `NullSessionStorage` driver which allows for unsaved sessions
  - Introduced new session storage drivers for Memcache and Memcached
  - Introduced new session storage drivers for PHP's native SQLite, Memcache and Memcached support

__General:__
  - Fixed bugs where session attributes are not saved and all cases where flash messages would get lost
  - Wrote new tests, refactored related existing tests and increased test coverage extensively.

__Rationale/Details__

I'll explain more detail in the following sections.

__Unit Tests__

All unit and functional tests pass.

__Note on Functional Testing__

I've introduced `MockFileSessionStorage` which replaces `FilesystemSessionStorage` to emulate a PHP session for functional testing.  Essentially the same methodology of functional testing has been maintained but without interrupting the other session storage drivers interaction with real PHP sessions.  The service is now called `session.storage.mock_file`.

__Session Workflow__

PHP sessions follow a specific workflow which is not being followed by the current session management implementation and is responsible for some unpredictable bugs and behaviours.

Basically, PHP session workflow is as follows: `open`, `read`, `write`, `close`.  In between these can occur, `destroy` and `garbage collection`.  These actions are handled by `session save handlers` and one is always registered in all cases.  By default, the `files` save handler (internally to PHP) is registered by PHP at the start of code execution.

PHP offers the possibility to change the save handler to another internal type, for example one provided by a PHP extension (think SQLite, Memcache etc), or you can register a user type and set your own handlers.  However __in all cases__ PHP requires the handlers.

The handlers are called when the following things occur:

  - `open` and `read` when `session_start()` or the session autostarts when PHP outputs some display
  - `destroy` when `session_regenerate_id(true)` is called
  - `write` and `close` when PHP shuts down or when `session_write_close()` is called
  - `garbage collection` is called randomly according to configurable probability

The next very important aspect of this PR is that `$_SESSION` plays an important part in this workflow because the contents of the $_SESSION is populated __after__ the `read` handler returns the previously saved serialised session data.  The `write` handler is sent the serialised `$_SESSION` contents for save.  Please note the serialisation is a different format to `serialize()`.

For this reason, any session implementation cannot get rid of using `$_SESSION`.

I wrote more details on this issue [here](#2607 (comment))

In order to make writing session storage drivers simple, I created a light base class `AbstractSessionStorage` and the `SessionSaveHandlerInterface` which allows you to quickly write native and custom save handler drivers.

__Flash Messages [BC BREAK]__

Flash messages currently allow representation of a single message per `$name`.  Fabien designed the original system so that `$name` was equivalent to flash message type.  The current PR changes the fact that Flash messages expire explicitly when retrieved for display to the user as opposed to immediately on the next page load.

The last issue fixes potential cases when flash messages are lost due to an unexpected intervening page-load (an error for example).  The API `get()` has a flag which allows you to override the `clear()` action.

__Flash message translation__

This PR does not cover translation of flash messages because  messages should be translated before calling the flash message API.  This is because flash messages are used to present messages to the user after a specific action, and in any case, immediately on the next page load.  Since we know the locale of the request in every case we can translate the message before storing.  Secondly, translation is simply a string manipulation.  Translation API calls should always have the raw untranslated string present because it allows for extraction of translation catalogs.  For a complete answer see my answer [here](#2543 (comment))

__Session attribute and structured namespacing__

__This has been implemented without changing the current default behaviour__ but details are below for the alternative:

Attributes are currently stored in a flat array which limits the potential of session attributes:

Here are some examples to see why this 'structured namespace' methodology is extremely convenient over using a flat system.  Let's look at an example with csrf tokens.  Let's say we have multiple csrftokens stored by form ID (allowing multiple forms on the page and tabbed browsing).

If we're using a flat system, you might have

    'tokens' => array('a' => 'a6c1e0b6',
                      'b' => 'f4a7b1f3')

With a flat system when you get the key `tokens`, you will get back an array, so now you have to analyse the array.  So if you simply want to add another token, you have to follow three steps: get the session attribute `tokens`, have to add to the array, and lastly set the entire array back to the session.

    $tokens = $session->get('tokens');
    $tokens['c'] = $value;
    $session->set('tokens', $tokens);

Doable, but you can see it's pretty long winded.

With structured namespacing you can simply do:

    $session->set('c', $value, '/tokens');

There are several ways to implement this, either with an additional `$namespace` argument, or by treating a character in the `$key` as a namespacer.  `NamespacedAttributeBag` treats `/` as a namespacer so you can represent `user.tokens/a` for example.  The namespace character is configurable in `NamespacedAttributeBag`.

---------------------------------------------------------------------------

by marijn at 2011-12-18T15:43:17Z

I haven't read the code yet but the description from this PR and your line of thought seem very well structured.
Seems like a big +1 for me.

---------------------------------------------------------------------------

by lsmith77 at 2011-12-19T16:01:19Z

@deviantintegral could you look over this to see if it really addresses everything you wanted with PR #2510 ?

---------------------------------------------------------------------------

by deviantintegral at 2011-12-24T20:12:03Z

I've read through the documentation and upgrade notes, and I can't see anything that's obviously missing from #2510. Being able to support multiple flashes per type is the most important, and the API looks reasonable to me. Drupal does support supressing repeat messages, but that can easily be implemented in our code unless there's a compelling case for it to be a part of Symfony.

I wonder if PHP memcache support is required in Symfony given the availability of memcached. I'm not familiar with how other parts of Symfony handle it, but there is often quite a bit of confusion between the two PHP extensions. It could be simpler to remove one, or add a bit of info describing or linking to why there are two nearly identical classes.

Is it possible to make one class inherit from the other (memcached is a child of memcache)?

---------------------------------------------------------------------------

by Fristi at 2011-12-24T20:29:46Z

Interesting, maybe add: session events as I did with the current impl: https://github.com/Fristi/SessionBundle

---------------------------------------------------------------------------

by drak at 2011-12-25T00:50:03Z

@deviantintegral - I agree about the confusion between memcache and memcached but actually, it is necessary to support both because `memcached` is not available everywhere.  For example on Debian Lenny and RHEL/CentOS 5, only memcache is available by default.  This would preclude a massive amount of shared hosting environments.  Also, it is not possible to inherit one from the other, they are completely different drivers.

@Fristi - I also thought about the events, but they do not belong as part of the standalone component as this would create a coupling to the event dispatcher.  The way you have done it, ie, in a bundle is the right way to achieve it.

---------------------------------------------------------------------------

by matheo at 2011-12-25T01:12:00Z

Impressive work, looks like a big improvement and deserves a big +1

---------------------------------------------------------------------------

by datiecher at 2011-12-26T11:57:12Z

Took some time to grok all the changes in this PR but all in all it is a keeper. Specially the new flash message API, it's really nicer to work with it then the previous one.

Nicely done @drak!

---------------------------------------------------------------------------

by lsmith77 at 2012-01-02T15:00:00Z

@fabpot did you have time to review this yet? with all the work @drak has done its important that he gets some feedback soon. its clear this PR breaks BC in ways we never wanted to allow. but i think this PR also clearly explains why its necessary none the less.

---------------------------------------------------------------------------

by drak at 2012-01-02T15:41:53Z

@fabpot - I have removed the WIP status from this PR now and rebased against the current master branch.

---------------------------------------------------------------------------

by Tobion at 2012-01-07T07:13:38Z

From what I read from the IRC chat logs, the main concern of @fabpot is whether we really need multiple flash messages per type. I'm in favor of this PR and just want to add one point to this discussion.
At the moment you can add multiple flash messages of different type/category/identifier. For example you can specify one error message and one info message after an operation. I think most agree that this can be usefull.
But then it makes semantically no sense that you currently cannot add 2 info messages. This approach feels a bit half-done.
So I think this PR eliminates this paradox.

---------------------------------------------------------------------------

by drak at 2012-01-07T09:11:07Z

For reference there is also a discussion started by @lsmith77 on the mailing list at https://groups.google.com/forum/#!topic/symfony-devs/cy4wokD0mQI

---------------------------------------------------------------------------

by dlsniper at 2012-01-07T16:02:15Z

@drak I could also add the next scenario that I currently have to live with, in addition to @lsmith77 ones.

I had this issue while working on our shopping cart implementation for a customer where the customer wanted to show the unavailability of the items as different lines in the 'flash-error' section of the cart. We had to set an array as the 'flash message' in order to display that information.

So in this case for example having the flash messages types as array would actually make more sense that sending an array to the flasher. Plus the the other issue we had was that we also wanted to add another error in the message but we had to do a check to see if the flash message is an array already or we need to make it an array.

I think it's better not to impose a limit of this sort and let the users be able to handle every scenario, even if some are rare, rather that forcing users to overcome limitations such as these.

I really hope this PR gets approved faster and thanks everyone for their hard work :)

---------------------------------------------------------------------------

by Tobion at 2012-01-07T21:01:07Z

@dlsniper I think you misinterpreted my point.

---------------------------------------------------------------------------

by dlsniper at 2012-01-07T21:04:04Z

@Tobion I'm sorry I did that, I'll edit the message asap. Seems no sleep in 26 hours can cause brain not to function as intended :)

---------------------------------------------------------------------------

by lsmith77 at 2012-02-01T14:38:52Z

FYI the drupal guys are liking this PR (including the flash changes):
http://drupal.org/node/335411

---------------------------------------------------------------------------

by drak at 2012-02-01T14:51:33Z

@lsmith77 Fabien asked me to remove the changes to the flash messages so that they are as before - i.e. only one flash per name/type /cc @fabpot

---------------------------------------------------------------------------

by fabpot at 2012-02-01T14:58:23Z

To be clear, I've asked to split this PR in two parts:

 * one about the session refactoring (which is non-controversial and should be merged ASAP)
 * this one with only the flash refactoring

---------------------------------------------------------------------------

by drak at 2012-02-02T11:29:26Z

@fabpot this is ready to be merged now.  I will open a separate PR later today for the flash messages as a bucket.

---------------------------------------------------------------------------

by fabpot at 2012-02-02T11:34:39Z

I must have missed something, but I still see a lot of changes related to the flash messages.

---------------------------------------------------------------------------

by drak at 2012-02-02T11:39:10Z

When I spoke to you you said you wanted to make the commit with flash messages with one message per name/type rather than multiple.  The old flash messages behaviour is 100% maintained in `AutoExpireFlashBag` which can be the default in the framework if you wish.  The `FlashBag` implementation makes Symfony2 ESI compatible.

---------------------------------------------------------------------------

by stof at 2012-02-02T11:47:38Z

@drak splitting into 2 PRs means you should not refactor the flash messages in this one but in the dedicated one.

---------------------------------------------------------------------------

by drak at 2012-02-02T12:29:43Z

@stof Yes. I discussed with Fabien over chat there are basically no changes
to flashes in `FlashBag` and `AutoExpireFlashBag` maintains the exact
behaviour as before.  The FlashBag just introduces ESI compatible flashes.
 There is no way to refactor the sessions without moving the flash messages
to their own bag.  The next PR will propose the changes to flashes that
allow multiple messages per name/type.  I can size the PR down a little
more removing the new storage drivers and so on to make the PR smaller but
that's really as far as I can go.  To be clear, while the API has changed a
little for flashes, the behaviour is the same.
  • Loading branch information...
2 parents 2ae1f90 + cb6fdb1 commit 48414000bb1342c01b729df7d9dcc6f6c66cc144 @fabpot fabpot committed Feb 11, 2012
Showing with 4,191 additions and 1,421 deletions.
  1. +28 −0 CHANGELOG-2.1.md
  2. +72 −5 UPGRADE-2.1.md
  3. +25 −33 src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionStorage.php
  4. +1 −1 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
  5. +1 −1 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
  6. +0 −1 src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php
  7. +18 −5 src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml
  8. +1 −1 src/Symfony/Bundle/FrameworkBundle/Templating/GlobalVariables.php
  9. +3 −3 src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php
  10. +1 −1 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php
  11. +1 −1 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
  12. +1 −1 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
  13. +1 −1 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
  14. +1 −1 src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/TestSessionListenerTest.php
  15. +3 −3 ...ymfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SessionController.php
  16. +1 −1 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml
  17. +11 −10 src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php
  18. +3 −3 src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php
  19. +1 −1 src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml
  20. +3 −3 src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php
  21. +4 −3 src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php
  22. +5 −3 src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php
  23. +1 −1 src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php
  24. +1 −1 src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/SessionCsrfProvider.php
  25. +6 −4 src/Symfony/Component/HttpFoundation/Request.php
  26. +0 −358 src/Symfony/Component/HttpFoundation/Session.php
  27. +137 −0 src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBag.php
  28. +70 −0 src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBagInterface.php
  29. +184 −0 src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php
  30. +174 −0 src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php
  31. +158 −0 src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php
  32. +85 −0 src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php
  33. +318 −0 src/Symfony/Component/HttpFoundation/Session/Session.php
  34. +48 −0 src/Symfony/Component/HttpFoundation/Session/SessionBagInterface.php
  35. +108 −0 src/Symfony/Component/HttpFoundation/Session/SessionInterface.php
  36. +339 −0 src/Symfony/Component/HttpFoundation/Session/Storage/AbstractSessionStorage.php
  37. +136 −0 src/Symfony/Component/HttpFoundation/Session/Storage/MemcacheSessionStorage.php
  38. +137 −0 src/Symfony/Component/HttpFoundation/Session/Storage/MemcachedSessionStorage.php
  39. +124 −0 src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php
  40. +136 −0 src/Symfony/Component/HttpFoundation/Session/Storage/MockFileSessionStorage.php
  41. +59 −0 src/Symfony/Component/HttpFoundation/Session/Storage/NativeFileSessionStorage.php
  42. +77 −0 src/Symfony/Component/HttpFoundation/Session/Storage/NativeMemcacheSessionStorage.php
  43. +76 −0 src/Symfony/Component/HttpFoundation/Session/Storage/NativeMemcachedSessionStorage.php
  44. +54 −0 src/Symfony/Component/HttpFoundation/Session/Storage/NativeSqliteSessionStorage.php
  45. +74 −0 src/Symfony/Component/HttpFoundation/Session/Storage/NullSessionStorage.php
  46. +31 −76 src/Symfony/Component/HttpFoundation/{SessionStorage → Session/Storage}/PdoSessionStorage.php
  47. +157 −0 src/Symfony/Component/HttpFoundation/Session/Storage/SessionSaveHandlerInterface.php
  48. +92 −0 src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php
  49. +0 −81 src/Symfony/Component/HttpFoundation/SessionStorage/ArraySessionStorage.php
  50. +0 −192 src/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php
  51. +0 −180 src/Symfony/Component/HttpFoundation/SessionStorage/NativeSessionStorage.php
  52. +0 −97 src/Symfony/Component/HttpFoundation/SessionStorage/SessionStorageInterface.php
  53. +1 −1 tests/Symfony/Tests/Component/Form/Extension/Csrf/CsrfProvider/SessionCsrfProviderTest.php
  54. +4 −6 tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php
  55. +155 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Attribute/AttributeBagTest.php
  56. +162 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBagTest.php
  57. +130 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php
  58. +121 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php
  59. +171 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php
  60. +127 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/AbstractSessionStorageTest.php
  61. +90 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MockArraySessionStorageTest.php
  62. +105 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/MockFileSessionStorageTest.php
  63. +23 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/NativeFileSessionStorageTest.php
  64. +27 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/NativeMemcacheSessionStorageTest.php
  65. +32 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/NativeMemcachedSessionStorageTest.php
  66. +28 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/NativeSqliteSessionStorageTest.php
  67. +42 −0 tests/Symfony/Tests/Component/HttpFoundation/Session/Storage/NullSessionStorageTest.php
  68. +0 −104 tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/FilesystemSessionStorageTest.php
  69. +0 −232 tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php
  70. +2 −2 tests/Symfony/Tests/Component/HttpKernel/EventListener/LocaleListenerTest.php
  71. +3 −3 tests/Symfony/Tests/Component/Security/Http/Firewall/ContextListenerTest.php
  72. +1 −1 tests/Symfony/Tests/Component/Security/Http/Logout/SessionLogoutHandlerTest.php
View
28 CHANGELOG-2.1.md
@@ -224,6 +224,34 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
* removed the ContentTypeMimeTypeGuesser class as it is deprecated and never used on PHP 5.3
* added ResponseHeaderBag::makeDisposition() (implements RFC 6266)
* made mimetype to extension conversion configurable
+ * [BC BREAK] Moved all session related classes and interfaces into own namespace, as
+ `Symfony\Component\HttpFoudation\Session` and renamed classes accordingly.
+ * Added `FlashBag`. Flashes expire when retrieved by `get()` or `all()`.
+ This makes the implementation ESI compatible.
+ * Added `AutoExpireFlashBag` (default) to replicate Symfony 2.0.x auto expire behaviour of messages auto expiring
+ after one page page load. Messages must be retrived by `get()` or `all()`.
+ * [BC BREAK] Removed the `close()` method from the Session class
+ * Deprecated the following methods from the Session class: `setFlash()`, `setFlashes()`
+ `getFlash()`, `hasFlash()`, and `removeFlash()`. Use `getFlashBag() instead which returns a `FlashBagInterface`.
+ * `Session->clear()` now only clears session attributes as before it cleared flash messages and
+ attributes. `Session->getFlashBag()->all()` clears flashes now.
+ * Added `Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage` base class for
+ session storage drivers.
+ * Added `Symfony\Component\HttpFoundation\Session\Storage\SessionSaveHandlerInterface` interface
+ which storage drivers should implement after inheriting from
+ `Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage` when writing custom session save handlers.
+ * [BC BREAK] `SessionStorageInterface` methods removed: `write()`, `read()` and `remove()`. Added
+ `getBag()`, `registerBag()`.
+ * Moved attribute storage to `Symfony\Component\HttpFoundation\Attribute\AttributeBagInterface`.
+ * Added `Symfony\Component\HttpFoundation\Attribute\AttributeBag` to replicate attributes storage
+ behaviour from 2.0.x (default).
+ * Added `Symfony\Component\HttpFoundation\Attribute\NamespacedAttributeBag` for namespace session attributes.
+ * Session now implements `Symfony\Component\HttpFoundation\Session\SessionInterface` making
+ implementation customizable and portable.
+ * [BC BREAK] Removed `NativeSessionStorage` and replaced with `NativeFileSessionStorage`.
+ * Added session storage drivers for PHP native Memcache, Memcached and SQLite session save handlers.
+ * Added session storage drivers for custom Memcache, Memcached and Null session save handlers.
+ * Removed `FilesystemSessionStorage`, use `MockFileSessionStorage` for functional testing instead.
### HttpKernel
View
77 UPGRADE-2.1.md
@@ -1,6 +1,8 @@
UPGRADE FROM 2.0 to 2.1
=======================
+### General
+
* assets_base_urls and base_urls merging strategy has changed
Unlike most configuration blocks, successive values for
@@ -11,6 +13,8 @@ UPGRADE FROM 2.0 to 2.1
and/or share a common base configuration (i.e. ``config.yml``), merging
could yield a set of base URL's for multiple environments.
+### [HttpFoundation]
+
* moved management of the locale from the Session class to the Request class
Configuring the default locale:
@@ -28,17 +32,20 @@ UPGRADE FROM 2.0 to 2.1
Retrieving the locale from a Twig template:
- Before: `{{ app.request.session.locale }}` or `{{ app.session.locale }}`
+ Before: `{{ app.request.session.locale }}` or `{{ app.session.locale }}`
+
After: `{{ app.request.locale }}`
Retrieving the locale from a PHP template:
- Before: `$view['session']->getLocale()`
+ Before: `$view['session']->getLocale()`
+
After: `$view['request']->getLocale()`
Retrieving the locale from PHP code:
- Before: `$session->getLocale()`
+ Before: `$session->getLocale()`
+
After: `$request->getLocale()`
* Method `equals` of `Symfony\Component\Security\Core\User\UserInterface` has
@@ -134,7 +141,7 @@ UPGRADE FROM 2.0 to 2.1
* The strategy for generating the HTML attributes "id" and "name"
of choices in a choice field has changed
-
+
Instead of appending the choice value, a generated integer is now appended
by default. Take care if your Javascript relies on that. If you can
guarantee that your choice values only contain ASCII letters, digits,
@@ -144,7 +151,7 @@ UPGRADE FROM 2.0 to 2.1
* The strategy for generating the HTML attributes "value" of choices in a
choice field has changed
-
+
Instead of using the choice value, a generated integer is now stored.
Again, take care if your Javascript reads this value. If your choice field
is a non-expanded single-choice field, or if the choices are guaranteed not
@@ -248,3 +255,63 @@ UPGRADE FROM 2.0 to 2.1
{
return isset($options['widget']) && 'single_text' === $options['widget'] ? 'text' : 'choice';
}
+
+* Flash Messages now returns and array based on type (the old method are still available but deprecated)
+
+ Before (PHP):
+
+ <?php if ($view['session']->hasFlash('notice')): ?>
+ <div class="flash-notice">
+ <?php echo $view['session']->getFlash('notice') ?>
+ </div>
+ <?php endif; ?>
+
+ After (PHP):
+
+ <?php if ($view['session']->getFlashBag()->has('notice')): ?>
+ <div class="flash-notice">
+ <?php echo $view['session']->getFlashBag()->get('notice') ?>
+ </div>
+ <?php endif; ?>
+
+ If you wanted to process all flash types you could also make use of the `getFlashBag()->all()` API:
+
+ <?php foreach ($view['session']->getFlashBag()->all() as $type => $flash): ?>
+ <div class="flash-$type">
+ <?php echo $flash; ?>
+ </div>
+ <?php endforeach; ?>
+
+ Before (Twig):
+
+ {% if app.session.hasFlash('notice') %}
+ <div class="flash-notice">
+ {{ app.session.flash('notice') }}
+ </div>
+ {% endif %}
+
+ After (Twig):
+
+ {% if app.session.flashes.has('notice') %}
+ <div class="flash-notice">
+ {{ app.session.flashes.get('notice') }}
+ </div>
+ {% endif %}
+
+ Again you can process all flash messages in one go with
+
+ {% for type, flashMessage in app.session.flashes.all() %}
+ <div class="flash-{{ type }}">
+ {{ flashMessage }}
+ </div>
+ {% endforeach %}
+
+* Session storage drivers
+
+ Session storage drivers should inherit from
+ `Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage`
+ and no longer should implement `read()`, `write()`, `remove()` which were removed from the
+ `SessionStorageInterface`.
+
+ Any session storage driver that wants to use custom save handlers should
+ implement `Symfony\Component\HttpFoundation\Session\Storage\SaveHandlerInterface`
View
58 src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionStorage.php
@@ -3,7 +3,8 @@
namespace Symfony\Bridge\Doctrine\HttpFoundation;
use Doctrine\DBAL\Platforms\MySqlPlatform;
-use Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage;
+use Symfony\Component\HttpFoundation\Session\Storage\AbstractSessionStorage;
+use Symfony\Component\HttpFoundation\Session\Storage\SessionSaveHandlerInterface;
use Doctrine\DBAL\Driver\Connection;
/**
@@ -12,39 +13,30 @@
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
-class DbalSessionStorage extends NativeSessionStorage
+class DbalSessionStorage extends AbstractSessionStorage implements SessionSaveHandlerInterface
{
+ /**
+ * @var Connection
+ */
private $con;
+
+ /**
+ * @var string
+ */
private $tableName;
+ /**
+ *
+ * @param Connection $con An instance of Connection.
+ * @param string $tableName Table name.
+ * @param array $options Session configuration options
+ */
public function __construct(Connection $con, $tableName = 'sessions', array $options = array())
{
- parent::__construct($options);
-
$this->con = $con;
$this->tableName = $tableName;
- }
- /**
- * 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();
+ parent::__construct($options);
}
/**
@@ -55,7 +47,7 @@ public function start()
*
* @return Boolean true, if the session was opened, otherwise an exception is thrown
*/
- public function sessionOpen($path = null, $name = null)
+ public function openSession($path = null, $name = null)
{
return true;
}
@@ -65,7 +57,7 @@ public function sessionOpen($path = null, $name = null)
*
* @return Boolean true, if the session was closed, otherwise false
*/
- public function sessionClose()
+ public function closeSession()
{
// do nothing
return true;
@@ -80,7 +72,7 @@ public function sessionClose()
*
* @throws \RuntimeException If the session cannot be destroyed
*/
- public function sessionDestroy($id)
+ public function destroySession($id)
{
try {
$this->con->executeQuery("DELETE FROM {$this->tableName} WHERE sess_id = :id", array(
@@ -102,7 +94,7 @@ public function sessionDestroy($id)
*
* @throws \RuntimeException If any old sessions cannot be cleaned
*/
- public function sessionGC($lifetime)
+ public function gcSession($lifetime)
{
try {
$this->con->executeQuery("DELETE FROM {$this->tableName} WHERE sess_time < :time", array(
@@ -124,7 +116,7 @@ public function sessionGC($lifetime)
*
* @throws \RuntimeException If the session cannot be read
*/
- public function sessionRead($id)
+ public function readSession($id)
{
try {
$data = $this->con->executeQuery("SELECT sess_data FROM {$this->tableName} WHERE sess_id = :id", array(
@@ -140,7 +132,7 @@ public function sessionRead($id)
return '';
} catch (\PDOException $e) {
- throw new \RuntimeException(sprintf('PDOException was thrown when trying to manipulate session data: %s', $e->getMessage()), 0, $e);
+ throw new \RuntimeException(sprintf('PDOException was thrown when trying to read the session data: %s', $e->getMessage()), 0, $e);
}
}
@@ -154,7 +146,7 @@ public function sessionRead($id)
*
* @throws \RuntimeException If the session data cannot be written
*/
- public function sessionWrite($id, $data)
+ public function writeSession($id, $data)
{
$platform = $this->con->getDatabasePlatform();
@@ -181,7 +173,7 @@ public function sessionWrite($id, $data)
$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);
+ throw new \RuntimeException(sprintf('PDOException was thrown when trying to write the session data: %s', $e->getMessage()), 0, $e);
}
return true;
View
2 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -167,7 +167,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
->canBeUnset()
->children()
->booleanNode('auto_start')->defaultFalse()->end()
- ->scalarNode('storage_id')->defaultValue('session.storage.native')->end()
+ ->scalarNode('storage_id')->defaultValue('session.storage.native_file')->end()
->scalarNode('name')->end()
->scalarNode('lifetime')->end()
->scalarNode('path')->end()
View
2 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -301,7 +301,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
$this->addClassesToCompile(array(
'Symfony\\Bundle\\FrameworkBundle\\EventListener\\SessionListener',
- 'Symfony\\Component\\HttpFoundation\\SessionStorage\\SessionStorageInterface',
+ 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorageInterface',
$container->getDefinition('session')->getClass(),
));
View
1 src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php
@@ -69,7 +69,6 @@ public function onKernelResponse(FilterResponseEvent $event)
if ($session = $event->getRequest()->getSession()) {
$session->save();
- $session->close();
$params = session_get_cookie_params();
View
23 src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml
@@ -5,22 +5,31 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
- <parameter key="session.class">Symfony\Component\HttpFoundation\Session</parameter>
- <parameter key="session.storage.native.class">Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage</parameter>
- <parameter key="session.storage.filesystem.class">Symfony\Component\HttpFoundation\SessionStorage\FilesystemSessionStorage</parameter>
+ <parameter key="session.class">Symfony\Component\HttpFoundation\Session\Session</parameter>
+ <parameter key="session.flashbag.class">Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag</parameter>
+ <parameter key="session.attribute_bag.class">Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag</parameter>
+ <parameter key="session.storage.native_file.class">Symfony\Component\HttpFoundation\Session\Storage\NativeFileSessionStorage</parameter>
+ <parameter key="session.storage.mock_file.class">Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage</parameter>
<parameter key="session_listener.class">Symfony\Bundle\FrameworkBundle\EventListener\SessionListener</parameter>
</parameters>
<services>
<service id="session" class="%session.class%">
<argument type="service" id="session.storage" />
+ <argument type="service" id="session.attribute_bag" />
+ <argument type="service" id="session.flash_bag" />
</service>
- <service id="session.storage.native" class="%session.storage.native.class%" public="false">
+ <service id="session.flash_bag" class="%session.flashbag.class%" public="false" />
+
+ <service id="session.attribute_bag" class="%session.attribute_bag.class%" public="false" />
+
+ <service id="session.storage.mock_file" class="%session.storage.mock_file.class%" public="false">
+ <argument>%kernel.cache_dir%/sessions</argument>
<argument>%session.storage.options%</argument>
</service>
- <service id="session.storage.filesystem" class="%session.storage.filesystem.class%" public="false">
+ <service id="session.storage.native_file" class="%session.storage.native_file.class%" public="false">
<argument>%kernel.cache_dir%/sessions</argument>
<argument>%session.storage.options%</argument>
</service>
@@ -29,5 +38,9 @@
<tag name="kernel.event_subscriber" />
<argument type="service" id="service_container" />
</service>
+
+ <!-- for BC -->
+ <service id="session.storage.native" alias="session.storage.native_file" />
+ <service id="session.storage.filesystem" alias="session.storage.mock_file" />
</services>
</container>
View
2 src/Symfony/Bundle/FrameworkBundle/Templating/GlobalVariables.php
@@ -79,7 +79,7 @@ public function getRequest()
/**
* Returns the current session.
*
- * @return Symfony\Component\HttpFoundation\Session|void The session
+ * @return Symfony\Component\HttpFoundation\Session\Session|void The session
*/
public function getSession()
{
View
6 src/Symfony/Bundle/FrameworkBundle/Templating/Helper/SessionHelper.php
@@ -48,17 +48,17 @@ public function get($name, $default = null)
public function getFlash($name, $default = null)
{
- return $this->session->getFlash($name, $default);
+ return $this->session->getFlashBag()->get($name);
}
public function getFlashes()
{
- return $this->session->getFlashes();
+ return $this->session->getFlashBag()->all();
}
public function hasFlash($name)
{
- return $this->session->hasFlash($name);
+ return $this->session->getFlashBag()->has($name);
}
/**
View
2 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php
@@ -20,7 +20,7 @@
),
'session' => array(
'auto_start' => true,
- 'storage_id' => 'session.storage.native',
+ 'storage_id' => 'session.storage.native_file',
'name' => '_SYMFONY',
'lifetime' => 86400,
'path' => '/',
View
2 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
@@ -12,7 +12,7 @@
<framework:esi enabled="true" />
<framework:profiler only-exceptions="true" />
<framework:router resource="%kernel.root_dir%/config/routing.xml" type="xml" />
- <framework:session auto-start="true" storage-id="session.storage.native" name="_SYMFONY" lifetime="86400" path="/" domain="example.com" secure="true" httponly="true" />
+ <framework:session auto-start="true" storage-id="session.storage.native_file" name="_SYMFONY" lifetime="86400" path="/" domain="example.com" secure="true" httponly="true" />
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" >
<framework:loader>loader.foo</framework:loader>
<framework:loader>loader.bar</framework:loader>
View
2 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
@@ -14,7 +14,7 @@ framework:
type: xml
session:
auto_start: true
- storage_id: session.storage.native
+ storage_id: session.storage.native_file
name: _SYMFONY
lifetime: 86400
path: /
View
2 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
@@ -78,7 +78,7 @@ public function testSession()
$this->assertTrue($container->hasDefinition('session'), '->registerSessionConfiguration() loads session.xml');
$this->assertEquals('fr', $container->getParameter('kernel.default_locale'));
$this->assertTrue($container->getDefinition('session_listener')->getArgument(1));
- $this->assertEquals('session.storage.native', (string) $container->getAlias('session.storage'));
+ $this->assertEquals('session.storage.native_file', (string) $container->getAlias('session.storage'));
$options = $container->getParameter('session.storage.options');
$this->assertEquals('_SYMFONY', $options['name']);
View
2 src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/TestSessionListenerTest.php
@@ -94,7 +94,7 @@ private function sessionMustBeSaved()
private function getSession()
{
- return $this->getMockBuilder('Symfony\Component\HttpFoundation\Session')
+ return $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')
->disableOriginalConstructor()
->getMock();
}
View
6 ...undle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SessionController.php
@@ -51,7 +51,7 @@ public function setFlashAction($message)
{
$request = $this->container->get('request');
$session = $request->getSession();
- $session->setFlash('notice', $message);
+ $session->getFlashBag()->set('notice', $message);
return new RedirectResponse($this->container->get('router')->generate('session_showflash'));
}
@@ -61,8 +61,8 @@ public function showFlashAction()
$request = $this->container->get('request');
$session = $request->getSession();
- if ($session->hasFlash('notice')) {
- $output = $session->getFlash('notice');
+ if ($session->getFlashBag()->has('notice')) {
+ $output = $session->getFlashBag()->get('notice');
} else {
$output = 'No flash was set.';
}
View
2 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml
@@ -10,7 +10,7 @@ framework:
default_locale: en
session:
auto_start: true
- storage_id: session.storage.filesystem
+ storage_id: session.storage.mock_file
services:
logger: { class: Symfony\Component\HttpKernel\Log\NullLogger }
View
21 src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/SessionHelperTest.php
@@ -12,8 +12,8 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper;
use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Session;
-use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage;
+use Symfony\Component\HttpFoundation\Session\Session;
+use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Bundle\FrameworkBundle\Templating\Helper\SessionHelper;
class SessionHelperTest extends \PHPUnit_Framework_TestCase
@@ -24,9 +24,9 @@ public function setUp()
{
$this->request = new Request();
- $session = new Session(new ArraySessionStorage());
+ $session = new Session(new MockArraySessionStorage());
$session->set('foobar', 'bar');
- $session->setFlash('foo', 'bar');
+ $session->getFlashBag()->set('notice', 'bar');
$this->request->setSession($session);
}
@@ -40,14 +40,15 @@ public function testFlash()
{
$helper = new SessionHelper($this->request);
- $this->assertTrue($helper->hasFlash('foo'));
+ $this->assertTrue($helper->hasFlash('notice'));
- $this->assertEquals('bar', $helper->getFlash('foo'));
- $this->assertEquals('foo', $helper->getFlash('bar', 'foo'));
-
- $this->assertNull($helper->getFlash('foobar'));
+ $this->assertEquals('bar', $helper->getFlash('notice'));
+ }
- $this->assertEquals(array('foo' => 'bar'), $helper->getFlashes());
+ public function testGetFlashes()
+ {
+ $helper = new SessionHelper($this->request);
+ $this->assertEquals(array('notice' => 'bar'), $helper->getFlashes());
}
public function testGet()
View
6 src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php
@@ -14,8 +14,8 @@
use Symfony\Bundle\FrameworkBundle\Templating\PhpEngine;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Session;
-use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage;
+use Symfony\Component\HttpFoundation\Session\Session;
+use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\Templating\TemplateNameParser;
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
@@ -64,7 +64,7 @@ protected function getContainer()
{
$container = new Container();
$request = new Request();
- $session = new Session(new ArraySessionStorage());
+ $session = new Session(new MockArraySessionStorage());
$request->setSession($session);
$container->set('request', $request);
View
2 src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/config/framework.yml
@@ -10,7 +10,7 @@ framework:
default_locale: en
session:
auto_start: true
- storage_id: session.storage.filesystem
+ storage_id: session.storage.mock_file
services:
logger: { class: Symfony\Component\HttpKernel\Log\NullLogger }
View
6 src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php
@@ -14,8 +14,8 @@
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Session;
-use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage;
+use Symfony\Component\HttpFoundation\Session\Session;
+use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\Templating\TemplateNameParser;
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
@@ -71,7 +71,7 @@ protected function getContainer()
{
$container = new Container();
$request = new Request();
- $session = new Session(new ArraySessionStorage());
+ $session = new Session(new MockArraySessionStorage());
$request->setSession($session);
$container->set('request', $request);
View
7 src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php
@@ -15,6 +15,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
/**
* ProfilerController.
@@ -146,9 +147,9 @@ public function toolbarAction($token, $position = null)
{
$request = $this->container->get('request');
- if (null !== $session = $request->getSession()) {
- // keep current flashes for one more request
- $session->setFlashes($session->getFlashes());
+ if (null !== $session = $request->getSession() && $session->getFlashBag() instanceof AutoExpireFlashBag) {
+ // keep current flashes for one more request if using AutoExpireFlashBag
+ $session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
}
if (null === $token) {
View
8 src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php
@@ -15,6 +15,7 @@
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Bundle\TwigBundle\TwigEngine;
+use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
/**
* WebDebugToolbarListener injects the Web Debug Toolbar.
@@ -70,9 +71,10 @@ public function onKernelResponse(FilterResponseEvent $event)
}
if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
- if (null !== $session = $request->getSession()) {
- // keep current flashes for one more request
- $session->setFlashes($session->getFlashes());
+ $session = $request->getSession();
+ if ($session->getFlashBag() instanceof AutoExpireFlashBag) {
+ // keep current flashes for one more request if using AutoExpireFlashBag
+ $session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
}
$response->setContent($this->templating->render('WebProfilerBundle:Profiler:toolbar_redirect.html.twig', array('location' => $response->headers->get('Location'))));
View
2 src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php
@@ -177,7 +177,7 @@ public function testToolbarIsNotInjectedOnNonHtmlRequests()
protected function getRequestMock($isXmlHttpRequest = false, $requestFormat = 'html')
{
- $session = $this->getMock('Symfony\Component\HttpFoundation\Session', array(), array(), '', false);
+ $session = $this->getMock('Symfony\Component\HttpFoundation\Session\Session', array(), array(), '', false);
$request = $this->getMock(
'Symfony\Component\HttpFoundation\Request',
array('getSession', 'isXmlHttpRequest', 'getRequestFormat'),
View
2 src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/SessionCsrfProvider.php
@@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Extension\Csrf\CsrfProvider;
-use Symfony\Component\HttpFoundation\Session;
+use Symfony\Component\HttpFoundation\Session\Session;
/**
* This provider uses a Symfony2 Session object to retrieve the user's
View
10 src/Symfony/Component/HttpFoundation/Request.php
@@ -11,6 +11,8 @@
namespace Symfony\Component\HttpFoundation;
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+
/**
* Request represents an HTTP request.
*
@@ -122,7 +124,7 @@ class Request
protected $format;
/**
- * @var \Symfony\Component\HttpFoundation\Session
+ * @var \Symfony\Component\HttpFoundation\Session\SessionInterface
*/
protected $session;
@@ -466,7 +468,7 @@ public function get($key, $default = null, $deep = false)
/**
* Gets the Session.
*
- * @return Session|null The session
+ * @return SessionInterface|null The session
*
* @api
*/
@@ -504,11 +506,11 @@ public function hasSession()
/**
* Sets the Session.
*
- * @param Session $session The Session
+ * @param SessionInterface $session The Session
*
* @api
*/
- public function setSession(Session $session)
+ public function setSession(SessionInterface $session)
{
$this->session = $session;
}
View
358 src/Symfony/Component/HttpFoundation/Session.php
@@ -1,358 +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;
-
-use Symfony\Component\HttpFoundation\SessionStorage\SessionStorageInterface;
-
-/**
- * Session.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- *
- * @api
- */
-class Session implements \Serializable
-{
- protected $storage;
- protected $started;
- protected $attributes;
- protected $flashes;
- protected $oldFlashes;
- protected $closed;
-
- /**
- * Constructor.
- *
- * @param SessionStorageInterface $storage A SessionStorageInterface instance
- */
- public function __construct(SessionStorageInterface $storage)
- {
- $this->storage = $storage;
- $this->flashes = array();
- $this->oldFlashes = array();
- $this->attributes = array();
- $this->started = false;
- $this->closed = false;
- }
-
- /**
- * Starts the session storage.
- *
- * @api
- */
- public function start()
- {
- if (true === $this->started) {
- return;
- }
-
- $this->storage->start();
-
- $attributes = $this->storage->read('_symfony2');
-
- if (isset($attributes['attributes'])) {
- $this->attributes = $attributes['attributes'];
- $this->flashes = $attributes['flashes'];
-
- // flag current flash messages to be removed at shutdown
- $this->oldFlashes = $this->flashes;
- }
-
- $this->started = true;
- }
-
- /**
- * Checks if an attribute is defined.
- *
- * @param string $name The attribute name
- *
- * @return Boolean true if the attribute is defined, false otherwise
- *
- * @api
- */
- public function has($name)
- {
- return array_key_exists($name, $this->attributes);
- }
-
- /**
- * Returns an attribute.
- *
- * @param string $name The attribute name
- * @param mixed $default The default value
- *
- * @return mixed
- *
- * @api
- */
- public function get($name, $default = null)
- {
- return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
- }
-
- /**
- * Sets an attribute.
- *
- * @param string $name
- * @param mixed $value
- *
- * @api
- */
- public function set($name, $value)
- {
- if (false === $this->started) {
- $this->start();
- }
-
- $this->attributes[$name] = $value;
- }
-
- /**
- * Returns attributes.
- *
- * @return array Attributes
- *
- * @api
- */
- public function all()
- {
- return $this->attributes;
- }
-
- /**
- * Sets attributes.
- *
- * @param array $attributes Attributes
- *
- * @api
- */
- public function replace(array $attributes)
- {
- if (false === $this->started) {
- $this->start();
- }
-
- $this->attributes = $attributes;
- }
-
- /**
- * Removes an attribute.
- *
- * @param string $name
- *
- * @api
- */
- public function remove($name)
- {
- if (false === $this->started) {
- $this->start();
- }
-
- if (array_key_exists($name, $this->attributes)) {
- unset($this->attributes[$name]);
- }
- }
-
- /**
- * Clears all attributes.
- *
- * @api
- */
- public function clear()
- {
- if (false === $this->started) {
- $this->start();
- }
-
- $this->attributes = array();
- $this->flashes = array();
- }
-
- /**
- * Invalidates the current session.
- *
- * @api
- */
- public function invalidate()
- {
- $this->clear();
- $this->storage->regenerate(true);
- }
-
- /**
- * Migrates the current session to a new session id while maintaining all
- * session attributes.
- *
- * @api
- */
- public function migrate()
- {
- $this->storage->regenerate();
- }
-
- /**
- * Returns the session ID
- *
- * @return mixed The session ID
- *
- * @api
- */
- public function getId()
- {
- if (false === $this->started) {
- $this->start();
- }
-
- return $this->storage->getId();
- }
-
- /**
- * Gets the flash messages.
- *
- * @return array
- */
- public function getFlashes()
- {
- return $this->flashes;
- }
-
- /**
- * Sets the flash messages.
- *
- * @param array $values
- */
- public function setFlashes($values)
- {
- if (false === $this->started) {
- $this->start();
- }
-
- $this->flashes = $values;
- $this->oldFlashes = array();
- }
-
- /**
- * Gets a flash message.
- *
- * @param string $name
- * @param string|null $default
- *
- * @return string
- */
- public function getFlash($name, $default = null)
- {
- return array_key_exists($name, $this->flashes) ? $this->flashes[$name] : $default;
- }
-
- /**
- * Sets a flash message.
- *
- * @param string $name
- * @param string $value
- */
- public function setFlash($name, $value)
- {
- if (false === $this->started) {
- $this->start();
- }
-
- $this->flashes[$name] = $value;
- unset($this->oldFlashes[$name]);
- }
-
- /**
- * Checks whether a flash message exists.
- *
- * @param string $name
- *
- * @return Boolean
- */
- public function hasFlash($name)
- {
- if (false === $this->started) {
- $this->start();
- }
-
- return array_key_exists($name, $this->flashes);
- }
-
- /**
- * Removes a flash message.
- *
- * @param string $name
- */
- public function removeFlash($name)
- {
- if (false === $this->started) {
- $this->start();
- }
-
- unset($this->flashes[$name]);
- }
-
- /**
- * Removes the flash messages.
- */
- public function clearFlashes()
- {
- if (false === $this->started) {
- $this->start();
- }
-
- $this->flashes = array();
- $this->oldFlashes = array();
- }
-
- public function save()
- {
- if (false === $this->started) {
- $this->start();
- }
-
- $this->flashes = array_diff_key($this->flashes, $this->oldFlashes);
-
- $this->storage->write('_symfony2', array(
- 'attributes' => $this->attributes,
- 'flashes' => $this->flashes,
- ));
- }
-
- /**
- * This method should be called when you don't want the session to be saved
- * when the Session object is garbaged collected (useful for instance when
- * you want to simulate the interaction of several users/sessions in a single
- * PHP process).
- */
- public function close()
- {
- $this->closed = true;
- }
-
- public function __destruct()
- {
- if (true === $this->started && !$this->closed) {
- $this->save();
- }
- }
-
- public function serialize()
- {
- return serialize($this->storage);
- }
-
- public function unserialize($serialized)
- {
- $this->storage = unserialize($serialized);
- $this->attributes = array();
- $this->started = false;
- }
-}
View
137 src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBag.php
@@ -0,0 +1,137 @@
+<?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\Session\Attribute;
+
+/**
+ * This class relates to session attribute storage
+ */
+class AttributeBag implements AttributeBagInterface
+{
+ private $name = 'attributes';
+
+ /**
+ * @var string
+ */
+ private $storageKey;
+
+ /**
+ * @var array
+ */
+ protected $attributes = array();
+
+ /**
+ * Constructor.
+ *
+ * @param type $storageKey The key used to store flashes in the session.
+ */
+ public function __construct($storageKey = '_sf2_attributes')
+ {
+ $this->storageKey = $storageKey;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function initialize(array &$attributes)
+ {
+ $this->attributes = &$attributes;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getStorageKey()
+ {
+ return $this->storageKey;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function has($name)
+ {
+ return array_key_exists($name, $this->attributes);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get($name, $default = null)
+ {
+ return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set($name, $value)
+ {
+ $this->attributes[$name] = $value;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function all()
+ {
+ return $this->attributes;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function replace(array $attributes)
+ {
+ $this->attributes = array();
+ foreach ($attributes as $key => $value) {
+ $this->set($key, $value);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function remove($name)
+ {
+ $retval = null;
+ if (array_key_exists($name, $this->attributes)) {
+ $retval = $this->attributes[$name];
+ unset($this->attributes[$name]);
+ }
+
+ return $retval;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function clear()
+ {
+ $return = $this->attributes;
+ $this->attributes = array();
+
+ return $return;
+ }
+}
View
70 src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBagInterface.php
@@ -0,0 +1,70 @@
+<?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\Session\Attribute;
+
+use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
+
+/**
+ * Attributes store.
+ *
+ * @author Drak <drak@zikula.org>
+ */
+interface AttributeBagInterface extends SessionBagInterface
+{
+ /**
+ * 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);
+}
View
184 src/Symfony/Component/HttpFoundation/Session/Attribute/NamespacedAttributeBag.php
@@ -0,0 +1,184 @@
+<?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\Session\Attribute;
+
+/**
+ * This class provides structured storage of session attributes using
+ * a name spacing character in the key.
+ *
+ * @author Drak <drak@zikula.org>
+ */
+class NamespacedAttributeBag extends AttributeBag
+{
+ /**
+ * Namespace character.
+ *
+ * @var string
+ */
+ private $namespaceCharacter;
+
+ /**
+ * Constructor.
+ *
+ * @param type $storageKey Session storage key.
+ * @param type $namespaceCharacter Namespace character to use in keys.
+ */
+ public function __construct($storageKey = '_sf2_attributes', $namespaceCharacter = '/')
+ {
+ $this->namespaceCharacter = $namespaceCharacter;
+ parent::__construct($storageKey);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function has($name)
+ {
+ $attributes = $this->resolveAttributePath($name);
+ $name = $this->resolveKey($name);
+
+ return array_key_exists($name, $attributes);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get($name, $default = null)
+ {
+ $attributes = $this->resolveAttributePath($name);
+ $name = $this->resolveKey($name);
+
+ return array_key_exists($name, $attributes) ? $attributes[$name] : $default;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set($name, $value)
+ {
+ $attributes = & $this->resolveAttributePath($name, true);
+ $name = $this->resolveKey($name);
+ $attributes[$name] = $value;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function all()
+ {
+ return $this->attributes;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function replace(array $attributes)
+ {
+ $this->attributes = array();
+ foreach ($attributes as $key => $value) {
+ $this->set($key, $value);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function remove($name)
+ {
+ $retval = null;
+ $attributes = & $this->resolveAttributePath($name);
+ $name = $this->resolveKey($name);
+ if (array_key_exists($name, $attributes)) {
+ $retval = $attributes[$name];
+ unset($attributes[$name]);
+ }
+
+ return $retval;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function clear()
+ {
+ $return = $this->attributes;
+ $this->attributes = array();
+
+ return $return;
+ }
+
+ /**
+ * Resolves a path in attributes property and returns it as a reference.
+ *
+ * This method allows structured namespacing of session attributes.
+ *
+ * @param string $name Key name
+ * @param boolean $writeContext Write context, default false
+ *
+ * @return array
+ */
+ protected function &resolveAttributePath($name, $writeContext = false)
+ {
+ $array = & $this->attributes;
+ $name = (strpos($name, $this->namespaceCharacter) === 0) ? substr($name, 1) : $name;
+
+ // Check if there is anything to do, else return
+ if (!$name) {
+ return $array;
+ }
+
+ $parts = explode($this->namespaceCharacter, $name);
+ if (count($parts) < 2) {
+ if (!$writeContext) {
+ return $array;
+ }
+
+ $array[$parts[0]] = array();
+
+ return $array;
+ }
+
+ unset($parts[count($parts)-1]);
+
+ foreach ($parts as $part) {
+ if (!array_key_exists($part, $array)) {
+ if (!$writeContext) {
+ return $array;
+ }
+
+ $array[$part] = array();
+ }
+
+ $array = & $array[$part];
+ }
+
+ return $array;
+ }
+
+ /**
+ * Resolves the key from the name.
+ *
+ * This is the last part in a dot separated string.
+ *
+ * @param string $name
+ *
+ * @return string
+ */
+ protected function resolveKey($name)
+ {
+ if (strpos($name, $this->namespaceCharacter) !== false) {
+ $name = substr($name, strrpos($name, $this->namespaceCharacter)+1, strlen($name));
+ }
+
+ return $name;
+ }
+}
View
174 src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php
@@ -0,0 +1,174 @@
+<?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\Session\Flash;
+
+/**
+ * AutoExpireFlashBag flash message container.
+ *
+ * @author Drak <drak@zikula.org>
+ */
+class AutoExpireFlashBag implements FlashBagInterface
+{
+ private $name = 'flashes';
+
+ /**
+ * Flash messages.
+ *
+ * @var array
+ */
+ private $flashes = array();
+
+ /**
+ * The storage key for flashes in the session
+ *
+ * @var string
+ */
+ private $storageKey;
+
+ /**
+ * Constructor.
+ *
+ * @param type $storageKey The key used to store flashes in the session.
+ */
+ public function __construct($storageKey = '_sf2_flashes')
+ {
+ $this->storageKey = $storageKey;
+ $this->flashes = array('display' => array(), 'new' => array());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function initialize(array &$flashes)
+ {
+ $this->flashes = &$flashes;
+
+ // The logic: messages from the last request will be stored in new, so we move them to previous
+ // This request we will show what is in 'display'. What is placed into 'new' this time round will
+ // be moved to display next time round.
+ $this->flashes['display'] = array_key_exists('new', $this->flashes) ? $this->flashes['new'] : array();
+ $this->flashes['new'] = array();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function peek($type, $default = null)
+ {
+ return $this->has($type) ? $this->flashes['display'][$type] : $default;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function peekAll()
+ {
+ return array_key_exists('display', $this->flashes) ? (array)$this->flashes['display'] : array();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get($type, $default = null)
+ {
+ if (!$this->has($type)) {
+ return $default;
+ }
+
+ $return = null;
+ if (isset($this->flashes['new'][$type])) {
+ unset($this->flashes['new'][$type]);
+ }
+
+ if (isset($this->flashes['display'][$type])) {
+ $return = $this->flashes['display'][$type];
+ unset($this->flashes['display'][$type]);
+ }
+
+ return $return;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function all()
+ {
+ $return = $this->flashes['display'];
+ $this->flashes = array('new' => array(), 'display' => array());
+
+ return $return;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setAll(array $messages)
+ {
+ $this->flashes['new'] = $messages;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set($type, $message)
+ {
+ $this->flashes['new'][$type] = $message;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function has($type)
+ {
+ return array_key_exists($type, $this->flashes['display']);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function keys()
+ {
+ return array_keys($this->flashes['display']);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getStorageKey()
+ {
+ return $this->storageKey;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function clear()
+ {
+ $return = $this->all();
+ $this->flashes = array('display' => array(), 'new' => array());
+
+ return $return;
+ }
+}
View
158 src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php
@@ -0,0 +1,158 @@
+<?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\Session\Flash;
+
+/**
+ * FlashBag flash message container.
+ *
+ * @author Drak <drak@zikula.org>
+ */
+class FlashBag implements FlashBagInterface
+{
+ private $name = 'flashes';
+
+ /**
+ * Flash messages.
+ *
+ * @var array
+ */
+ private $flashes = array();
+
+ /**
+ * The storage key for flashes in the session
+ *
+ * @var string
+ */
+ private $storageKey;
+
+ /**
+ * Constructor.
+ *
+ * @param type $storageKey The key used to store flashes in the session.
+ */
+ public function __construct($storageKey = '_sf2_flashes')
+ {
+ $this->storageKey = $storageKey;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function initialize(array &$flashes)
+ {
+ $this->flashes = &$flashes;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function peek($type, $default = null)
+ {
+ return $this->has($type) ? $this->flashes[$type] : $default;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function peekAll()
+ {
+ return $this->flashes;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get($type, $default = null)
+ {
+ if (!$this->has($type)) {
+ return $default;
+ }
+
+ $return = $this->flashes[$type];
+
+ unset($this->flashes[$type]);
+
+ return $return;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function all()
+ {
+ $return = $this->peekAll();
+ $this->flashes = array();
+
+ return $return;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function set($type, $message)
+ {
+ $this->flashes[$type] = $message;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setAll(array $messages)
+ {
+ $this->flashes = $messages;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function has($type)
+ {
+ return array_key_exists($type, $this->flashes);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function keys()
+ {
+ return array_keys($this->flashes);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getStorageKey()
+ {
+ return $this->storageKey;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function clear()
+ {
+ return $this->all();
+ }
+}
View
85 src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php
@@ -0,0 +1,85 @@
+<?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\Session\Flash;
+
+use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
+
+/**
+ * FlashBagInterface.
+ *
+ * @author Drak <drak@zikula.org>
+ */
+interface FlashBagInterface extends SessionBagInterface
+{
+ /**
+ * Registers a message for a given type.
+ *
+ * @param string $type
+ * @param string $message
+ */