1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Platine\App\Http\Action\User; |
6
|
|
|
|
7
|
|
|
use Platine\Framework\Auth\AuthenticationInterface; |
8
|
|
|
use Platine\Framework\Helper\Flash; |
9
|
|
|
use Platine\Framework\Http\Response\RedirectResponse; |
10
|
|
|
use Platine\Framework\Http\RouteHelper; |
11
|
|
|
use Platine\Http\Handler\RequestHandlerInterface; |
12
|
|
|
use Platine\Http\ResponseInterface; |
13
|
|
|
use Platine\Http\ServerRequestInterface; |
14
|
|
|
use Platine\Lang\Lang; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @class LogoutAction |
18
|
|
|
* @package Platine\App\Http\Action\User |
19
|
|
|
*/ |
20
|
|
|
class LogoutAction implements RequestHandlerInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The AuthenticationInterface instance |
24
|
|
|
* @var AuthenticationInterface |
25
|
|
|
*/ |
26
|
|
|
protected AuthenticationInterface $authentication; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The Flash instance |
30
|
|
|
* @var Flash |
31
|
|
|
*/ |
32
|
|
|
protected Flash $flash; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The RouteHelper instance |
36
|
|
|
* @var RouteHelper |
37
|
|
|
*/ |
38
|
|
|
protected RouteHelper $routeHelper; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The Lang instance |
42
|
|
|
* @var Lang |
43
|
|
|
*/ |
44
|
|
|
protected Lang $lang; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Create new instance |
48
|
|
|
* @param AuthenticationInterface $authentication |
49
|
|
|
* @param Flash $flash |
50
|
|
|
* @param RouteHelper $routeHelper |
51
|
|
|
* @param Lang $lang |
52
|
|
|
*/ |
53
|
|
|
public function __construct( |
54
|
|
|
AuthenticationInterface $authentication, |
55
|
|
|
Flash $flash, |
56
|
|
|
RouteHelper $routeHelper, |
57
|
|
|
Lang $lang |
58
|
|
|
) { |
59
|
|
|
$this->authentication = $authentication; |
60
|
|
|
$this->flash = $flash; |
61
|
|
|
$this->routeHelper = $routeHelper; |
62
|
|
|
$this->lang = $lang; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function handle(ServerRequestInterface $request): ResponseInterface |
69
|
|
|
{ |
70
|
|
|
$this->authentication->logout(); |
71
|
|
|
|
72
|
|
|
$this->flash->setInfo($this->lang->tr('You are successfully logged out')); |
73
|
|
|
|
74
|
|
|
return new RedirectResponse( |
75
|
|
|
$this->routeHelper->generateUrl('user_login') |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|