8000 Add workaround for symfony/symfony#23411 · pamil/Sylius@951e26d · GitHub
[go: up one dir, main page]

Skip to content

Commit 951e26d

Browse files
committed
Add workaround for symfony/symfony#23411
1 parent 79a5285 commit 951e26d

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

src/Sylius/Bundle/UserBundle/Authentication/AuthenticationSuccessHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\HttpFoundation\JsonResponse;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
17-
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
1817

1918
/**
2019
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2 10000 +
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Sylius\Bundle\UserBundle\Authentication;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler as SymfonyDefaultAuthenticationSuccessHandler;
16+
use Symfony\Component\Security\Http\ParameterBagUtils;
17+
use Symfony\Component\Security\Http\Util\TargetPathTrait;
18+
19+
/**
20+
* TODO: Workaround for regression introduced in Symfony 3.3. To be deleted when fixed.
21+
*
22+
* @see https://github.com/symfony/symfony/pull/23411
23+
* @see https://github.com/symfony/symfony/pull/23061
24+
*
25+
* @internal
26+
*
27+
* {@inheritdoc}
28+
*/
29+
class DefaultAuthenticationSuccessHandler extends SymfonyDefaultAuthenticationSuccessHandler
30+
{
31+
use TargetPathTrait;
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
protected function determineTargetUrl(Request $request)
37+
{
38+
if ($this->options['always_use_default_target_path']) {
39+
return $this->options['default_target_path'];
40+
}
41+
42+
if ($targetUrl = ParameterBagUtils::getRequestParameterValue($request, $this->options['target_path_parameter'])) {
43+
return $targetUrl;
44+
}
45+
46+
if (null !== $this->providerKey && $targetUrl = $this->getTargetPath($request->getSession(), $this->providerKey)) {
47+
$this->removeTargetPath($request->getSession(), $this->providerKey);
48+
49+
return $targetUrl;
50+
}
51+
52+
if ($this->options['use_referer'] && ($targetUrl = $request->headers->get('Referer')) && parse_url($targetUrl, PHP_URL_PATH) !== parse_url($this->httpUtils->generateUri($request, $this->options['login_path']), PHP_URL_PATH)) {
53+
return $targetUrl;
54+
}
55+
56+
return $this->options['default_target_path'];
57+
}
58+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Sylius\Bundle\UserBundle\DependencyInjection\Compiler;
13+
14+
use Sylius\Bundle\UserBundle\Authentication\DefaultAuthenticationSuccessHandler as SyliusDefaultAuthenticationSuccessHandler;
15+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler as SymfonyDefaultAuthenticationSuccessHandler;
18+
19+
/**
20+
* @see SyliusDefaultAuthenticationSuccessHandler
21+
*
22+
* @internal
23+
*/
24+
final class SymfonyCompatibilityPass implements CompilerPassInterface
25+
{
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function process(ContainerBuilder $container)
30+
{
31+
foreach ($container->getDefinitions() as $definition) {
32+
if ($definition->getClass() === SymfonyDefaultAuthenticationSuccessHandler::class) {
33+
$definition->setClass(SyliusDefaultAuthenticationSuccessHandler::class);
34+
}
35+
}
36+
}
37+
}

src/Sylius/Bundle/UserBundle/SyliusUserBundle.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Sylius\Bundle\ResourceBundle\AbstractResourceBundle;
1515
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
16+
use Sylius\Bundle\UserBundle\DependencyInjection\Compiler\SymfonyCompatibilityPass;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1618

1719
/**
1820
* @author Paweł Jędrzejewski <pawel@sylius.org>
@@ -29,6 +31,16 @@ public function getSupportedDrivers()
2931
];
3032
}
3133

34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function build(ContainerBuilder $container)
38+
{
39+
parent::build($container);
40+
41+
$container->addCompilerPass(new SymfonyCompatibilityPass());
42+
}
43+
3244
/**
3345
* {@inheritdoc}
3446
*/

0 commit comments

Comments
 (0)
0