symfony/symfony — pull request #2714 by drak (2011-11-24 11:30:00+00:00)
Title: [WIP][HttpFoundation] Fix session handling, session storage, drivers and improved flash messages

__THIS IS A WORK IN PROGRESS, SUBMITTED NOW FOR RFC__

I'm submitting this PR now to get some review and maybe some testing feedback. It's nearly complete but definitely in WIP status. This PR contains both bug fixes and features.

Bug fix: yes
Feature addition: yes
Backwards compatibility break: yes
Symfony2 tests pass: yes
Fixes the following tickets: #2607, #2591
References the following tickets: #2592, #2541
Todo: Unify exceptions, documentation, decide on namespacing character, review unit tests, make changes to symfony-standard's `config.yml` for `PDOSessionStorage` driver, complete `sessionGc()` in `FilesystemSessionStorage`

Because of the complexity of the changes I have opted to merge in #2592 and #2541. I will summarise the changes here although the main reasoning for the session management changes is explained in #2607.

__SessionInterface__

Session now implements `SessionInterface` making the session object more portable and customisable.

__Session Save Handlers__

Introduced a special `SessionSaveHandlerInterface` and `AbstractSessionStorage` to make the job of custom session save handling more easy.

__$_SESSION__

Please note that there is some use of `$_SESSION` here. This is intentional and not avoidable. Session handling cannot abstract away the `$_SESSION` superglobal. There is no such thing/concept as "native" session management which uses `$_SESSION` and custom session handling which doesn't. The only difference between PHP's internal session management and the custom handlers we can define are the "save handlers" referenced in #2607.

__Flash Messages__ [BC Break]

This has been outsourced to a FlashBagInterface and now implements a bucket system so we can have multiple messages in multiple categories. The clearing of flash messages is now done when they are used as opposed to automatically. This resolves some chicken and egg issues in #2607.

The flash-message API has been removed from the `Session` interface. We could add them back as they would just be a proxy to the `FlashBag`.

__Session attribute namespacing__

Attribute keys like `user.foo.bar` are now stored in a structured array as explained in #2592 but this time there is no extra $namespace parameter, we're just using the `.` as a namespacer. We could change that to `/` so that keys would only be stored in a structured array if there is a `/`, e.g. `user.token/a`, or we could just have a separate `$namespace` parameter.

__Memcache/Memcached storage support__

I have added support for memcache and memcache__d__ both using PHP native handlers and using custom save handlers.