|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
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 Symfony\Component\Security\Http\Logout; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
|
|
15 |
use Symfony\Component\HttpFoundation\Response; |
|
|
16 |
use Symfony\Component\HttpFoundation\Request; |
|
|
17 |
|
|
|
18 |
/** |
|
|
19 |
* This handler clears the passed cookies when a user logs out. |
|
|
20 |
* |
|
|
21 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
22 |
*/ |
|
|
23 |
class CookieClearingLogoutHandler implements LogoutHandlerInterface |
|
|
24 |
{ |
|
|
25 |
private $cookies; |
|
|
26 |
|
|
|
27 |
/** |
|
|
28 |
* Constructor |
|
|
29 |
* @param array $cookies An array of cookie names to unset |
|
|
30 |
*/ |
|
|
31 |
public function __construct(array $cookies) |
|
|
32 |
{ |
|
|
33 |
$this->cookies = $cookies; |
|
|
34 |
} |
|
|
35 |
|
|
|
36 |
/** |
|
|
37 |
* Implementation for the LogoutHandlerInterface. Deletes all requested cookies. |
|
|
38 |
* |
|
|
39 |
* @param Request $request |
|
|
40 |
* @param Response $response |
|
|
41 |
* @param TokenInterface $token |
|
|
42 |
* @return void |
|
|
43 |
*/ |
|
|
44 |
public function logout(Request $request, Response $response, TokenInterface $token) |
|
|
45 |
{ |
|
|
46 |
foreach ($this->cookies as $cookieName => $cookieData) { |
|
|
47 |
$response->headers->clearCookie($cookieName, $cookieData['path'], $cookieData['domain']); |
|
|
48 |
} |
|
|
49 |
} |
|
|
50 |
} |