-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added a brief explanation about Doctrine DBAL Session Storage #5019
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,3 +217,85 @@ For MSSQL, the statement might look like the following: | |
ALLOW_PAGE_LOCKS = ON | ||
) ON [PRIMARY] | ||
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] | ||
|
||
Doctrine DBAL Session Storage | ||
----------------------------- | ||
|
||
Symfony applications can also use a Doctrine DBAL based session storage. This | ||
alternative implementation is very similar to the ``PdoSessionHandler`` explained | ||
above, but uses a Doctrine connection and thus also works with non-PDO-based | ||
drivers like mysqli and OCI8. | ||
|
||
The only significant disadvantage of the Doctrine DBAL session storage comparing | ||
it with ``PdoSessionHandler`` is that you can only configure the name of the | ||
table used to store sessions but not its column names. | ||
|
||
DBAL Session Storage configuration example: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/config.yml | ||
framework: | ||
session: | ||
# ... | ||
handler_id: session.handler.dbal | ||
|
||
parameters: | ||
# ... | ||
dbal_session_table: session | ||
|
||
# app/config/services.yml | ||
services: | ||
# ... | ||
session.handler.dbal: | ||
class: Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler | ||
arguments: ["@doctrine.dbal.default_connection", "%dbal_session_table%"] | ||
|
||
.. code-block:: xml | ||
|
||
<!-- app/config/config.xml --> | ||
<framework:config> | ||
<!-- ... --> | ||
<framework:session handler-id="session.handler.dbal" cookie-lifetime="3600" auto-start="true"/> | ||
</framework:config> | ||
|
||
<parameters> | ||
<!-- ... --> | ||
<parameter key="dbal_session_table">session</parameter> | ||
</parameters> | ||
|
||
<!-- app/config/services.xml --> | ||
<services> | ||
<!-- ... --> | ||
<service id="session.handler.dbal" class="Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler"> | ||
<argument type="service" id="doctrine.dbal.default_connection" /> | ||
<argument>%dbal_session_table%</argument> | ||
</service> | ||
</services> | ||
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. I prefer to have a complete example: <?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<!-- ... -->
<framework:session handler-id="session.handler.dbal" />
</framework:config>
<parameters>
<!-- ... -->
<parameter key="dbal_session_table">session</parameter>
</parameters>
</container>
<!-- app/config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<!-- ... -->
<service id="session.handler.dbal" class="Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler">
<argument type="service" id="doctrine.dbal.default_connection" />
<argument>%dbal_session_table%</argument>
</service>
</services>
</container> |
||
|
||
.. code-block:: php | ||
|
||
// app/config/config.php | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
$container->loadFromExtension('framework', array( | ||
// ... | ||
'session' => array( | ||
// ... | ||
'handler_id' => 'session.handler.dbal', | ||
), | ||
)); | ||
|
||
// ... | ||
$container->setParameter('pdo.dbal_session_table', 'sess'); | ||
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. The other examples don't have the |
||
|
||
// app/config/services.php | ||
// ... | ||
$storageDefinition = new Definition('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', array( | ||
new Reference('doctrine.dbal.default_connection'), | ||
'%dbal_session_table%', | ||
)); | ||
$container->setDefinition('session.handler.dbal', $storageDefinition); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
note that these paragraphs are true for 2.3, but not for 2.6+ (the DBAL session storage has not been migrated to implement session locking yet AFAIK)