Skip to content

Updated the session/* articles for Symfony 4 #8689

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 1 commit into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Sessions

.. toctree::
:maxdepth: 1
:glob:

session/*
session/sessions_directory
session/avoid_session_start
Copy link
Member

Choose a reason for hiding this comment

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

@sroze not sure if you're the best person, but I was wondering if the above article needs to change at all for the new lazy session handling stuff?

Copy link
Contributor

Choose a reason for hiding this comment

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

Erm, that's a good point. I'll have a look.

session/locale_sticky_session
session/limit_metadata_writes
session/php_bridge
session/proxy_examples
Copy link
Member

Choose a reason for hiding this comment

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

@javiereguiluz could we also link to doctrine/pdo_session_storage in here without creating issues? I actually think it should be the first or second article.


3 changes: 3 additions & 0 deletions session/limit_metadata_writes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ than zero:

.. code-block:: yaml

# config/packages/framework.yaml
framework:
session:
metadata_update_threshold: 120

.. code-block:: xml

<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:framework="http://symfony.com/schema/dic/symfony"
Expand All @@ -45,6 +47,7 @@ than zero:

.. code-block:: php

// config/packages/framework.php
$container->loadFromExtension('framework', array(
'session' => array(
'metadata_update_threshold' => 120,
Expand Down
18 changes: 10 additions & 8 deletions session/locale_sticky_session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,18 @@ via some "Change Locale" route & controller), or create a route with a the :ref:

.. code-block:: yaml

# config/services.yaml
services:
# ...

App\EventSubscriber\LocaleSubscriber:
arguments: ['%kernel.default_locale%']
# redundant if you're using autoconfigure
tags: [kernel.event_subscriber]
# uncomment the next line if you are not using autoconfigure
# tags: [kernel.event_subscriber]

.. code-block:: xml

<!-- 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"
Expand All @@ -93,18 +95,21 @@ via some "Change Locale" route & controller), or create a route with a the :ref:
<service id="App\EventSubscriber\LocaleSubscriber">
<argument>%kernel.default_locale%</argument>

<tag name="kernel.event_subscriber" />
<!-- uncomment the next line if you are not using autoconfigure -->
<!-- <tag name="kernel.event_subscriber" /> -->
</service>
</services>
</container>

.. code-block:: php

// config/services.php
use App\EventSubscriber\LocaleSubscriber;

$container->register(LocaleSubscriber::class)
->addArgument('%kernel.default_locale%')
->addTag('kernel.event_subscriber');
// uncomment the next line if you are not using autoconfigure
// ->addTag('kernel.event_subscriber');

That's it! Now celebrate by changing the user's locale and seeing that it's
sticky throughout the request.
Expand All @@ -115,7 +120,7 @@ method::
// from a controller...
use Symfony\Component\HttpFoundation\Request;

public function indexAction(Request $request)
public function index(Request $request)
{
$locale = $request->getLocale();
}
Expand Down Expand Up @@ -159,9 +164,6 @@ event:
$this->session = $session;
}

/**
* @param InteractiveLoginEvent $event
*/
public function onInteractiveLogin(InteractiveLoginEvent $event)
{
$user = $event->getAuthenticationToken()->getUser();
Expand Down
6 changes: 6 additions & 0 deletions session/php_bridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ for the ``handler_id``:

.. code-block:: yaml

# config/packages/framework.yaml
framework:
session:
storage_id: session.storage.php_bridge
handler_id: ~

.. code-block:: xml

<!-- config/packages/framework.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"
Expand All @@ -38,6 +40,7 @@ for the ``handler_id``:

.. code-block:: php

// config/packages/framework.php
$container->loadFromExtension('framework', array(
'session' => array(
'storage_id' => 'session.storage.php_bridge',
Expand All @@ -54,13 +57,15 @@ the example below:

.. code-block:: yaml

# config/packages/framework.yaml
framework:
session:
storage_id: session.storage.php_bridge
handler_id: session.handler.native_file

.. code-block:: xml

<!-- config/packages/framework.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"
Expand All @@ -77,6 +82,7 @@ the example below:

.. code-block:: php

// config/packages/framework.php
$container->loadFromExtension('framework', array(
'session' => array(
'storage_id' => 'session.storage.php_bridge',
Expand Down
6 changes: 3 additions & 3 deletions session/proxy_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ Symfony to use your session handler instead of the default one:

.. code-block:: yaml

# app/config/config.yml
# config/packages/framework.yaml
framework:
session:
# ...
handler_id: App\Session\CustomSessionHandler

.. code-block:: xml

<!-- app/config/config.xml -->
<!-- config/packages/framework.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"
Expand All @@ -44,7 +44,7 @@ Symfony to use your session handler instead of the default one:

.. code-block:: php

// app/config/config.php
// config/packages/framework.php
use App\Session\CustomSessionHandler;
$container->loadFromExtension('framework', array(
// ...
Expand Down
6 changes: 3 additions & 3 deletions session/sessions_directory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ this path, update the ``framework.session.save_path`` configuration key:

.. code-block:: yaml

# app/config/config.yml
# config/packages/framework.yaml
framework:
session:
handler_id: session.handler.native_file
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'

.. code-block:: xml

<!-- app/config/config.xml -->
<!-- config/packages/framework.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"
Expand All @@ -36,7 +36,7 @@ this path, update the ``framework.session.save_path`` configuration key:

.. code-block:: php

// app/config/config.php
// config/packages/framework.php
$container->loadFromExtension('framework', array(
'session' => array(
'handler_id' => 'session.handler.native_file',
Expand Down