Skip to content

Commit

Permalink
[FrameworkBundle] Make session save path configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
asm89 committed Apr 13, 2012
1 parent 114bc14 commit c0e7ee9
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
->scalarNode('gc_divisor')->end()
->scalarNode('gc_probability')->end()
->scalarNode('gc_maxlifetime')->end()
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
->scalarNode('lifetime')->setInfo('DEPRECATED! Please use: cookie_lifetime')->end()
->scalarNode('path')->setInfo('DEPRECATED! Please use: cookie_path')->end()
->scalarNode('domain')->setInfo('DEPRECATED! Please use: cookie_domain')->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
// session handler (the internal callback registered with PHP session management)
$container->setAlias('session.handler', $config['handler_id']);

$container->setParameter('session.save_path', $config['save_path']);

$this->addClassesToCompile(array(
'Symfony\\Bundle\\FrameworkBundle\\EventListener\\SessionListener',
'Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorageInterface',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<xsd:attribute name="gc-maxlifetime" type="xsd:string" />
<xsd:attribute name="gc-divisor" type="xsd:string" />
<xsd:attribute name="gc-probability" type="xsd:string" />
<xsd:attribute name="save-path" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="templating">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</service>

<service id="session.handler.native_file" class="%session.handler.native_file.class%" public="false">
<argument>%kernel.cache_dir%/sessions</argument>
<argument>%session.save_path%</argument>
</service>

<service id="session_listener" class="%session_listener.class%">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'gc_maxlifetime' => 90000,
'gc_divisor' => 108,
'gc_probability' => 1,
'save_path' => '/path/to/sessions',
),
'templating' => array(
'assets_version' => 'SomeVersionScheme',
Expand Down
Original file line number Diff line number Diff line change
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" gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" 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:session auto-start="true" gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" 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" save-path="/path/to/sessions" />
<framework:templating assets-version="SomeVersionScheme" cache="/path/to/cache" >
<framework:loader>loader.foo</framework:loader>
<framework:loader>loader.bar</framework:loader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ framework:
gc_probability: 1
gc_divisor: 108
gc_maxlifetime: 90000
save_path: /path/to/sessions
templating:
assets_version: SomeVersionScheme
assets_base_urls: http://cdn.example.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public function testSession()
$this->assertEquals(108, $options['gc_divisor']);
$this->assertEquals(1, $options['gc_probability']);
$this->assertEquals(90000, $options['gc_maxlifetime']);

$this->assertEquals('/path/to/sessions', $container->getParameter('session.save_path'));
}

public function testSessionDeprecatedMergeFull()
Expand Down

0 comments on commit c0e7ee9

Please sign in to comment.