Conditions | 9 |
Paths | 20 |
Total Lines | 33 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
28 | public function resolve(RequestContext $requestContext): SiteInterface |
||
29 | { |
||
30 | $matches = []; |
||
31 | |||
32 | if (preg_match('#^/([^/]+)/?#', $requestContext->getPathInfo(), $matches) > 0) { |
||
33 | $identifier = $matches[1]; |
||
34 | } else { |
||
35 | $identifier = $this->defaultIdentifier; |
||
36 | } |
||
37 | |||
38 | if (empty($identifier)) { |
||
39 | throw SiteNotFoundException::withRequestContext($requestContext); |
||
40 | } |
||
41 | |||
42 | foreach ($this->siteRepository->findAll() as $site) { |
||
43 | if (!$site instanceof IdentifiedSiteInterface) { |
||
44 | continue; |
||
45 | } |
||
46 | |||
47 | if ($site->matches($identifier)) { |
||
48 | return $site; |
||
49 | } |
||
50 | |||
51 | if ($site->matches($this->defaultIdentifier)) { |
||
|
|||
52 | $defaultSite = $site; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | if (!empty($defaultSite) && $defaultSite instanceof IdentifiedSiteInterface) { |
||
57 | return $defaultSite; |
||
58 | } |
||
59 | |||
60 | throw SiteNotFoundException::withRequestContext($requestContext); |
||
61 | } |
||
63 |