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
143ca105
Commit
143ca105
authored
Feb 27, 2012
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[session-update] update to 2.1 session refactoring
parent
d230b294
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
10 deletions
+22
-10
doc/providers/session.rst
doc/providers/session.rst
+4
-2
doc/services.rst
doc/services.rst
+4
-0
src/Silex/Application.php
src/Silex/Application.php
+3
-0
src/Silex/Provider/SessionServiceProvider.php
src/Silex/Provider/SessionServiceProvider.php
+8
-5
tests/Silex/Tests/Provider/SessionServiceProviderTest.php
tests/Silex/Tests/Provider/SessionServiceProviderTest.php
+3
-3
No files found.
doc/providers/session.rst
View file @
143ca105
...
@@ -7,12 +7,14 @@ between requests.
...
@@ -7,12 +7,14 @@ between requests.
Parameters
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
* **session.storage.options**: An array of options that is passed to the
constructor of the ``session.storage`` service.
constructor of the ``session.storage`` service.
In case of the default ``NativeSessionStorage``, the possible options are:
In case of the default ``Native
File
SessionStorage``, the possible options are:
* **name**: The cookie name (_SESS by default)
* **name**: The cookie name (_SESS by default)
* **id**: The session id (null by default)
* **id**: The session id (null by default)
...
...
doc/services.rst
View file @
143ca105
...
@@ -264,6 +264,10 @@ Core parameters
...
@@ -264,6 +264,10 @@ Core parameters
This parameter can be used by the ``UrlGeneratorProvider``.
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** (optional): Returns whether or not the application is running in
debug mode.
debug mode.
...
...
src/Silex/Application.php
View file @
143ca105
...
@@ -111,6 +111,8 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
...
@@ -111,6 +111,8 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return
new
RedirectableUrlMatcher
(
$app
[
'routes'
],
$app
[
'request_context'
]);
return
new
RedirectableUrlMatcher
(
$app
[
'routes'
],
$app
[
'request_context'
]);
});
});
$this
[
'request.default_locale'
]
=
'en'
;
$this
[
'request'
]
=
function
()
{
$this
[
'request'
]
=
function
()
{
throw
new
\RuntimeException
(
'Accessed request service outside of request scope. Try moving that call to a before handler or controller.'
);
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
...
@@ -375,6 +377,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$this
->
beforeDispatched
=
false
;
$this
->
beforeDispatched
=
false
;
$this
[
'request'
]
=
$request
;
$this
[
'request'
]
=
$request
;
$this
[
'request'
]
->
setDefaultLocale
(
$this
[
'request.default_locale'
]);
$this
->
flush
();
$this
->
flush
();
...
...
src/Silex/Provider/SessionServiceProvider.php
View file @
143ca105
...
@@ -14,8 +14,8 @@ namespace Silex\Provider;
...
@@ -14,8 +14,8 @@ namespace Silex\Provider;
use
Silex\Application
;
use
Silex\Application
;
use
Silex\ServiceProviderInterface
;
use
Silex\ServiceProviderInterface
;
use
Symfony\Component\HttpFoundation\Session
Storage\Nativ
eSessionStorage
;
use
Symfony\Component\HttpFoundation\Session
\Storage\NativeFil
eSessionStorage
;
use
Symfony\Component\HttpFoundation\Session
;
use
Symfony\Component\HttpFoundation\Session
\Session
;
use
Symfony\Component\HttpKernel\KernelEvents
;
use
Symfony\Component\HttpKernel\KernelEvents
;
/**
/**
...
@@ -32,11 +32,14 @@ class SessionServiceProvider implements ServiceProviderInterface
...
@@ -32,11 +32,14 @@ class SessionServiceProvider implements ServiceProviderInterface
$this
->
app
=
$app
;
$this
->
app
=
$app
;
$app
[
'session'
]
=
$app
->
share
(
function
()
use
(
$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
)
{
$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
);
$app
[
'dispatcher'
]
->
addListener
(
KernelEvents
::
REQUEST
,
array
(
$this
,
'onKernelRequest'
),
128
);
...
...
tests/Silex/Tests/Provider/SessionServiceProviderTest.php
View file @
143ca105
...
@@ -15,7 +15,7 @@ use Silex\Application;
...
@@ -15,7 +15,7 @@ use Silex\Application;
use
Silex\Provider\SessionServiceProvider
;
use
Silex\Provider\SessionServiceProvider
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Session
Storage\
ArraySessionStorage
;
use
Symfony\Component\HttpFoundation\Session
\Storage\Mock
ArraySessionStorage
;
/**
/**
* SessionProvider test cases.
* SessionProvider test cases.
...
@@ -31,7 +31,7 @@ class SessionServiceProviderTest extends \PHPUnit_Framework_TestCase
...
@@ -31,7 +31,7 @@ class SessionServiceProviderTest extends \PHPUnit_Framework_TestCase
$app
->
register
(
new
SessionServiceProvider
());
$app
->
register
(
new
SessionServiceProvider
());
$app
[
'session.storage'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
$app
[
'session.storage'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
return
new
ArraySessionStorage
();
return
new
Mock
ArraySessionStorage
();
});
});
$app
->
get
(
'/login'
,
function
()
use
(
$app
)
{
$app
->
get
(
'/login'
,
function
()
use
(
$app
)
{
...
@@ -41,7 +41,7 @@ class SessionServiceProviderTest extends \PHPUnit_Framework_TestCase
...
@@ -41,7 +41,7 @@ class SessionServiceProviderTest extends \PHPUnit_Framework_TestCase
$app
->
get
(
'/account'
,
function
()
use
(
$app
)
{
$app
->
get
(
'/account'
,
function
()
use
(
$app
)
{
if
(
!
$app
[
'session'
]
->
get
(
'logged_in'
))
{
if
(
!
$app
[
'session'
]
->
get
(
'logged_in'
))
{
return
'You are not in.'
;
return
'You are not
logged
in.'
;
}
}
return
'This is your account.'
;
return
'This is your account.'
;
...
...
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