public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
if ($this->autodetect) {
$this->basePath(Utils\Helpers::joinPath(self::detectBasePath($request), $this->basePath));
}
$uri = $request->getUri();
$path = $this->getPath($uri->getPath());
$request = $request->withUri($uri->withPath($path));
$generator = function ($path) {
return Utils\Helpers::joinPath($this->basePath, $path);
};
$request = self::setAttribute($request, self::KEY, $this->basePath);
$request = self::setAttribute($request, self::KEY_GENERATOR, $generator);
return $next($request, $response);
}