1 | <?php |
||
21 | class TenantResolver implements TenantResolverInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $domain; |
||
27 | |||
28 | /** |
||
29 | * @var TenantRepositoryInterface |
||
30 | */ |
||
31 | private $tenantRepository; |
||
32 | |||
33 | /** |
||
34 | * Construct. |
||
35 | * |
||
36 | * @param string $domain |
||
37 | * @param TenantRepositoryInterface $tenantRepository |
||
38 | */ |
||
39 | public function __construct($domain, TenantRepositoryInterface $tenantRepository) |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public function resolve($host = null) |
||
49 | { |
||
50 | // fallback to default tenant |
||
51 | if (null === $host) { |
||
52 | $host = self::DEFAULT_TENANT; |
||
53 | } |
||
54 | |||
55 | $subdomain = $this->extractSubdomain($host); |
||
56 | |||
57 | return $this->tenantRepository->findBySubdomain($subdomain); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Extracts subdomain from the host. |
||
62 | * |
||
63 | * @param string $host Hostname |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | protected function extractSubdomain($host) |
||
81 | } |
||
82 |