public function __invoke(HttpRequest $request, HttpResponse $response) { $path = $this->path . substr($request->getUrl(), 1); $fn = $this->filter; if ($fn($path)) { $response->setContentEncoding(HttpResponse::GZIP); if (is_dir($path) && $this->hasIndex) { // serve the index of the specified path $fn = $this->index; $response->setContentType('text/html'); $response->setBody($fn($path)); } else { if (is_file($path)) { $response->setContentType($this->finfo->file($path, FILEINFO_MIME_TYPE)); $response->setBody(fopen($path, 'r')); } } } }