ILIAS  release_8 Revision v8.24
BaseHTTPResponseBasedConsumer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
33{
34 // Firefox determines the content type from the file content anyway for some content.
36 private \ILIAS\HTTP\Services $http;
37
38 public function __construct(
39 \ILIAS\HTTP\Services $http,
43 ) {
44 $this->http = $http;
46 }
47
48 abstract protected function getDisposition(): string;
49
50 public function run(): void
51 {
52 $revision = $this->getRevision();
53 $filename_with_extension = $this->file_name ?? $revision->getInformation()->getTitle();
54 $extension = pathinfo($filename_with_extension, PATHINFO_EXTENSION);
55 $file_name_for_consumer = $this->file_name_policy->prepareFileNameForConsumer($filename_with_extension);
56
57 // Build Response
58 $response = $this->http->response();
59 if ($this->file_name_policy->isValidExtension($extension)) {
60 $response = $response->withHeader(ResponseHeader::CONTENT_TYPE, $revision->getInformation()->getMimeType());
61 } else {
63 $response = $response->withHeader(ResponseHeader::CONTENT_TYPE, self::NON_VALID_EXTENSION_MIME);
64 }
65
66 $response = $response->withHeader(ResponseHeader::CONNECTION, 'close');
68 $response = $response->withHeader(
70 $this->getDisposition()
71 . '; filename="'
72 . $file_name_for_consumer
73 . '"'
74 );
75 $revision = $this->stream_access->populateRevision($revision);
76
77 $response = $response->withBody($revision->maybeGetToken()->resolveStream());
78
79 $this->http->saveResponse($response);
80 $this->http->sendResponse();
81 $this->http->close();
82 }
83}
__construct(\ILIAS\HTTP\Services $http, StorableResource $resource, StreamAccess $stream_access, FileNamePolicy $file_name_policy)
Interface ResponseHeader.
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
$response