Skip to content

Commit

Permalink
[FrameworkBundle] Add session.handler service and handler_id configur…
Browse files Browse the repository at this point in the history
…ation property.

Revert service back to session.storage.native
Rename session.storage.native_file to session.handler.native_file (which is the default so no BC break from 2.0)
  • Loading branch information
Drak committed Mar 14, 2012
1 parent 1308312 commit a1c678e
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 17 deletions.
Expand Up @@ -167,7 +167,8 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
->canBeUnset()
->children()
->booleanNode('auto_start')->defaultFalse()->end()
->scalarNode('storage_id')->defaultValue('session.storage.native_file')->end()
->scalarNode('storage_id')->defaultValue('session.storage.native')->end()
->scalarNode('handler_id')->defaultValue('session.handler.native_file')->end()
->scalarNode('name')->end()
->scalarNode('cookie_lifetime')->end()
->scalarNode('cookie_path')->end()
Expand Down
Expand Up @@ -310,10 +310,16 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
}
$container->setParameter('session.storage.options', $options);

// session handler (the internal callback registered with PHP session management)
$container->setAlias('session.handler', $config['handler_id']);

$this->addClassesToCompile(array(
'Symfony\\Bundle\\FrameworkBundle\\EventListener\\SessionListener',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorageInterface',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\AbstractSessionStorage',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorage',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\NativeSessionHandler',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\AbstractProxy',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\SessionHandlerProxy',
$container->getDefinition('session')->getClass(),
));

Expand Down
Expand Up @@ -74,6 +74,7 @@

<xsd:complexType name="session">
<xsd:attribute name="storage-id" type="xsd:string" />
<xsd:attribute name="handler-id" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="cookie-lifetime" type="xsd:integer" />
<xsd:attribute name="cookie-path" type="xsd:string" />
Expand Down
13 changes: 8 additions & 5 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml
Expand Up @@ -8,8 +8,9 @@
<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.native.class">Symfony\Component\HttpFoundation\Session\Storage\SessionStorage</parameter>
<parameter key="session.storage.mock_file.class">Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage</parameter>
<parameter key="session.handler.native_file.class">Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler</parameter>
<parameter key="session_listener.class">Symfony\Bundle\FrameworkBundle\EventListener\SessionListener</parameter>
</parameters>

Expand All @@ -20,18 +21,21 @@
<argument type="service" id="session.flash_bag" />
</service>

<service id="session.storage.native" class="%session.storage.native.class%">
<argument>%session.storage.options%</argument>
<argument type="service" id="session.handler" />
</service>

<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.native_file" class="%session.storage.native_file.class%" public="false">
<service id="session.handler.native_file" class="%session.handler.native_file.class%" public="false">
<argument>%kernel.cache_dir%/sessions</argument>
<argument>%session.storage.options%</argument>
</service>

<service id="session_listener" class="%session_listener.class%">
Expand All @@ -40,7 +44,6 @@
</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>
Expand Up @@ -4,7 +4,8 @@
'secret' => 's3cr3t',
'session' => array(
'auto_start' => true,
'storage_id' => 'session.storage.native_file',
'storage_id' => 'session.storage.native',
'handler_id' => 'session.handler.native_file',
'name' => '_SYMFONY',
'lifetime' => 2012,
'path' => '/sf2',
Expand Down
Expand Up @@ -4,7 +4,8 @@
'secret' => 's3cr3t',
'session' => array(
'auto_start' => true,
'storage_id' => 'session.storage.native_file',
'storage_id' => 'session.storage.native',
'handler_id' => 'session.handler.native_file',
'name' => '_SYMFONY',
'lifetime' => 2012,
'path' => '/sf2',
Expand Down
Expand Up @@ -20,7 +20,8 @@
),
'session' => array(
'auto_start' => true,
'storage_id' => 'session.storage.native_file',
'storage_id' => 'session.storage.native',
'handler_id' => 'session.handler.native_file',
'name' => '_SYMFONY',
'lifetime' => 86400,
'path' => '/',
Expand Down
Expand Up @@ -7,6 +7,6 @@
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config secret="s3cr3t">
<framework:session auto-start="true" storage-id="session.storage.native_file" name="_SYMFONY" lifetime="2012" path="/sf2" domain="sf2.example.com" secure="false" httponly="false" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="true" />
<framework:session auto-start="true" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" lifetime="2012" path="/sf2" domain="sf2.example.com" secure="false" httponly="false" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="true" />
</framework:config>
</container>
Expand Up @@ -7,6 +7,6 @@
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config secret="s3cr3t">
<framework:session auto-start="true" storage-id="session.storage.native_file" name="_SYMFONY" lifetime="2012" path="/sf2" domain="sf2.example.com" secure="false" httponly="false" cookie-lifetime="86400" cookie-path="/" cookie-httponly="true" />
<framework:session auto-start="true" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" lifetime="2012" path="/sf2" domain="sf2.example.com" secure="false" httponly="false" cookie-lifetime="86400" cookie-path="/" cookie-httponly="true" />
</framework:config>
</container>
Expand Up @@ -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_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="true" />
<framework:session auto-start="true" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="true" />
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" >
<framework:loader>loader.foo</framework:loader>
<framework:loader>loader.bar</framework:loader>
Expand Down
Expand Up @@ -2,7 +2,8 @@ framework:
secret: s3cr3t
session:
auto_start: true
storage_id: session.storage.native_file
storage_id: session.storage.native
handler_id: session.handler.native_file
name: _SYMFONY
lifetime: 2012
path: /sf2
Expand Down
Expand Up @@ -2,7 +2,8 @@ framework:
secret: s3cr3t
session:
auto_start: true
storage_id: session.storage.native_file
storage_id: session.storage.native
handler_id: session.handler.native_file
name: _SYMFONY
lifetime: 2012
path: /sf2
Expand Down
Expand Up @@ -14,7 +14,8 @@ framework:
type: xml
session:
auto_start: true
storage_id: session.storage.native_file
storage_id: session.storage.native
handler_id: session.handler.native_file
name: _SYMFONY
lifetime: 86400
path: /
Expand Down
Expand Up @@ -78,7 +78,8 @@ 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_file', (string) $container->getAlias('session.storage'));
$this->assertEquals('session.storage.native', (string) $container->getAlias('session.storage'));
$this->assertEquals('session.handler.native_file', (string) $container->getAlias('session.handler'));

$options = $container->getParameter('session.storage.options');
$this->assertEquals('_SYMFONY', $options['name']);
Expand Down

0 comments on commit a1c678e

Please sign in to comment.