ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
XAccelResponseBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Psr\Http\Message\ResponseInterface;
25use Psr\Http\Message\ServerRequestInterface;
26
31{
35 private const DATA = 'data';
39 private const SECURED_DATA = 'secured-data';
43 private const SECURED_EXT_DATA = 'secured-ext-data';
47 private const X_ACCEL_REDIRECT_HEADER = 'X-Accel-Redirect';
48
49 public function __construct(private string $external_data_dir)
50 {
51 $this->external_data_dir = rtrim($this->external_data_dir, '/') . '/';
52 }
53
54 public function getName(): string
55 {
56 return 'x-accel';
57 }
58
59 public function buildForStream(
60 ServerRequestInterface $request,
61 ResponseInterface $response,
62 FileStream $stream,
63 ): ResponseInterface {
64 $path_to_file = $stream->getMetadata('uri');
65 if (str_starts_with((string) $path_to_file, './' . self::DATA . '/')) {
66 $path_to_file = str_replace(
67 './' . self::DATA . '/',
68 '/' . self::SECURED_DATA
69 . '/',
71 );
72 } elseif (str_starts_with((string) $path_to_file, $this->external_data_dir)) {
73 $path_to_file = str_replace(
74 $this->external_data_dir,
75 '/' . self::SECURED_EXT_DATA . '/',
77 );
78 }
79
80 return $response->withHeader(
81 self::X_ACCEL_REDIRECT_HEADER,
83 );
84 }
85
86 public function supportPartial(): bool
87 {
88 return true;
89 }
90
91 public function supportStreaming(): bool
92 {
93 return true;
94 }
95
96 public function supportFileDeletion(): bool
97 {
98 return false;
99 }
100
101 public function supportsInlineDelivery(): bool
102 {
103 return true;
104 }
105
106 public function supportsAttachmentDelivery(): bool
107 {
108 return true;
109 }
110}
buildForStream(ServerRequestInterface $request, ResponseInterface $response, FileStream $stream,)
The base interface for all filesystem streams.
Definition: FileStream.php:32
$response
Definition: xapitoken.php:90