19 declare(strict_types=1);
54 $this->
http->saveResponse($r->withStatus(404));
55 $this->
http->sendResponse();
68 Disposition::ATTACHMENT
72 public function inline(
87 string $download_file_name,
88 ?
string $mime_type = null,
91 $r = $this->
http->response();
92 $uri = $stream->getMetadata()[
'uri'];
94 if ($stream instanceof
ZIPStream || $stream->getMetadata()[
'uri'] ===
'php://memory') {
95 $this->response_builder = $this->fallback_response_builder;
101 $mime_type ?? mime_content_type($uri),
106 $r = $this->response_builder->buildForStream(
107 $this->
http->request(),
117 $parts = explode(self::SUBREQUEST_SEPARATOR, $token);
121 $sub_request = implode(
'/', array_slice(
$parts, 1));
124 $r = $this->
http->response();
125 $payload = $this->data_signer->verifyStreamToken($token);
130 $mime_type =
$payload->getMimeType();
131 $file_name =
$payload->getFilename();
137 $file_name =
$payload->getFilename();
147 if ($sub_request === null) {
156 $this->
http->saveResponse(
157 $this->response_builder->buildForStream(
158 $this->http->request(),
164 $requested_zip = $uri;
165 $sub_request = urldecode($sub_request);
167 $sub_request = explode(
'?', $sub_request)[0];
174 $file_inside_zip_uri = $file_inside_ZIP->getMetadata()[
'uri'];
175 $file_inside_zip_stream = fopen($file_inside_zip_uri,
'rb');
177 if ($file_inside_zip_stream ===
false) {
182 $this->response_builder = $this->fallback_response_builder;
187 $file_inside_zip_uri,
189 basename($sub_request),
194 $this->
http->saveResponse(
195 $this->response_builder->buildForStream(
196 $this->http->request(),
202 $this->
http->sendResponse();
203 $this->
http->close();
208 $suffix = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
209 if (isset($this->mime_type_map[$suffix])) {
210 if (is_array($this->mime_type_map[$suffix]) && isset($this->mime_type_map[$suffix][0])) {
211 return $this->mime_type_map[$suffix][0];
214 return $this->mime_type_map[$suffix];
217 $mime_type = mime_content_type($filename);
218 if ($mime_type ===
'application/octet-stream') {
219 $mime_type = mime_content_type(substr($filename, 64));
221 return $mime_type ?:
'application/octet-stream';
setGeneralHeaders(ResponseInterface $r, string $uri, string $mime_type, string $file_name, Disposition $disposition=Disposition::INLINE)
deliver(FileStream $stream, string $download_file_name, ?string $mime_type=null, Disposition $disposition=Disposition::INLINE)
attached(FileStream $stream, string $download_file_name, ?string $mime_type=null)
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
if(count($parts) !=3) $payload
static ofFileInsideZIP(string $path_to_zip, string $path_inside_zip)
const SUBREQUEST_SEPARATOR
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
static http()
Fetches the global http state from ILIAS.
__construct(private DataSigner $data_signer, Services $http, ResponseBuilder $response_builder, ResponseBuilder $fallback_response_builder,)
determineMimeType(string $filename)
saveAndClose(ResponseInterface $r, string $path_to_delete=null)
notFound(ResponseInterface $r)
deliverFromToken(string $token)
string $download_file_name
The base interface for all filesystem streams.