public function process(RequestInterface $request)
{
$dispatch = $this->dispatch;
$done = $this->nextDelegate;
$request = $this->resetPath($request);
// No middleware remains; done
if ($this->queue->isEmpty()) {
return $this->dispatchNextDelegate($done, $request);
}
$layer = $this->queue->dequeue();
$path = $request->getUri()->getPath() ?: '/';
$route = $layer->path;
$normalizedRoute = strlen($route) > 1 ? rtrim($route, '/') : $route;
// Skip if layer path does not match current url
if (substr(strtolower($path), 0, strlen($normalizedRoute)) !== strtolower($normalizedRoute)) {
return $this->process($request);
}
// Skip if match is not at a border ('/', '.', or end)
$border = $this->getBorder($path, $normalizedRoute);
if ($border && '/' !== $border && '.' !== $border) {
return $this->process($request);
}
// Trim off the part of the url that matches the layer route
if (!empty($route) && $route !== '/') {
$request = $this->stripRouteFromPath($request, $route);
}
$result = $dispatch->process($layer, $request, $this);
if (!$result instanceof ResponseInterface) {
return $this->getResponsePrototype();
}
return $result;
}