ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
BaseHTTPResponseBasedConsumer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
32 {
33  // Firefox determines the content type from the file content anyway for some content.
35  private \ILIAS\HTTP\Services $http;
36  private \ILIAS\FileDelivery\Delivery\StreamDelivery $delivery;
37 
38  public function __construct(
39  \ILIAS\HTTP\Services $http,
43  ) {
44  global $DIC;
45  $this->delivery = $DIC->fileDelivery()->delivery();
46  parent::__construct($resource, $stream_access, $file_name_policy);
47  }
48 
49  abstract protected function getDisposition(): string;
50 
51  public function run(): void
52  {
53  $revision = $this->getRevision();
54  $filename_with_extension = $this->file_name ?? $revision->getInformation()->getTitle();
55  $extension = pathinfo($filename_with_extension, PATHINFO_EXTENSION);
56  $file_name_for_consumer = $this->file_name_policy->prepareFileNameForConsumer($filename_with_extension);
57 
58  $mime_type = $this->file_name_policy->isValidExtension($extension)
59  ? $revision->getInformation()->getMimeType()
60  : self::NON_VALID_EXTENSION_MIME;
61 
62  // Build Response
63  $revision = $this->stream_access->populateRevision($revision);
64 
65  switch ($this->getDisposition()) {
66  case 'attachment':
67  $this->delivery->attached(
68  $revision->maybeStreamResolver()?->getStream(),
69  $file_name_for_consumer,
70  $mime_type
71  );
72  break;
73  case 'inline':
74  $this->delivery->inline(
75  $revision->maybeStreamResolver()?->getStream(),
76  $file_name_for_consumer,
77  $mime_type
78  );
79  break;
80  default:
81  throw new \InvalidArgumentException('Invalid disposition');
82  }
83  }
84 }
__construct(\ILIAS\HTTP\Services $http, StorableResource $resource, StreamAccess $stream_access, FileNamePolicy $file_name_policy)
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)