Skip to content

Commit b4c1e03

Browse files
committed
merged branch jmikola/logout-url-helper-request-dep (PR symfony#3511)
Commits ------- 8796276 [SecurityBundle] Avoid direct request dependency in LogoutUrlHelper Discussion ---------- [SecurityBundle] Avoid direct request dependency in LogoutUrlHelper This quickly addresses the problem when the helper is constructed in a console environment without request scope. Ideally, the helper should be able to construct the absolute logout URL using data already available in the UrlGenerator's RequestContext and the $_SERVER environment variable; however, that will require copying some code from the Request class to create a base URI and path. Fixes symfony#3508 [![Build Status](https://secure.travis-ci.org/jmikola/symfony.png?branch=master)](http://travis-ci.org/jmikola/symfony)
2 parents dcdd785 + 8796276 commit b4c1e03

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Symfony/Bundle/SecurityBundle/Resources/config/templating_php.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<services>
1313
<service id="templating.helper.logout_url" class="%templating.helper.logout_url.class%">
1414
<tag name="templating.helper" alias="logout_url" />
15-
<argument type="service" id="request" strict="false" />
15+
<argument type="service" id="service_container" />
1616
<argument type="service" id="router" />
1717
</service>
1818

src/Symfony/Bundle/SecurityBundle/Templating/Helper/LogoutUrlHelper.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\Templating\Helper;
1313

14+
use Symfony\Component\DependencyInjection\ContainerInterface;
1415
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
15-
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1717
use Symfony\Component\Templating\Helper\Helper;
1818

@@ -23,19 +23,19 @@
2323
*/
2424
class LogoutUrlHelper extends Helper
2525
{
26+
private $container;
2627
private $listeners;
27-
private $request;
2828
private $router;
2929

3030
/**
3131
* Constructor.
3232
*
33-
* @param Request $request A request instance
34-
* @param UrlGeneratorInterface $router A Router instance
33+
* @param ContainerInterface $container A ContainerInterface instance
34+
* @param UrlGeneratorInterface $router A Router instance
3535
*/
36-
public function __construct(Request $request, UrlGeneratorInterface $router)
36+
public function __construct(ContainerInterface $container, UrlGeneratorInterface $router)
3737
{
38-
$this->request = $request;
38+
$this->container = $container;
3939
$this->router = $router;
4040
$this->listeners = array();
4141
}
@@ -95,7 +95,9 @@ private function generateLogoutUrl($key, $absolute)
9595
$parameters = null !== $csrfProvider ? array($csrfParameter => $csrfProvider->generateCsrfToken($intention)) : array();
9696

9797
if ('/' === $logoutPath[0]) {
98-
$url = ($absolute ? $this->request->getUriForPath($logoutPath) : $this->request->getBasePath() . $logoutPath);
98+
$request = $this->container->get('request');
99+
100+
$url = ($absolute ? $request->getUriForPath($logoutPath) : $request->getBasePath() . $logoutPath);
99101

100102
if (!empty($parameters)) {
101103
$url .= '?' . http_build_query($parameters);

0 commit comments

Comments
 (0)