ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
XAccel.php
Go to the documentation of this file.
1 <?php
2 
4 
8 
9 require_once('./Services/FileDelivery/interfaces/int.ilFileDeliveryType.php');
10 
18 final class XAccel implements ilFileDeliveryType
19 {
21  const DATA = 'data';
22  const SECURED_DATA = 'secured-data';
26  private $httpService;
27  const X_ACCEL_REDIRECT = 'X-Accel-Redirect';
28 
29 
35  public function __construct(GlobalHttpState $httpState)
36  {
37  $this->httpService = $httpState;
38  }
39 
43  public function doesFileExists($path_to_file)
44  {
45  return is_readable($path_to_file);
46  }
47 
48 
49 
53  public function prepare($path_to_file)
54  {
55  $response = $this->httpService->response()->withHeader(ResponseHeader::CONTENT_TYPE, '');
56 
57  $this->httpService->saveResponse($response);
58 
59  return true;
60  }
61 
62 
66  public function deliver($path_to_file, $file_marked_to_delete)
67  {
68  // There is currently no way to delete the file after delivery
69  if (strpos($path_to_file, './' . self::DATA . '/') === 0) {
70  $path_to_file = str_replace('./' . self::DATA . '/', '/' . self::SECURED_DATA
71  . '/', $path_to_file);
72  }
73 
74  $response = $this->httpService->response();
75  $delivery = function () use ($path_to_file, $response) {
76  $response = $response->withHeader(self::X_ACCEL_REDIRECT, $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()
93  {
94  return true;
95  }
96 
97 
101  public function supportsAttachmentDelivery()
102  {
103  return true;
104  }
105 
106 
110  public function supportsStreaming()
111  {
112  return true;
113  }
114 
115 
119  public function handleFileDeletion($path_to_file)
120  {
121  // No possibilities to do this at the moment
122  }
123 }
Interface GlobalHttpState.
$response
__construct(GlobalHttpState $httpState)
PHP constructor.
Definition: XAccel.php:35
deliver($path_to_file, $file_marked_to_delete)
absolute path to fileThis is needed at this point for header-based delivery methodsbool ...
Definition: XAccel.php:66