index/src/Http/HttpRequestBuilder.php

73 lines
1.7 KiB
PHP

<?php
// HttpRequestBuilder.php
// Created: 2022-02-08
// Updated: 2022-02-27
namespace Index\Http;
class HttpRequestBuilder extends HttpMessageBuilder {
private string $method = 'GET';
private string $path = '/';
private array $params = [];
private array $cookies = [];
protected function getMethod(): string {
return $this->method;
}
public function setMethod(string $method): void {
$this->method = $method;
}
protected function getPath(): string {
return $this->path;
}
public function setPath(string $path): void {
$this->path = $path;
}
protected function getParams(): array {
return $this->params;
}
public function setParams(array $params): void {
$this->params = $params;
}
public function setParam(string $name, mixed $value): void {
$this->params[$name] = $value;
}
public function removeParam(string $name): void {
unset($this->params[$name]);
}
protected function getCookies(): array {
return $this->cookies;
}
public function setCookies(array $cookies): void {
$this->cookies = $cookies;
}
public function setCookie(string $name, mixed $value): void {
$this->cookies[$name] = $value;
}
public function removeCookie(string $name): void {
unset($this->cookies[$name]);
}
public function toRequest(): HttpRequest {
return new HttpRequest(
$this->getHttpVersion(),
$this->getMethod(),
$this->getPath(),
$this->getParams(),
$this->getCookies(),
$this->getHeaders(),
$this->getContent()
);
}
}