ILIAS  release_8 Revision v8.24
XSendfile.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
9
10/******************************************************************************
11 *
12 * This file is part of ILIAS, a powerful learning management system.
13 *
14 * ILIAS is licensed with the GPL-3.0, you should have received a copy
15 * of said license along with the source code.
16 *
17 * If this is not the case or you just want to try ILIAS, you'll find
18 * us at:
19 * https://www.ilias.de
20 * https://github.com/ILIAS-eLearning
21 *
22 *****************************************************************************/
30final class XSendfile implements ilFileDeliveryType
31{
32 use HeaderBasedDeliveryHelper;
33 public const X_SENDFILE = 'X-Sendfile';
34 public const X_SENDFILE_TEMPORARY = 'X-Sendfile-Temporary';
35 private \ILIAS\HTTP\Services $httpService;
36
37
44 public function __construct(Services $httpState)
45 {
46 $this->httpService = $httpState;
47 }
48
49
53 public function doesFileExists(string $path_to_file): bool
54 {
55 return is_readable($path_to_file);
56 }
57
58
62 public function prepare(string $path_to_file): bool
63 {
64 // Nothing has to be done here
65 return true;
66 }
67
68
72 public function deliver(string $path_to_file, bool $file_marked_to_delete): void
73 {
74 $delivery = function () use ($path_to_file): void {
75 $response = $this->httpService->response()
76 ->withHeader(self::X_SENDFILE, realpath($path_to_file));
77 $this->httpService->saveResponse($response);
78 $this->httpService->sendResponse();
79 };
80
81 if ($file_marked_to_delete) {
82 $this->sendFileUnbufferedUsingHeaders($delivery);
83 } else {
84 $delivery();
85 }
86 }
87
88
92 public function supportsInlineDelivery(): bool
93 {
94 return true;
95 }
96
97
101 public function supportsAttachmentDelivery(): bool
102 {
103 return true;
104 }
105
106
110 public function supportsStreaming(): bool
111 {
112 return true;
113 }
114
115
119 public function handleFileDeletion(string $path_to_file): bool
120 {
121 return unlink($path_to_file);
122 }
123}
deliver(string $path_to_file, bool $file_marked_to_delete)
void
Definition: XSendfile.php:72
handleFileDeletion(string $path_to_file)
bool
Definition: XSendfile.php:119
doesFileExists(string $path_to_file)
@inheritDoc
Definition: XSendfile.php:53
__construct(Services $httpState)
PHP constructor.
Definition: XSendfile.php:44
Class Services.
Definition: Services.php:38
$response