ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
LegacyDelivery.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
28 final class LegacyDelivery extends BaseDelivery
29 {
30  public function attached(
31  string $path_to_file,
32  ?string $download_file_name = null,
33  ?string $mime_type = null,
34  ?bool $delete_file = false
35  ): never {
36  $this->deliver(
37  $path_to_file,
38  Disposition::ATTACHMENT,
40  $mime_type,
42  );
43  }
44 
45  public function inline(
46  string $path_to_file,
47  ?string $download_file_name = null,
48  ?string $mime_type = null,
49  ?bool $delete_file = false
50  ): never {
51  $this->deliver(
52  $path_to_file,
53  Disposition::INLINE,
54  $download_file_name,
55  $mime_type,
56  $delete_file
57  );
58  }
59 
60  protected function deliver(
61  string $path_to_file,
63  ?string $download_file_name = null,
64  ?string $mime_type = null,
65  ?bool $delete_file = false
66  ): never {
67  $r = $this->setGeneralHeaders(
68  $this->http->response(),
70  $mime_type ?? mime_content_type($path_to_file),
71  $download_file_name ?? basename($path_to_file),
73  );
74  $r = $this->response_builder->buildForStream(
75  $this->http->request(),
76  $r,
77  Streams::ofResource(fopen($path_to_file, 'rb'))
78  );
79  $this - $this->saveAndClose($r, $delete_file ? $path_to_file : null);
80  }
81 }
setGeneralHeaders(ResponseInterface $r, string $uri, string $mime_type, string $file_name, Disposition $disposition=Disposition::INLINE)
attached(string $path_to_file, ?string $download_file_name=null, ?string $mime_type=null, ?bool $delete_file=false)
saveAndClose(ResponseInterface $r, ?string $path_to_delete=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
deliver(string $path_to_file, Disposition $disposition, ?string $download_file_name=null, ?string $mime_type=null, ?bool $delete_file=false)
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:64
static http()
Fetches the global http state from ILIAS.
$r