ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
LegacyDelivery.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
29 final class LegacyDelivery extends BaseDelivery
30 {
31  public function attached(
32  string $path_to_file,
33  ?string $download_file_name = null,
34  ?string $mime_type = null,
35  ?bool $delete_file = false
36  ): never {
37  $this->deliver(
38  $path_to_file,
39  Disposition::ATTACHMENT,
41  $mime_type,
43  );
44  }
45 
46  public function inline(
47  string $path_to_file,
48  ?string $download_file_name = null,
49  ?string $mime_type = null,
50  ?bool $delete_file = false
51  ): never {
52  $this->deliver(
53  $path_to_file,
54  Disposition::INLINE,
55  $download_file_name,
56  $mime_type,
57  $delete_file
58  );
59  }
60 
61  protected function deliver(
62  string $path_to_file,
64  ?string $download_file_name = null,
65  ?string $mime_type = null,
66  ?bool $delete_file = false
67  ): never {
68  $r = $this->setGeneralHeaders(
69  $this->http->response(),
71  $mime_type ?? mime_content_type($path_to_file),
72  $download_file_name ?? basename($path_to_file),
74  );
75  $r = $this->response_builder->buildForStream(
76  $this->http->request(),
77  $r,
78  Streams::ofResource(fopen($path_to_file, 'rb'))
79  );
80  $this - $this->saveAndClose($r, $delete_file ? $path_to_file : null);
81  }
82 }
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)
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.
saveAndClose(ResponseInterface $r, string $path_to_delete=null)
$r