public function __construct($http_range_header, $file_path)
{
// Simulate basic support for the Content-Range header.
preg_match('/bytes=(\\d+)?-(\\d+)?/', $http_range_header, $matches);
$this->first_byte = isset($matches['1']) ? (int) $matches['1'] : null;
$this->last_byte = isset($matches['2']) ? (int) $matches['2'] : null;
$this->filesize = filesize($file_path);
// Start position begins after end of file.
if ($this->first_byte >= $this->filesize) {
$this->is_valid = false;
}
// "If the last-byte-pos value is present, it MUST be greater than or equal to the first-byte-pos in that
// byte-range-spec, or the byte- range-spec is syntactically invalid."
if (!($this->last_byte === null) && !($this->last_byte >= $this->first_byte)) {
$this->is_valid = false;
}
}