Skip to content

Commit

Permalink
TASK: Improve readability of SiteDetectionMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 9, 2023
1 parent 936860d commit ba013ef
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,16 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$requestUriHost = $request->getUri()->getHost();
try {
if (!empty($requestUriHost)) {
// try to get site by domain
$activeDomain = $this->domainRepository->findOneByHost($requestUriHost, true);
if ($activeDomain !== null) {
$site = $activeDomain->getSite();
}
$site = $activeDomain?->getSite();
}
if ($site === null) {
// try to get any site
$site = $this->siteRepository->findFirstOnline();
}
} catch (DatabaseException) {
// doctrine might have not been migrated yet or not database exists.
// this doesn't have to be handled here, and we should allow other middlewares / routes to work
return $handler->handle($request);
// doctrine might have not been migrated yet or no database is connected.
}

if (!$site instanceof Site) {
Expand Down

0 comments on commit ba013ef

Please sign in to comment.