Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[WCM] Document PhpSessionStorage#2474

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
weaverryan merged 6 commits intosymfony:masterfromunknown repositoryApr 27, 2013
Merged
Show file tree
Hide file tree
Changes fromall 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
1 change: 1 addition & 0 deletionscomponents/http_foundation/index.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,4 +8,5 @@ HTTP Foundation
sessions
session_configuration
session_testing
session_php_bridge
trusting_proxies
49 changes: 49 additions & 0 deletionscomponents/http_foundation/session_php_bridge.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
.. index::
single: HTTP
single: HttpFoundation, Sessions

Integrating with Legacy Sessions
================================

Sometimes it may be necessary to integrate Symfony into a legacy application
where you do not initially have the level of control you require.

As stated elsewhere, Symfony Sessions are designed to replace the use of
PHP's native ``session_*()`` functions and use of the ``$_SESSION``
superglobal. Additionally, it is mandatory for Symfony to start the session.

However when there really are circumstances where this is not possible, it is possible
to use a special storage bridge
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\PhpBridgeSessionStorage`
which is designed to allow Symfony to work with a session started outside of
the Symfony Session framework. You are warned that things can interrupt this
use case unless you are careful: for example legacy application erases ``$_SESSION``.

Typical use of this might look as follows::

<?php
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\PhpBridgeSessionStorage;

// legacy application configures session
ini_set('session.save_handler', 'files');
ini_set('session.save_path', '/tmp');
session_start();

// Get Symfony to interface with this existing session
$session = new Session(new PhpBridgeSessionStorage());

// symfony will now interface with the existing PHP session
$session->start();

This will allow you to start using the Symfony Session API and allow
migration of your application to Symfony Sessions.

.. note::

Symfony Sessions store data like attributes in special 'Bags' which use a
key in the ``$_SESSION`` superglobal. This means that a Symfony Session
cannot access arbitary keys in ``$_SESSION`` that may be set by the legacy
application, although all the ``$_SESSION`` contents will be saved when
the session is saved.

1 change: 1 addition & 0 deletionscookbook/index.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,7 @@ The Cookbook
debugging
event_dispatcher/index
request/index
session/index
profiler/index
web_services/index
symfony1
Expand Down
4 changes: 4 additions & 0 deletionscookbook/map.rst.inc
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,10 @@

* :doc:`/cookbook/request/mime_type`

* :doc:`/cookbook/session/index`

* :doc:`/cookbook/session/php_bridge`

* :doc:`/cookbook/routing/index`

* :doc:`/cookbook/routing/scheme`
Expand Down
7 changes: 7 additions & 0 deletionscookbook/sessions/index.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
Sessions
========

.. toctree::
:maxdepth: 2

php_bridge
36 changes: 36 additions & 0 deletionscookbook/sessions/php_bridge.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
.. index::
single: Sessions

Bridge a legacy application with Symfony Sessions
--------------------------------------------------------

.. versionadded:: 2.3
Added ability to integrate with a legacy PHP session

You may take advantage of the PHP Bridge Session when integrating
a legacy application into the Symfony Full Stack Framework when it
may not be possible to avoid the legacy application starting the
session with ``session_start()``

If the application has sets it's own PHP save handler, you can
specify null for the ``handler_id``:

.. code-block:: yml

framework:
session:
storage_id: session.storage.php_bridge
handler_id: ~

Otherwise, if the problem is simply that you cannot avoid the application
starting the session with ``session_start()`` but you can still make use of
a Symfony based session save handler, you can specify the save handle
as in the example below:

.. code-block:: yml

framework:
session:
storage_id: session.storage.php_bridge
handler_id: session.handler.native_file


[8]ページ先頭

©2009-2025 Movatter.jp