Psr7Middlewares\Middleware\BasePath::__invoke PHP Method

__invoke() public method

Execute the middleware.
public __invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
$next callable
return Psr\Http\Message\ResponseInterface
    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);
    }