Mercurial > hg > isophonics-drupal-site
comparison core/modules/hal/src/LinkManager/LinkManagerBase.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\hal\LinkManager; | |
4 | |
5 /** | |
6 * Defines an abstract base-class for HAL link manager objects. | |
7 */ | |
8 abstract class LinkManagerBase { | |
9 | |
10 /** | |
11 * Link domain used for type links URIs. | |
12 * | |
13 * @var string | |
14 */ | |
15 protected $linkDomain; | |
16 | |
17 /** | |
18 * Config factory service. | |
19 * | |
20 * @var \Drupal\Core\Config\ConfigFactoryInterface | |
21 */ | |
22 protected $configFactory; | |
23 | |
24 /** | |
25 * The request stack. | |
26 * | |
27 * @var \Symfony\Component\HttpFoundation\RequestStack | |
28 */ | |
29 protected $requestStack; | |
30 | |
31 /** | |
32 * {@inheritdoc} | |
33 */ | |
34 public function setLinkDomain($domain) { | |
35 $this->linkDomain = rtrim($domain, '/'); | |
36 return $this; | |
37 } | |
38 | |
39 /** | |
40 * Gets the link domain. | |
41 * | |
42 * @return string | |
43 * The link domain. | |
44 */ | |
45 protected function getLinkDomain() { | |
46 if (empty($this->linkDomain)) { | |
47 if ($domain = $this->configFactory->get('hal.settings')->get('link_domain')) { | |
48 $this->linkDomain = rtrim($domain, '/'); | |
49 } | |
50 else { | |
51 $request = $this->requestStack->getCurrentRequest(); | |
52 $this->linkDomain = $request->getSchemeAndHttpHost() . $request->getBasePath(); | |
53 } | |
54 } | |
55 return $this->linkDomain; | |
56 } | |
57 | |
58 } |