MediaWiki master
Wikimedia\FileBackend\HTTPFileStreamer Class Reference

Functions related to the output of file content. More...

Public Member Functions

 __construct ( $path, array $params=[])
 stream ( $headers=[], $sendErrors=true, $optHeaders=[], $flags=0)
 Stream a file to the browser, adding all the headings and fun stuff.

Static Public Member Functions

static parseRange ( $range, $size)
 Convert a Range header value to an absolute (start, end) range tuple.
static preprocessHeaders ( $headers)
 Takes HTTP headers in a name => value format and converts them to the weird format expected by stream().
static send404Message ( $fname, $flags=0)
 Send out a standard 404 message for a file.

Public Attributes

const STREAM_ALLOW_OB = 2
const STREAM_HEADLESS = 1

Static Protected Member Functions

static contentTypeFromPath (string $filename)
 Determine the file type of a file based on the path.
static resetOutputBuffers ()

Protected Attributes

callable $headerFunc
callable $obResetFunc
string $path
callable $streamMimeFunc

Detailed Description

Functions related to the output of file content.

Since
1.28

Definition at line 21 of file HTTPFileStreamer.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\FileBackend\HTTPFileStreamer::__construct ( $path,
array $params = [] )
Parameters
string$pathLocal filesystem path to a file
array$paramsOptions map, which includes:
  • obResetFunc : alternative callback to clear the output buffer
  • streamMimeFunc : alternative method to determine the content type from the path
  • headerFunc : alternative method for sending response headers

Definition at line 64 of file HTTPFileStreamer.php.

References $path, contentTypeFromPath(), and resetOutputBuffers().

Member Function Documentation

◆ contentTypeFromPath()

Wikimedia\FileBackend\HTTPFileStreamer::contentTypeFromPath ( string $filename)
staticprotected

Determine the file type of a file based on the path.

Parameters
string$filenameStorage path or file system path

Definition at line 262 of file HTTPFileStreamer.php.

Referenced by __construct().

◆ parseRange()

Wikimedia\FileBackend\HTTPFileStreamer::parseRange ( $range,
$size )
static

Convert a Range header value to an absolute (start, end) range tuple.

Parameters
string$rangeRange header value
int$sizeFile size
Returns
array|string Returns error string on failure (start, end, length)
Since
1.24

Definition at line 220 of file HTTPFileStreamer.php.

Referenced by stream().

◆ preprocessHeaders()

Wikimedia\FileBackend\HTTPFileStreamer::preprocessHeaders ( $headers)
static

Takes HTTP headers in a name => value format and converts them to the weird format expected by stream().

Parameters
string[]$headers
Returns
array[] [ $headers, $optHeaders ]
Since
1.34

Definition at line 43 of file HTTPFileStreamer.php.

Referenced by MediaWiki\FileRepo\AuthenticatedFileEntryPoint\execute().

◆ resetOutputBuffers()

Wikimedia\FileBackend\HTTPFileStreamer::resetOutputBuffers ( )
staticprotected

Definition at line 247 of file HTTPFileStreamer.php.

Referenced by __construct().

◆ send404Message()

Wikimedia\FileBackend\HTTPFileStreamer::send404Message ( $fname,
$flags = 0 )
static

Send out a standard 404 message for a file.

Parameters
string$fnameFull name and path of the file to stream
int$flagsBitfield of STREAM_* constants
Since
1.24

Definition at line 196 of file HTTPFileStreamer.php.

Referenced by Wikimedia\FileBackend\FileBackendStore\doStreamFile(), Wikimedia\FileBackend\SwiftFileBackend\doStreamFile(), and stream().

◆ stream()

Wikimedia\FileBackend\HTTPFileStreamer::stream ( $headers = [],
$sendErrors = true,
$optHeaders = [],
$flags = 0 )

Stream a file to the browser, adding all the headings and fun stuff.

Headers sent include: Content-type, Content-Length, Last-Modified, and Content-Disposition.

Parameters
array$headersAny additional headers to send if the file exists
bool$sendErrorsSend error messages if errors occur (like 404)
array$optHeadersHTTP request header map (e.g. "range") (use lowercase keys)
int$flagsBitfield of STREAM_* constants
Returns
bool Success

Definition at line 82 of file HTTPFileStreamer.php.

References $headerFunc, $obResetFunc, $streamMimeFunc, parseRange(), and send404Message().

Referenced by MediaWiki\Output\StreamFile\stream().

Member Data Documentation

◆ $headerFunc

callable Wikimedia\FileBackend\HTTPFileStreamer::$headerFunc
protected

Definition at line 29 of file HTTPFileStreamer.php.

Referenced by stream().

◆ $obResetFunc

callable Wikimedia\FileBackend\HTTPFileStreamer::$obResetFunc
protected

Definition at line 25 of file HTTPFileStreamer.php.

Referenced by stream().

◆ $path

string Wikimedia\FileBackend\HTTPFileStreamer::$path
protected

Definition at line 23 of file HTTPFileStreamer.php.

Referenced by __construct().

◆ $streamMimeFunc

callable Wikimedia\FileBackend\HTTPFileStreamer::$streamMimeFunc
protected

Definition at line 27 of file HTTPFileStreamer.php.

Referenced by stream().

◆ STREAM_ALLOW_OB

const Wikimedia\FileBackend\HTTPFileStreamer::STREAM_ALLOW_OB = 2

◆ STREAM_HEADLESS

const Wikimedia\FileBackend\HTTPFileStreamer::STREAM_HEADLESS = 1

The documentation for this class was generated from the following file: