Skip to content

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

Merged
merged 6 commits into from Apr 29, 2013
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion components/http_foundation/session_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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`
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.


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
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

when any attempt is made to read ro write session data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo ro instead of or.

Copy link
Author

Choose a reason for hiding this comment

The 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put every argument on a new line, to avoid horizontal scrolling.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

$session = new Session($storage);


PHP 5.4 compatibility
~~~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 4 additions & 0 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Configuration
* enabled
* field_name
* `session`_
* `auto_start`_
* `on_demand`_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about mock_name ?

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

* `cookie_lifetime`_
* `cookie_path`_
* `cookie_domain`_
Expand Down Expand Up @@ -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: ~
Expand Down