Skip to content
PHP Ecosystem
Explore

ContentRange

API reference › PSR bridge › emitter › ContentRange

final classyii2\extensions\psrbridge\emitter\ContentRange
ImplementsStringable
Sourcesrc/emitter/ContentRange.php

Represents and parses HTTP Content-Range header values.

ContentRangeUnit Supported range units.

See also: https://datatracker.ietf.org/doc/html/rfc7233#section-4.2 (RFC 7233 section 4.2.).

PropertyTypeDescriptionDefined by
$first readonly constructorintFirst byte position in the range.ContentRange
$last readonly constructorintLast byte position in the range.ContentRange
$length readonly constructorint|stringTotal length of the resource (’*’ for unknown length).ContentRange
$unit readonly constructorContentRangeUnitUnit of measurement (for example, ContentRangeUnit::BYTES).ContentRange
MethodDescriptionDefined by
__construct()Creates a new instance of the ContentRange class.ContentRange
__toString()Converts the Content-Range to its string representation.ContentRange
fromHeader() staticCreates a new ContentRange instance from a Content-Range header string.ContentRange
public function __construct(yii2\extensions\psrbridge\emitter\ContentRangeUnit $unit, int $first, int $last, int|string $length)

Creates a new instance of the ContentRange class.

Parameters

ParameterTypeDescription
$unitContentRangeUnitUnit of measurement (for example, ContentRangeUnit::BYTES).
$firstintFirst byte position in the range.
$lastintLast byte position in the range.
$lengthint|stringTotal length of the resource (’*’ for unknown length).
public function __toString(): string

Converts the Content-Range to its string representation.

Returns

string: String representation in format ‘<unit> <first>-<last>/<length>’.

public static function fromHeader(string $header): self|null

Creates a new ContentRange instance from a Content-Range header string.

Parses a Content-Range header value in the format ‘<unit> <first>-<last>/<length>’ (for example, “bytes 0-1233/1234” or “bytes 42-1233/*”).

Accepts a matching byte-range expression and checks that the first byte does not exceed the last. It does not verify that the total length exceeds the last byte or reject surrounding header text.

Parameters

ParameterTypeDescription
$headerstringContent-Range header value to parse.

Returns

self|null: ContentRange instance if parsing succeeds, null if the header is invalid or unsupported or the range is inconsistent.