Commit ef60bc96 authored by Fabien Potencier's avatar Fabien Potencier

merged branch igorw/session-update (PR #266)

Commits
-------

ee1793c7 [session-update] bring vendors up to date
77429a59 [session-update] Update all docs references to 2.1
dbc55d25 [session-update] add note to CHANGELOG
143ca105 [session-update] update to 2.1 session refactoring

Discussion
----------

Session update
parents d230b294 ee1793c7
......@@ -3,6 +3,8 @@ Changelog
This changelog references all backward incompatibilities as we introduce them:
* **2012-02-27**: Updated to Symfony 2.1 session handling.
* **2012-01-02**: Introduced support for streaming responses.
* **2011-09-22**: ``ExtensionInterface`` has been renamed to
......
......@@ -12,11 +12,11 @@ Application
The application is the main interface to Silex. It
implements Symfony2's `HttpKernelInterface
<http://api.symfony.com/2.0/Symfony/Component/HttpKernel/HttpKernelInterface.html>`_,
<http://api.symfony.com/master/Symfony/Component/HttpKernel/HttpKernelInterface.html>`_,
so you can pass a `Request
<http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Request.html>`_
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Request.html>`_
to the ``handle`` method and it will return a `Response
<http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Response.html>`_.
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Response.html>`_.
It extends the ``Pimple`` service container, allowing
for flexibility on the outside as well as the inside. you
......@@ -24,9 +24,9 @@ could replace any service, and you are also able to read
them.
The application makes strong use of the `EventDispatcher
<http://api.symfony.com/2.0/Symfony/Component/EventDispatcher/EventDispatcher.html>`_
<http://api.symfony.com/master/Symfony/Component/EventDispatcher/EventDispatcher.html>`_
to hook into the Symfony2 `HttpKernel
<http://api.symfony.com/2.0/Symfony/Component/HttpKernel/HttpKernel.html>`_ events. This allows
<http://api.symfony.com/master/Symfony/Component/HttpKernel/HttpKernel.html>`_ events. This allows
fetching the ``Request``, converting string responses into
``Response`` objects and handling Exceptions. We also use it
to dispatch some custom events like before/after filters and
......@@ -36,7 +36,7 @@ Controller
~~~~~~~~~~
The Symfony2 `Route
<http://api.symfony.com/2.0/Symfony/Component/Routing/Route.html>`_
<http://api.symfony.com/master/Symfony/Component/Routing/Route.html>`_
is actually quite powerful. Routes
can be named, which allows for URL generation. They can
also have requirements for the variable parts. In order
......@@ -49,7 +49,7 @@ ControllerCollection
~~~~~~~~~~~~~~~~~~~~
One of the goals of exposing the `RouteCollection
<http://api.symfony.com/2.0/Symfony/Component/Routing/RouteCollection.html>`_
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
was to make it mutable, so providers could add stuff to it.
The challenge here is the fact that routes know nothing
about their name. The name only has meaning in context
......
......@@ -9,14 +9,14 @@ Parameters
* **http_cache.cache_dir**: The cache directory to store the HTTP cache data.
* **http_cache.options** (optional): An array of options for the `HttpCache
<http://api.symfony.com/2.0/Symfony/Component/HttpKernel/HttpCache/HttpCache.html>`_
<http://api.symfony.com/master/Symfony/Component/HttpKernel/HttpCache/HttpCache.html>`_
constructor.
Services
--------
* **http_cache**: An instance of `HttpCache
<http://api.symfony.com/2.0/Symfony/Component/HttpKernel/HttpCache/HttpCache.html>`_,
<http://api.symfony.com/master/Symfony/Component/HttpKernel/HttpCache/HttpCache.html>`_,
Registering
-----------
......
......@@ -7,12 +7,14 @@ between requests.
Parameters
----------
* **session.default_locale**: The locale used by default in the session.
* **session.storage.save_path** (optional): The path for the
``NativeFileSessionStorage``, defaults to the value of
``sys_get_temp_dir()``.
* **session.storage.options**: An array of options that is passed to the
constructor of the ``session.storage`` service.
In case of the default ``NativeSessionStorage``, the possible options are:
In case of the default ``NativeFileSessionStorage``, the possible options are:
* **name**: The cookie name (_SESS by default)
* **id**: The session id (null by default)
......@@ -29,11 +31,11 @@ Services
--------
* **session**: An instance of Symfony2's `Session
<http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Session.html>`_.
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Session/Session.html>`_.
* **session.storage**: A service that is used for persistence of the
session data. Defaults to a `NativeSessionStorage
<http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/SessionStorage/NativeSessionStorage.html>`_.
session data. Defaults to a `NativeFileSessionStorage
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Session/Storage/NativeFileSessionStorage.html>`_.
Registering
-----------
......
......@@ -23,16 +23,16 @@ Services
--------
* **translator**: An instance of `Translator
<http://api.symfony.com/2.0/Symfony/Component/Translation/Translator.html>`_,
<http://api.symfony.com/master/Symfony/Component/Translation/Translator.html>`_,
that is used for translation.
* **translator.loader**: An instance of an implementation of the translation
`LoaderInterface <http://api.symfony.com/2.0/Symfony/Component/Translation/Loader/LoaderInterface.html>`_,
`LoaderInterface <http://api.symfony.com/master/Symfony/Component/Translation/Loader/LoaderInterface.html>`_,
defaults to an `ArrayLoader
<http://api.symfony.com/2.0/Symfony/Component/Translation/Loader/ArrayLoader.html>`_.
<http://api.symfony.com/master/Symfony/Component/Translation/Loader/ArrayLoader.html>`_.
* **translator.message_selector**: An instance of `MessageSelector
<http://api.symfony.com/2.0/Symfony/Component/Translation/MessageSelector.html>`_.
<http://api.symfony.com/master/Symfony/Component/Translation/MessageSelector.html>`_.
Registering
-----------
......
......@@ -13,9 +13,9 @@ Services
--------
* **url_generator**: An instance of `UrlGenerator
<http://api.symfony.com/2.0/Symfony/Component/Routing/Generator/UrlGenerator.html>`_,
<http://api.symfony.com/master/Symfony/Component/Routing/Generator/UrlGenerator.html>`_,
using the `RouteCollection
<http://api.symfony.com/2.0/Symfony/Component/Routing/RouteCollection.html>`_
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
that is provided through the ``routes`` service.
It has a ``generate`` method, which takes the route name as an argument,
followed by an array of route parameters.
......
......@@ -15,7 +15,7 @@ Services
--------
* **validator**: An instance of `Validator
<http://api.symfony.com/2.0/Symfony/Component/Validator/Validator.html>`_.
<http://api.symfony.com/master/Symfony/Component/Validator/Validator.html>`_.
* **validator.mapping.class_metadata_factory**: Factory for metadata loaders,
which can read validation constraint information from classes. Defaults to
......
......@@ -184,7 +184,7 @@ of them.
* **request**: Contains the current request object,
which is an instance of `Request
<http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Request.html>`_.
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Request.html>`_.
It gives you access to ``GET``, ``POST`` parameters
and lots more!
......@@ -197,7 +197,7 @@ of them.
* **autoloader**: This service provides you with a
`UniversalClassLoader
<http://api.symfony.com/2.0/Symfony/Component/ClassLoader/UniversalClassLoader.html>`_
<http://api.symfony.com/master/Symfony/Component/ClassLoader/UniversalClassLoader.html>`_
that is already registered. You can register prefixes
and namespaces on it.
......@@ -206,10 +206,10 @@ of them.
$app['autoloader']->registerPrefix('Twig_', $app['twig.class_path']);
For more information, check out the `Symfony2 autoloader documentation
<http://symfony.com/doc/2.0/cookbook/tools/autoloader.html>`_.
<http://symfony.com/doc/current/components/class_loader.html>`_.
* **routes**: The `RouteCollection
<http://api.symfony.com/2.0/Symfony/Component/Routing/RouteCollection.html>`_
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
that is used internally. You can add, modify, read
routes.
......@@ -218,17 +218,17 @@ of them.
chapter for more information.
* **dispatcher**: The `EventDispatcher
<http://api.symfony.com/2.0/Symfony/Component/EventDispatcher/EventDispatcher.html>`_
<http://api.symfony.com/master/Symfony/Component/EventDispatcher/EventDispatcher.html>`_
that is used internally. It is the core of the Symfony2
system and is used quite a bit by Silex.
* **resolver**: The `ControllerResolver
<http://api.symfony.com/2.0/Symfony/Component/HttpKernel/Controller/ControllerResolver.html>`_
<http://api.symfony.com/master/Symfony/Component/HttpKernel/Controller/ControllerResolver.html>`_
that is used internally. It takes care of executing the
controller with the right arguments.
* **kernel**: The `HttpKernel
<http://api.symfony.com/2.0/Symfony/Component/HttpKernel/HttpKernel.html>`_
<http://api.symfony.com/master/Symfony/Component/HttpKernel/HttpKernel.html>`_
that is used internally. The HttpKernel is the heart of
Symfony2, it takes a Request as input and returns a
Response as output.
......@@ -264,6 +264,10 @@ Core parameters
This parameter can be used by the ``UrlGeneratorProvider``.
* **request.default_locale** (optional): The locale used by default.
Defaults to ``en``.
* **debug** (optional): Returns whether or not the application is running in
debug mode.
......
......@@ -174,12 +174,12 @@ It is pretty straightforward.
The current ``request`` is automatically injected by Silex to the Closure
thanks to the type hinting. It is an instance of `Request
<http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Request.html>`_,
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Request.html>`_,
so you can fetch variables using the request ``get`` method.
Instead of returning a string we are returning an instance of
`Response
<http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Response.html>`_.
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Response.html>`_.
This allows setting an HTTP
status code, in this case it is set to ``201 Created``.
......
......@@ -111,6 +111,8 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
});
$this['request.default_locale'] = 'en';
$this['request'] = function () {
throw new \RuntimeException('Accessed request service outside of request scope. Try moving that call to a before handler or controller.');
};
......@@ -375,6 +377,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$this->beforeDispatched = false;
$this['request'] = $request;
$this['request']->setDefaultLocale($this['request.default_locale']);
$this->flush();
......
......@@ -14,8 +14,8 @@ namespace Silex\Provider;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage;
use Symfony\Component\HttpFoundation\Session;
use Symfony\Component\HttpFoundation\Session\Storage\NativeFileSessionStorage;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\KernelEvents;
/**
......@@ -32,11 +32,14 @@ class SessionServiceProvider implements ServiceProviderInterface
$this->app = $app;
$app['session'] = $app->share(function () use ($app) {
return new Session($app['session.storage'], $app['session.default_locale']);
return new Session($app['session.storage']);
});
$app['session.storage'] = $app->share(function () use ($app) {
return new NativeSessionStorage($app['session.storage.options']);
return new NativeFileSessionStorage(
isset($app['session.storage.save_path']) ? $app['session.storage.save_path'] : null,
$app['session.storage.options']
);
});
$app['dispatcher']->addListener(KernelEvents::REQUEST, array($this, 'onKernelRequest'), 128);
......@@ -44,7 +47,7 @@ class SessionServiceProvider implements ServiceProviderInterface
if (!isset($app['session.storage.options'])) {
$app['session.storage.options'] = array();
}
if (!isset($app['session.default_locale'])) {
$app['session.default_locale'] = 'en';
}
......
......@@ -15,7 +15,7 @@ use Silex\Application;
use Silex\Provider\SessionServiceProvider;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
/**
* SessionProvider test cases.
......@@ -31,7 +31,7 @@ class SessionServiceProviderTest extends \PHPUnit_Framework_TestCase
$app->register(new SessionServiceProvider());
$app['session.storage'] = $app->share(function () use ($app) {
return new ArraySessionStorage();
return new MockArraySessionStorage();
});
$app->get('/login', function () use ($app) {
......@@ -41,7 +41,7 @@ class SessionServiceProviderTest extends \PHPUnit_Framework_TestCase
$app->get('/account', function () use ($app) {
if (!$app['session']->get('logged_in')) {
return 'You are not in.';
return 'You are not logged in.';
}
return 'This is your account.';
......
Subproject commit fa6d62d0c007c07f23b70f5b6644d9e4992df408
Subproject commit afa16de6b91833b5a72ca89dc942ffb424737687
Subproject commit 0245ee6ef14a4a98cba373c48d38747c15cd8106
Subproject commit 8bceaa2f1fed52f6285b2cea39e7ae37fbea1c9b
Subproject commit 5a5c778ee7d27228e9eaaa43a0e8e46b42bf9f9f
Subproject commit dcce8174c551814c7aadcf13a2f8d73f3a6b4347
Subproject commit 57a69cfa4ac3e7c4ff48d55d95dc9773e98cde49
Subproject commit d35d208382d6e23a39a9e3c09357801b911eead6
Subproject commit 716d0f5e627c66538853c0e52a3778534438b100
Subproject commit f6b7f60b0c29ab8167de7d7c9ba78fc9cc283c64
Subproject commit dd56fc9f1f0baa006d7491d5c17eb3e2dd8a066c
Subproject commit b3adc8d5c29593db93c0abc4711a1e25fd3a6fa0
Subproject commit 4f29b46c69c3ad06a1b0ce2d75cce43b3406d02a
Subproject commit 2abe7f1b8e0f808dad0cc001b9d69371b604d719
Subproject commit 14df9f99823fdf82fe7b95c278ccd28c9bafecc9
Subproject commit cf2bb8655a13fcb516b1d0b95ddf0c51db25b2a8
Subproject commit 379b35a41a2749cf7361dda0f03e04410daaca4c
Subproject commit 6aceac404d8574cf7da57e7e29b00a665b7bd559
Subproject commit ed54b91173475ebfd55977ef080556cb90c8a840
Subproject commit d3d9c02357b2db6503539d11f6c379ccd86f9cc4
Subproject commit a33c4fbec76087da869bdec705734ae4bec39287
Subproject commit 2c507eb8587d472d98f7c4df3c32a123800121ce
Subproject commit 4478816e41d30de147e6dfb684af005e3050234a
Subproject commit 01f733f4b5407a7a2cc97f2b6dc269c8432da022
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment