Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Aug 1, 2023
1 parent 96e5fa7 commit 8287e9b
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/Pipeline/EnsureMatchesDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,32 @@ public function __invoke(State $state, Closure $next): mixed
return $next($state);
}

$route = (new Route(['GET'], $this->mountPath->baseUri, fn () => null))
->domain($this->mountPath->domain)
->bind($this->request);
$route = $this->route();

if (! (new HostValidator)->matches($route, $this->request)) {
if ($this->matchesDomain($route) === false) {
return new StopIterating();
}

$state->data = array_merge($state->data, $route->parameters());
$state->data = array_merge($route->parameters(), $state->data);

return $next($state);
}

/**
* Get the route that should be used to match the request.
*/
protected function route(): Route
{
return (new Route(['GET'], $this->mountPath->baseUri, fn () => null))
->domain($this->mountPath->domain)
->bind($this->request);
}

/**
* Determine if the request matches the domain.
*/
protected function matchesDomain(Route $route): bool
{
return (bool) (new HostValidator)->matches($route, $this->request);
}
}

0 comments on commit 8287e9b

Please sign in to comment.