ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
XAccel.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
10 
11 /******************************************************************************
12  *
13  * This file is part of ILIAS, a powerful learning management system.
14  *
15  * ILIAS is licensed with the GPL-3.0, you should have received a copy
16  * of said license along with the source code.
17  *
18  * If this is not the case or you just want to try ILIAS, you'll find
19  * us at:
20  * https://www.ilias.de
21  * https://github.com/ILIAS-eLearning
22  *
23  *****************************************************************************/
31 final class XAccel implements ilFileDeliveryType
32 {
34  public const DATA = 'data';
35  public const SECURED_DATA = 'secured-data';
36  private \ILIAS\HTTP\Services $httpService;
37  public const X_ACCEL_REDIRECT = 'X-Accel-Redirect';
38 
39 
45  public function __construct(Services $httpState)
46  {
47  $this->httpService = $httpState;
48  }
49 
53  public function doesFileExists(string $path_to_file): bool
54  {
55  return is_readable($path_to_file);
56  }
57 
58 
59 
63  public function prepare(string $path_to_file): bool
64  {
65  $response = $this->httpService->response()->withHeader(ResponseHeader::CONTENT_TYPE, '');
66 
67  $this->httpService->saveResponse($response);
68 
69  return true;
70  }
71 
72 
76  public function deliver(string $path_to_file, bool $file_marked_to_delete): void
77  {
78  // There is currently no way to delete the file after delivery
79  if (strpos($path_to_file, './' . self::DATA . '/') === 0) {
80  $path_to_file = str_replace('./' . self::DATA . '/', '/' . self::SECURED_DATA
81  . '/', $path_to_file);
82  }
83 
84  $response = $this->httpService->response();
85  $delivery = function () use ($path_to_file, $response): void {
86  $response = $response->withHeader(self::X_ACCEL_REDIRECT, $path_to_file);
87  $this->httpService->saveResponse($response);
88  $this->httpService->sendResponse();
89  };
90 
91  if ($file_marked_to_delete) {
92  $this->sendFileUnbufferedUsingHeaders($delivery);
93  } else {
94  $delivery();
95  }
96  }
97 
98 
102  public function supportsInlineDelivery(): bool
103  {
104  return true;
105  }
106 
107 
111  public function supportsAttachmentDelivery(): bool
112  {
113  return true;
114  }
115 
116 
120  public function supportsStreaming(): bool
121  {
122  return true;
123  }
124 
125 
129  public function handleFileDeletion(string $path_to_file): bool
130  {
131  // No possibilities to do this at the moment
132  return true;
133  }
134 }
__construct(Services $httpState)
PHP constructor.
Definition: XAccel.php:45
doesFileExists(string $path_to_file)
Definition: XAccel.php:53
handleFileDeletion(string $path_to_file)
bool
Definition: XAccel.php:129
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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:76
prepare(string $path_to_file)
bool
Definition: XAccel.php:63
$response