Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Routing/RequestContext.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\Core\Routing; | |
4 | |
5 use Symfony\Component\HttpFoundation\Request; | |
6 use Symfony\Component\HttpFoundation\RequestStack; | |
7 use Symfony\Component\Routing\RequestContext as SymfonyRequestContext; | |
8 | |
9 /** | |
10 * Holds information about the current request. | |
11 * | |
12 * @todo: Remove once the upstream RequestContext provides fromRequestStack(): | |
13 * https://github.com/symfony/symfony/issues/12057 | |
14 */ | |
15 class RequestContext extends SymfonyRequestContext { | |
16 | |
17 /** | |
18 * The scheme, host and base path, for example "http://example.com/d8". | |
19 * | |
20 * @var string | |
21 */ | |
22 protected $completeBaseUrl; | |
23 | |
24 /** | |
25 * Populates the context from the current request from the request stack. | |
26 * | |
27 * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack | |
28 * The current request stack. | |
29 */ | |
30 public function fromRequestStack(RequestStack $request_stack) { | |
31 $this->fromRequest($request_stack->getCurrentRequest()); | |
32 } | |
33 | |
34 /** | |
35 * {@inheritdoc} | |
36 */ | |
37 public function fromRequest(Request $request) { | |
38 parent::fromRequest($request); | |
39 | |
40 // @todo Extract the code in DrupalKernel::initializeRequestGlobals. | |
41 // See https://www.drupal.org/node/2404601 | |
42 if (isset($GLOBALS['base_url'])) { | |
43 $this->setCompleteBaseUrl($GLOBALS['base_url']); | |
44 } | |
45 } | |
46 | |
47 /** | |
48 * Gets the scheme, host and base path. | |
49 * | |
50 * For example, in an installation in a subdirectory "d8", it should be | |
51 * "https://example.com/d8". | |
52 */ | |
53 public function getCompleteBaseUrl() { | |
54 return $this->completeBaseUrl; | |
55 } | |
56 | |
57 /** | |
58 * Sets the complete base URL for the Request context. | |
59 * | |
60 * @param string $complete_base_url | |
61 * The complete base URL. | |
62 */ | |
63 public function setCompleteBaseUrl($complete_base_url) { | |
64 $this->completeBaseUrl = $complete_base_url; | |
65 } | |
66 | |
67 } |