36 lines
852 B
PHP
36 lines
852 B
PHP
|
<?php
|
||
|
// AuthorizationHeader.php
|
||
|
// Created: 2022-02-14
|
||
|
// Updated: 2022-02-27
|
||
|
|
||
|
namespace Index\Http\Headers;
|
||
|
|
||
|
use Index\Http\HttpHeader;
|
||
|
|
||
|
class AuthorizationHeader {
|
||
|
private string $method;
|
||
|
private string $params;
|
||
|
|
||
|
public function __construct(string $method, string $params) {
|
||
|
$this->method = $method;
|
||
|
$this->params = $params;
|
||
|
}
|
||
|
|
||
|
public function getMethod(): string {
|
||
|
return $this->method;
|
||
|
}
|
||
|
|
||
|
public function isMethod(string $method): bool {
|
||
|
return $this->method === strtolower($method);
|
||
|
}
|
||
|
|
||
|
public function getParams(): string {
|
||
|
return $this->params;
|
||
|
}
|
||
|
|
||
|
public static function parse(HttpHeader $header): AuthorizationHeader {
|
||
|
$parts = explode(' ', trim($header->getFirstLine()), 2);
|
||
|
return new AuthorizationHeader($parts[0], $parts[1] ?? '');
|
||
|
}
|
||
|
}
|