forked from speckcommerce/SpeckMultisite
/
DomainResolver.php
49 lines (39 loc) · 1.15 KB
/
DomainResolver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace SpeckMultisite\Service;
use Zend\Session\Container as SessionContainer,
Zend\Http\PhpEnvironment\Response as HttpResponse,
Zend\EventManager\StaticEventManager;
class DomainResolver
{
const DOMAIN_UNRESOLVED = 'UNRESOLVED';
const DOMAIN_UNKNOWN = 'UNKNOWN';
/**
* Array that maps url, to site id's
* @var array
*/
protected $domainMap = array();
/**
* Identifier for the resolved domain
*
* @var string
*/
protected $resolvedDomain = null;
/**
* Resolves on which siteDomain we currently are viewing
*/
public function resolveSiteDomain(\Zend\Http\Request $request)
{
$host = $request->getServer()->HTTP_HOST;
if (!in_array($host, array_keys($this->domainMap)))
$this->resolvedDomain = self::DOMAIN_UNKNOWN;
else
$this->resolvedDomain = strtoupper ($this->domainMap[$host]);
}
public function setDomainMap(\Zend\Config\Config $domainMap) {
$this->domainMap = $domainMap->toArray();
}
public function getDomain()
{
return $this->resolvedDomain ?: self::DOMAIN_UNRESOLVED;
}
}