-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Document start on demand feature. #2475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ examples if you wish to write your own. | |
Example usage:: | ||
|
||
use Symfony\Component\HttpFoundation\Session\Session; | ||
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorage; | ||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; | ||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; | ||
|
||
$storage = new NativeSessionStorage(array(), new PdoSessionHandler()); | ||
|
@@ -217,6 +217,41 @@ particular cookie by reading the ``getLifetime()`` method:: | |
The expiry time of the cookie can be determined by adding the created | ||
timestamp and the lifetime. | ||
|
||
Session start-on-demand | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. versionadded:: 2.3 | ||
Control over session "start-on-demand" was added in Symfony 2.3. | ||
|
||
In versions 2.1-2.2, Symfony Sessions automatically invoked ``$session->start()`` when | ||
any attempt was made to access session data (effectively 'start on demand'). | ||
From Symfony 2.3 this behaviour can be controlled. | ||
|
||
There are three modes defined by :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorageInterface` | ||
|
||
The settings are as follows: | ||
|
||
- ``SessionStorageInterface::NO_START_ON_DEMAND_STRICT`` - The session will not be started on demand | ||
and any attempt to read or write session data will result in a ``\RuntimeException`` | ||
- ``SessionStorageInterface::START_ON_DEMAND`` - The session will be started if it hasn't already been | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you should mention that this setting reflects what 2.1-2.2 used as default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
when any attempt is made to read ro write session data. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
- ``SessionStorageInterface::NO_START_ON_DEMAND_LAX`` - The sessions will not be started on demand | ||
when session data is read or written to. It will allow access to the unitialized ``BagInterface``. | ||
If this session is subsequently started manually after data is written to a ``BagInterface`` will | ||
be overwritten (by the session data read from persistence). | ||
|
||
You can configure these by injecting a configured storage engine into the session:: | ||
|
||
<?php | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; | ||
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface; | ||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; | ||
|
||
$storage = new NativeSessionStorage(array(), new PdoSessionHandler(), SessionStorageInterface::NO_START_ON_DEMAND_STRICT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please put every argument on a new line, to avoid horizontal scrolling. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
$session = new Session($storage); | ||
|
||
|
||
PHP 5.4 compatibility | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ Configuration | |
* enabled | ||
* field_name | ||
* `session`_ | ||
* `auto_start`_ | ||
* `on_demand`_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about mock_name ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these should link to headings explaining these options. If you don't add a section about these options, it should be: * `session`_
* auto_start
* on_demand There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
* `cookie_lifetime`_ | ||
* `cookie_path`_ | ||
* `cookie_domain`_ | ||
|
@@ -462,6 +464,8 @@ Full Default Configuration | |
session: | ||
storage_id: session.storage.native | ||
handler_id: session.handler.native_file | ||
auto_start: false | ||
on_demand: on #on, off or off_lax | ||
name: ~ | ||
cookie_lifetime: ~ | ||
cookie_path: ~ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put the class role on a new line, to not break or 72th line wrapping rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.