-
- Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Changes from 1 commit
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 |
|---|---|---|
| | @@ -217,3 +217,79 @@ 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. | ||
| 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 am not sure of the comma here | ||
| | ||
| 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 | ||
| | ||
| 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> | ||
| | ||
| <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( | ||
| ..., | ||
| 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. why arbitrarily doing // ... and then here do ... without the // ? | ||
| 'session' => array( | ||
| // ..., | ||
| 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. are we doing that ...,? sounds weird | ||
| '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 | ||
| | ||
| $storageDefinition = new Definition('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', array( | ||
| new Reference('doctrine.dbal.default_connection'), | ||
| '%dbal_session_table%', | ||
| )); | ||
| $container->setDefinition('session.handler.dbal', $storageDefinition); | ||
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)