ILIAS  release_8 Revision v8.24
ILIAS\ResourceStorage\Consumer\BaseHTTPResponseBasedConsumer Class Reference
+ Inheritance diagram for ILIAS\ResourceStorage\Consumer\BaseHTTPResponseBasedConsumer:
+ Collaboration diagram for ILIAS\ResourceStorage\Consumer\BaseHTTPResponseBasedConsumer:

Public Member Functions

 __construct (\ILIAS\HTTP\Services $http, StorableResource $resource, StreamAccess $stream_access, FileNamePolicy $file_name_policy)
 
 run ()
 This runs the actual DeliveryConsumer. More...
 
- Public Member Functions inherited from ILIAS\ResourceStorage\Consumer\BaseConsumer
 __construct (StorableResource $resource, StreamAccess $stream_access, FileNamePolicy $file_name_policy)
 DownloadConsumer constructor. More...
 
 run ()
 This runs the actual DeliveryConsumer. More...
 
 setRevisionNumber (int $revision_number)
 @inheritDoc More...
 
 overrideFileName (string $file_name)
 
 run ()
 This runs the actual DeliveryConsumer. More...
 
 setRevisionNumber (int $revision_number)
 
 overrideFileName (string $file_name)
 

Protected Member Functions

 getDisposition ()
 

Private Attributes

const NON_VALID_EXTENSION_MIME = \ILIAS\FileUpload\MimeType::APPLICATION__OCTET_STREAM
 
ILIAS HTTP Services $http
 

Additional Inherited Members

- Protected Attributes inherited from ILIAS\ResourceStorage\Consumer\BaseConsumer
int $revision_number = null
 
string $file_name = ''
 
StorableResource $resource
 
StreamAccess $stream_access
 
FileNamePolicy $file_name_policy
 

Detailed Description

Definition at line 32 of file BaseHTTPResponseBasedConsumer.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\ResourceStorage\Consumer\BaseHTTPResponseBasedConsumer::__construct ( \ILIAS\HTTP\Services  $http,
StorableResource  $resource,
StreamAccess  $stream_access,
FileNamePolicy  $file_name_policy 
)

Member Function Documentation

◆ getDisposition()

ILIAS\ResourceStorage\Consumer\BaseHTTPResponseBasedConsumer::getDisposition ( )
abstractprotected

◆ run()

ILIAS\ResourceStorage\Consumer\BaseHTTPResponseBasedConsumer::run ( )

This runs the actual DeliveryConsumer.

E.g. a DownloadConsumer will pass the Stream of a Ressource to the HTTP-Service and download the file.

Reimplemented from ILIAS\ResourceStorage\Consumer\BaseConsumer.

Definition at line 50 of file BaseHTTPResponseBasedConsumer.php.

50 : 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 }
$response

References $response, ILIAS\HTTP\Response\ResponseHeader\ACCEPT_RANGES, ILIAS\HTTP\Response\ResponseHeader\CONNECTION, ILIAS\HTTP\Response\ResponseHeader\CONTENT_DISPOSITION, ILIAS\HTTP\Response\ResponseHeader\CONTENT_TYPE, ILIAS\ResourceStorage\Consumer\BaseHTTPResponseBasedConsumer\getDisposition(), ILIAS\FileDelivery\http(), and ILIAS\HTTP\Response\ResponseHeader\X_CONTENT_TYPE_OPTIONS.

+ Here is the call graph for this function:

Field Documentation

◆ $http

ILIAS HTTP Services ILIAS\ResourceStorage\Consumer\BaseHTTPResponseBasedConsumer::$http
private

◆ NON_VALID_EXTENSION_MIME

const ILIAS\ResourceStorage\Consumer\BaseHTTPResponseBasedConsumer::NON_VALID_EXTENSION_MIME = \ILIAS\FileUpload\MimeType::APPLICATION__OCTET_STREAM
private

Definition at line 35 of file BaseHTTPResponseBasedConsumer.php.


The documentation for this class was generated from the following file: