ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 {
38  public const DATA = 'data';
39  public const SECURED_DATA = 'secured-data';
40  private \ILIAS\HTTP\Services $httpService;
41  public const X_ACCEL_REDIRECT = 'X-Accel-Redirect';
42 
43 
49  public function __construct(Services $httpState)
50  {
51  $this->httpService = $httpState;
52  }
53 
57  public function doesFileExists(string $path_to_file): bool
58  {
59  return is_readable($path_to_file);
60  }
61 
62 
63 
67  public function prepare(string $path_to_file, ?FileStream $possible_stream): bool
68  {
69  $response = $this->httpService->response()->withHeader(ResponseHeader::CONTENT_TYPE, '');
70 
71  $this->httpService->saveResponse($response);
72 
73  return true;
74  }
75 
76 
80  public function deliver(string $path_to_file, bool $file_marked_to_delete): void
81  {
82  // There is currently no way to delete the file after delivery
83  if (strpos($path_to_file, './' . self::DATA . '/') === 0) {
84  $path_to_file = str_replace('./' . self::DATA . '/', '/' . self::SECURED_DATA
85  . '/', $path_to_file);
86  }
87 
88  $response = $this->httpService->response();
89  $delivery = function () use ($path_to_file, $response): void {
90  $response = $response->withHeader(self::X_ACCEL_REDIRECT, $path_to_file);
91  $this->httpService->saveResponse($response);
92  $this->httpService->sendResponse();
93  };
94 
95  if ($file_marked_to_delete) {
96  $this->sendFileUnbufferedUsingHeaders($delivery);
97  } else {
98  $delivery();
99  }
100  }
101 
102 
106  public function supportsInlineDelivery(): bool
107  {
108  return true;
109  }
110 
111 
115  public function supportsAttachmentDelivery(): bool
116  {
117  return true;
118  }
119 
120 
124  public function supportsStreaming(): bool
125  {
126  return true;
127  }
128 
129 
133  public function handleFileDeletion(string $path_to_file): bool
134  {
135  // No possibilities to do this at the moment
136  return true;
137  }
138 }
__construct(Services $httpState)
PHP constructor.
Definition: XAccel.php:49
prepare(string $path_to_file, ?FileStream $possible_stream)
bool
Definition: XAccel.php:67
doesFileExists(string $path_to_file)
Definition: XAccel.php:57
$response
Definition: xapitoken.php:93
handleFileDeletion(string $path_to_file)
bool
Definition: XAccel.php:133
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:80
The base interface for all filesystem streams.
Definition: FileStream.php:31