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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\ShopBundle\EventListener; |
15
|
|
|
|
16
|
|
|
use Sylius\Bundle\ShopBundle\ShopSession; |
17
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
20
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
21
|
|
|
use Symfony\Component\Security\Http\HttpUtils; |
22
|
|
|
use Symfony\Component\Security\Http\Logout\DefaultLogoutSuccessHandler; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Mateusz Zalewski <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
final class ShopUserLogoutHandler extends DefaultLogoutSuccessHandler |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var SessionInterface |
31
|
|
|
*/ |
32
|
|
|
private $session; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ChannelContextInterface |
36
|
|
|
*/ |
37
|
|
|
private $channelContext; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
* |
42
|
|
|
* @param SessionInterface $session |
43
|
|
|
* @param ChannelContextInterface $channelContext |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
HttpUtils $httpUtils, |
47
|
|
|
string $targetUrl, |
48
|
|
|
SessionInterface $session, |
49
|
|
|
ChannelContextInterface $channelContext |
50
|
|
|
) { |
51
|
|
|
parent::__construct($httpUtils, $targetUrl); |
52
|
|
|
|
53
|
|
|
$this->session = $session; |
54
|
|
|
$this->channelContext = $channelContext; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function onLogoutSuccess(Request $request): Response |
61
|
|
|
{ |
62
|
|
|
$channel = $this->channelContext->getChannel(); |
63
|
|
|
$this->session->remove('_sylius.cart.' . $channel->getCode()); |
64
|
|
|
|
65
|
|
|
return parent::onLogoutSuccess($request); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|