34 lines
709 B
PHP
34 lines
709 B
PHP
<?php
|
|
// DNTHeader.php
|
|
// Created: 2022-02-14
|
|
// Updated: 2022-02-14
|
|
|
|
namespace Index\Http\Headers;
|
|
|
|
use Index\Http\HttpHeader;
|
|
|
|
class DNTHeader {
|
|
private ?bool $state;
|
|
|
|
public function __construct(?bool $state) {
|
|
$this->state = $state;
|
|
}
|
|
|
|
public function getState(): ?bool {
|
|
return $this->state;
|
|
}
|
|
|
|
public function hasNoPreference(): bool {
|
|
return $this->state === null;
|
|
}
|
|
|
|
public function allowsTracking(): bool {
|
|
return $this->state !== false;
|
|
}
|
|
|
|
public static function parse(HttpHeader $header): DNTHeader {
|
|
$value = $header->getFirstLine();
|
|
return new DNTHeader($value === 'null' ? null : ($value === '1'));
|
|
}
|
|
}
|