ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
XAccel.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
35 final class XAccel implements ilFileDeliveryType
36 {
41  public const DATA = 'data';
45  public const SECURED_DATA = 'secured-data';
49  public const X_ACCEL_REDIRECT = 'X-Accel-Redirect';
50 
51 
57  public function __construct(private Services $httpService)
58  {
59  }
60 
64  public function doesFileExists(string $path_to_file): bool
65  {
66  return is_readable($path_to_file);
67  }
68 
69 
70 
74  public function prepare(string $path_to_file, ?FileStream $possible_stream): bool
75  {
76  $response = $this->httpService->response()->withHeader(ResponseHeader::CONTENT_TYPE, '');
77 
78  $this->httpService->saveResponse($response);
79 
80  return true;
81  }
82 
83 
87  public function deliver(string $path_to_file, bool $file_marked_to_delete): void
88  {
89  // There is currently no way to delete the file after delivery
90  if (str_starts_with($path_to_file, './' . self::DATA . '/')) {
91  $path_to_file = str_replace('./' . self::DATA . '/', '/' . self::SECURED_DATA
92  . '/', $path_to_file);
93  }
94 
95  $response = $this->httpService->response();
96  $delivery = function () use ($path_to_file, $response): void {
97  $response = $response->withHeader(self::X_ACCEL_REDIRECT, $path_to_file);
98  $this->httpService->saveResponse($response);
99  $this->httpService->sendResponse();
100  };
101 
102  if ($file_marked_to_delete) {
103  $this->sendFileUnbufferedUsingHeaders($delivery);
104  } else {
105  $delivery();
106  }
107  }
108 
109 
113  public function supportsInlineDelivery(): bool
114  {
115  return true;
116  }
117 
118 
122  public function supportsAttachmentDelivery(): bool
123  {
124  return true;
125  }
126 
127 
131  public function supportsStreaming(): bool
132  {
133  return true;
134  }
135 
136 
140  public function handleFileDeletion(string $path_to_file): bool
141  {
142  // No possibilities to do this at the moment
143  return true;
144  }
145 }
__construct(private Services $httpService)
PHP constructor.
Definition: XAccel.php:57
prepare(string $path_to_file, ?FileStream $possible_stream)
Definition: XAccel.php:74
doesFileExists(string $path_to_file)
Definition: XAccel.php:64
$response
Definition: xapitoken.php:93
handleFileDeletion(string $path_to_file)
bool
Definition: XAccel.php:140
deliver(string $path_to_file, bool $file_marked_to_delete)
absolute path to fileThis is needed at this point for header-based delivery methodsvoid ...
Definition: XAccel.php:87
The base interface for all filesystem streams.
Definition: FileStream.php:31