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

Appearance settings

[FrameworkBundle] start session on flashbag injection #36063

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
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
10 changes: 6 additions & 4 deletions 10 src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

<service id="session" class="Symfony\Component\HttpFoundation\Session\Session" public="true">
<argument type="service" id="session.storage" />
<argument type="service" id="session.attribute_bag" />
<argument type="service" id="session.flash_bag" />
</service>

<service id="Symfony\Component\HttpFoundation\Session\SessionInterface" alias="session" />
Expand All @@ -37,10 +35,14 @@
<argument type="service" id="session.storage.metadata_bag" />
</service>

<service id="session.flash_bag" class="Symfony\Component\HttpFoundation\Session\Flash\FlashBag" />
<service id="session.flash_bag" class="Symfony\Component\HttpFoundation\Session\Flash\FlashBag">
<factory service="session" method="getFlashBag"/>
</service>
<service id="Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface" alias="session.flash_bag" />

<service id="session.attribute_bag" class="Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag" />
<service id="session.attribute_bag" class="Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag">
<factory service="session" method="getAttributeBag"/>
</service>

<service id="session.storage.mock_file" class="Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage">
<argument>%kernel.cache_dir%/sessions</argument>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\Routing\RouterInterface;

class InjectedFlashbagSessionController
{
/**
* @var FlashBagInterface
*/
private $flashBag;

/**
* @var RouterInterface
*/
private $router;

public function __construct(
FlashBagInterface $flashBag,
RouterInterface $router
) {
$this->flashBag = $flashBag;
$this->router = $router;
}

public function setFlashAction(Request $request, $message)
{
$this->flashBag->add('notice', $message);

return new RedirectResponse($this->router->generate('session_showflash'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ session_setflash:
path: /session_setflash/{message}
defaults: { _controller: TestBundle:Session:setFlash}

injected_flashbag_session_setflash:
path: injected_flashbag/session_setflash/{message}
defaults: { _controller: TestBundle:InjectedFlashbagSession:setFlash}

session_showflash:
path: /session_showflash
defaults: { _controller: TestBundle:Session:showFlash}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ public function testFlash($config, $insulate)
$this->assertStringContainsString('No flash was set.', $crawler->text());
}

/**
* Tests flash messages work when flashbag service is injected to the constructor.
*
* @dataProvider getConfigs
*/
public function testFlashOnInjectedFlashbag($config, $insulate)
{
$client = $this->createClient(['test_case' => 'Session', 'root_config' => $config]);
if ($insulate) {
$client->insulate();
}

// set flash
$client->request('GET', '/injected_flashbag/session_setflash/Hello%20world.');

// check flash displays on redirect
$this->assertStringContainsString('Hello world.', $client->followRedirect()->text());

// check flash is gone
$crawler = $client->request('GET', '/session_showflash');
$this->assertStringContainsString('No flash was set.', $crawler->text());
}

/**
* See if two separate insulated clients can run without
* polluting each other's session data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ services:
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SubRequestController:
tags:
- { name: controller.service_arguments, action: indexAction, argument: handler, id: fragment.handler }

Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\InjectedFlashbagSessionController:
autowire: true
tags: ['controller.service_arguments']
Morty Proxy This is a proxified and sanitized view of the page, visit original site.