ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BaseHTTPResponseBasedConsumer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29
35{
36 // Firefox determines the content type from the file content anyway for some content.
38 private Services $http;
40
41 public function __construct(
43 StorableResource $resource,
44 StreamAccess $stream_access,
45 FileNamePolicy $file_name_policy
46 ) {
47 global $DIC;
48 $this->delivery = $DIC->fileDelivery()->delivery();
49 parent::__construct($resource, $stream_access, $file_name_policy);
50 }
51
52 abstract protected function getDisposition(): string;
53
54 public function run(): void
55 {
56 $revision = $this->getRevision();
57 $filename_with_extension = $this->file_name ?? $revision->getInformation()->getTitle();
58 $extension = pathinfo($filename_with_extension, PATHINFO_EXTENSION);
59 $file_name_for_consumer = $this->file_name_policy->prepareFileNameForConsumer($filename_with_extension);
60
61 $mime_type = $this->file_name_policy->isValidExtension($extension)
62 ? $revision->getInformation()->getMimeType()
64
65 // Build Response
66 $revision = $this->stream_access->populateRevision($revision);
67
68 match ($this->getDisposition()) {
69 'attachment' => $this->delivery->attached(
70 $revision->maybeStreamResolver()?->getStream(),
71 $file_name_for_consumer,
72 $mime_type
73 ),
74 'inline' => $this->delivery->inline(
75 $revision->maybeStreamResolver()?->getStream(),
76 $file_name_for_consumer,
77 $mime_type
78 ),
79 default => throw new \InvalidArgumentException('Invalid disposition'),
80 };
81 }
82}
Mime type determination.
Definition: MimeType.php:30
Class Services.
Definition: Services.php:38
__construct(Services $http, StorableResource $resource, StreamAccess $stream_access, FileNamePolicy $file_name_policy)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26