ContentRange
API reference › PSR bridge › emitter › ContentRange
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.).
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$first readonly constructor | int | First byte position in the range. | ContentRange |
$last readonly constructor | int | Last byte position in the range. | ContentRange |
$length readonly constructor | int| | Total length of the resource (’*’ for unknown length). | ContentRange |
$unit readonly constructor | ContentRangeUnit | Unit of measurement (for example, ContentRangeUnit::BYTES). | ContentRange |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a new instance of the ContentRange class. | ContentRange |
__toString() | Converts the Content-Range to its string representation. | ContentRange |
fromHeader() static | Creates a new ContentRange instance from a Content-Range header string. | ContentRange |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”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
| Parameter | Type | Description |
|---|---|---|
$unit | ContentRangeUnit | Unit of measurement (for example, ContentRangeUnit::BYTES). |
$first | int | First byte position in the range. |
$last | int | Last byte position in the range. |
$length | int| | Total length of the resource (’*’ for unknown length). |
__toString()
Section titled “__toString() ”public function __toString(): stringConverts the Content-Range to its string representation.
Returns
string: String representation in format ‘<unit> <first>-<last>/<length>’.
fromHeader()
Section titled “fromHeader() ”public static function fromHeader(string $header): self|nullCreates 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
| Parameter | Type | Description |
|---|---|---|
$header | string | Content-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.