Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
e92c002a
Commit
e92c002a
authored
Mar 27, 2011
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a Session extension
parent
5fdbaf7f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
src/Silex/Extension/SessionExtension.php
src/Silex/Extension/SessionExtension.php
+49
-0
No files found.
src/Silex/Extension/SessionExtension.php
0 → 100644
View file @
e92c002a
<?php
/*
* This file is part of the Silex framework.
*
* (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
Silex\Extension
;
use
Silex\Application
;
use
Silex\ExtensionInterface
;
use
Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage
;
use
Symfony\Component\HttpFoundation\Session
;
use
Symfony\Component\HttpKernel\Events
as
HttpKernelEvents
;
class
SessionExtension
implements
ExtensionInterface
{
private
$app
;
public
function
register
(
Application
$app
)
{
$this
->
app
=
$app
;
$app
[
'session'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
return
new
Session
(
$app
[
'session_storage'
]);
});
$app
[
'session_storage'
]
=
$app
->
share
(
function
()
{
return
new
NativeSessionStorage
();
});
$app
[
'dispatcher'
]
->
addListener
(
HttpKernelEvents
::
onCoreRequest
,
$this
,
-
255
);
}
public
function
onCoreRequest
(
$event
)
{
$request
=
$event
->
getRequest
();
$request
->
setSession
(
$this
->
app
[
'session'
]);
// starts the session if a session cookie already exists in the request...
if
(
$request
->
hasSession
())
{
$request
->
getSession
()
->
start
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment