Mercurial > hg > isophonics-drupal-site
comparison core/modules/system/src/Controller/CsrfTokenController.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\system\Controller; | |
4 | |
5 use Drupal\Core\Access\CsrfRequestHeaderAccessCheck; | |
6 use Drupal\Core\Access\CsrfTokenGenerator; | |
7 use Drupal\Core\DependencyInjection\ContainerInjectionInterface; | |
8 use Symfony\Component\DependencyInjection\ContainerInterface; | |
9 use Symfony\Component\HttpFoundation\Response; | |
10 | |
11 /** | |
12 * Returns responses for CSRF token routes. | |
13 */ | |
14 class CsrfTokenController implements ContainerInjectionInterface { | |
15 | |
16 /** | |
17 * The CSRF token generator. | |
18 * | |
19 * @var \Drupal\Core\Access\CsrfTokenGenerator | |
20 */ | |
21 protected $tokenGenerator; | |
22 | |
23 /** | |
24 * Constructs a new CsrfTokenController object. | |
25 * | |
26 * @param \Drupal\Core\Access\CsrfTokenGenerator $token_generator | |
27 * The CSRF token generator. | |
28 */ | |
29 public function __construct(CsrfTokenGenerator $token_generator) { | |
30 $this->tokenGenerator = $token_generator; | |
31 } | |
32 | |
33 /** | |
34 * {@inheritdoc} | |
35 */ | |
36 public static function create(ContainerInterface $container) { | |
37 return new static( | |
38 $container->get('csrf_token') | |
39 ); | |
40 } | |
41 | |
42 /** | |
43 * Returns a CSRF protecting session token. | |
44 * | |
45 * @return \Symfony\Component\HttpFoundation\Response | |
46 * The response object. | |
47 */ | |
48 public function csrfToken() { | |
49 return new Response($this->tokenGenerator->get(CsrfRequestHeaderAccessCheck::TOKEN_KEY), 200, ['Content-Type' => 'text/plain']); | |
50 } | |
51 | |
52 } |