mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-10 00:43:50 +09:00
Update dependencies
This commit is contained in:
@@ -34,18 +34,18 @@ class BinaryFileResponse extends Response
|
||||
protected $offset = 0;
|
||||
protected $maxlen = -1;
|
||||
protected $deleteFileAfterSend = false;
|
||||
protected $chunkSize = 8 * 1024;
|
||||
protected $chunkSize = 16 * 1024;
|
||||
|
||||
/**
|
||||
* @param \SplFileInfo|string $file The file to stream
|
||||
* @param int $status The response status code
|
||||
* @param int $status The response status code (200 "OK" by default)
|
||||
* @param array $headers An array of response headers
|
||||
* @param bool $public Files are public by default
|
||||
* @param string|null $contentDisposition The type of Content-Disposition to set automatically with the filename
|
||||
* @param bool $autoEtag Whether the ETag header should be automatically set
|
||||
* @param bool $autoLastModified Whether the Last-Modified header should be automatically set
|
||||
*/
|
||||
public function __construct($file, int $status = 200, array $headers = [], bool $public = true, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true)
|
||||
public function __construct(\SplFileInfo|string $file, int $status = 200, array $headers = [], bool $public = true, ?string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true)
|
||||
{
|
||||
parent::__construct(null, $status, $headers);
|
||||
|
||||
@@ -56,36 +56,14 @@ class BinaryFileResponse extends Response
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \SplFileInfo|string $file The file to stream
|
||||
* @param int $status The response status code
|
||||
* @param array $headers An array of response headers
|
||||
* @param bool $public Files are public by default
|
||||
* @param string|null $contentDisposition The type of Content-Disposition to set automatically with the filename
|
||||
* @param bool $autoEtag Whether the ETag header should be automatically set
|
||||
* @param bool $autoLastModified Whether the Last-Modified header should be automatically set
|
||||
*
|
||||
* @return static
|
||||
*
|
||||
* @deprecated since Symfony 5.2, use __construct() instead.
|
||||
*/
|
||||
public static function create($file = null, int $status = 200, array $headers = [], bool $public = true, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true)
|
||||
{
|
||||
trigger_deprecation('symfony/http-foundation', '5.2', 'The "%s()" method is deprecated, use "new %s()" instead.', __METHOD__, static::class);
|
||||
|
||||
return new static($file, $status, $headers, $public, $contentDisposition, $autoEtag, $autoLastModified);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file to stream.
|
||||
*
|
||||
* @param \SplFileInfo|string $file The file to stream
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws FileException
|
||||
*/
|
||||
public function setFile($file, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true)
|
||||
public function setFile(\SplFileInfo|string $file, ?string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true): static
|
||||
{
|
||||
if (!$file instanceof File) {
|
||||
if ($file instanceof \SplFileInfo) {
|
||||
@@ -118,10 +96,8 @@ class BinaryFileResponse extends Response
|
||||
|
||||
/**
|
||||
* Gets the file.
|
||||
*
|
||||
* @return File
|
||||
*/
|
||||
public function getFile()
|
||||
public function getFile(): File
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
@@ -131,7 +107,7 @@ class BinaryFileResponse extends Response
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setChunkSize(int $chunkSize): self
|
||||
public function setChunkSize(int $chunkSize): static
|
||||
{
|
||||
if ($chunkSize < 1 || $chunkSize > \PHP_INT_MAX) {
|
||||
throw new \LogicException('The chunk size of a BinaryFileResponse cannot be less than 1 or greater than PHP_INT_MAX.');
|
||||
@@ -147,9 +123,9 @@ class BinaryFileResponse extends Response
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAutoLastModified()
|
||||
public function setAutoLastModified(): static
|
||||
{
|
||||
$this->setLastModified(\DateTime::createFromFormat('U', $this->file->getMTime()));
|
||||
$this->setLastModified(\DateTimeImmutable::createFromFormat('U', $this->file->getMTime()));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -159,7 +135,7 @@ class BinaryFileResponse extends Response
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAutoEtag()
|
||||
public function setAutoEtag(): static
|
||||
{
|
||||
$this->setEtag(base64_encode(hash_file('sha256', $this->file->getPathname(), true)));
|
||||
|
||||
@@ -175,7 +151,7 @@ class BinaryFileResponse extends Response
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setContentDisposition(string $disposition, string $filename = '', string $filenameFallback = '')
|
||||
public function setContentDisposition(string $disposition, string $filename = '', string $filenameFallback = ''): static
|
||||
{
|
||||
if ('' === $filename) {
|
||||
$filename = $this->file->getFilename();
|
||||
@@ -201,10 +177,7 @@ class BinaryFileResponse extends Response
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepare(Request $request)
|
||||
public function prepare(Request $request): static
|
||||
{
|
||||
if ($this->isInformational() || $this->isEmpty()) {
|
||||
parent::prepare($request);
|
||||
@@ -248,7 +221,7 @@ class BinaryFileResponse extends Response
|
||||
$parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping', ''), ',=');
|
||||
foreach ($parts as $part) {
|
||||
[$pathPrefix, $location] = $part;
|
||||
if (substr($path, 0, \strlen($pathPrefix)) === $pathPrefix) {
|
||||
if (str_starts_with($path, $pathPrefix)) {
|
||||
$path = $location.substr($path, \strlen($pathPrefix));
|
||||
// Only set X-Accel-Redirect header if a valid URI can be produced
|
||||
// as nginx does not serve arbitrary file paths.
|
||||
@@ -267,7 +240,7 @@ class BinaryFileResponse extends Response
|
||||
$range = $request->headers->get('Range');
|
||||
|
||||
if (str_starts_with($range, 'bytes=')) {
|
||||
[$start, $end] = explode('-', substr($range, 6), 2) + [0];
|
||||
[$start, $end] = explode('-', substr($range, 6), 2) + [1 => 0];
|
||||
|
||||
$end = ('' === $end) ? $fileSize - 1 : (int) $end;
|
||||
|
||||
@@ -316,14 +289,11 @@ class BinaryFileResponse extends Response
|
||||
return $lastModified->format('D, d M Y H:i:s').' GMT' === $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function sendContent()
|
||||
public function sendContent(): static
|
||||
{
|
||||
try {
|
||||
if (!$this->isSuccessful()) {
|
||||
return parent::sendContent();
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (0 === $this->maxlen) {
|
||||
@@ -341,14 +311,21 @@ class BinaryFileResponse extends Response
|
||||
|
||||
$length = $this->maxlen;
|
||||
while ($length && !feof($file)) {
|
||||
$read = ($length > $this->chunkSize) ? $this->chunkSize : $length;
|
||||
$length -= $read;
|
||||
$read = $length > $this->chunkSize || 0 > $length ? $this->chunkSize : $length;
|
||||
|
||||
stream_copy_to_stream($file, $out, $read);
|
||||
|
||||
if (connection_aborted()) {
|
||||
if (false === $data = fread($file, $read)) {
|
||||
break;
|
||||
}
|
||||
while ('' !== $data) {
|
||||
$read = fwrite($out, $data);
|
||||
if (false === $read || connection_aborted()) {
|
||||
break 2;
|
||||
}
|
||||
if (0 < $length) {
|
||||
$length -= $read;
|
||||
}
|
||||
$data = substr($data, $read);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($out);
|
||||
@@ -363,11 +340,9 @@ class BinaryFileResponse extends Response
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws \LogicException when the content is not null
|
||||
*/
|
||||
public function setContent(?string $content)
|
||||
public function setContent(?string $content): static
|
||||
{
|
||||
if (null !== $content) {
|
||||
throw new \LogicException('The content cannot be set on a BinaryFileResponse instance.');
|
||||
@@ -376,16 +351,15 @@ class BinaryFileResponse extends Response
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContent()
|
||||
public function getContent(): string|false
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trust X-Sendfile-Type header.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function trustXSendfileTypeHeader()
|
||||
{
|
||||
@@ -398,7 +372,7 @@ class BinaryFileResponse extends Response
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function deleteFileAfterSend(bool $shouldDelete = true)
|
||||
public function deleteFileAfterSend(bool $shouldDelete = true): static
|
||||
{
|
||||
$this->deleteFileAfterSend = $shouldDelete;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user