Files

37 lines
1.3 KiB
PHP
Executable File

<?php
namespace app\external_requests;
use app\exceptions\InvalidCurlStructureException;
class CurlRequestBuilder extends CurlRequest
{
private ?string $url = NULL;
private ?string $request = NULL;
private ?array $headers = NULL;
private ?array $body = NULL;
private bool $isReturnable = false;
public function __construct(){}
public function setUrl(?string $url): void{$this->url = $url;}
public function setHeaders(?array $headers): void{$this->headers = $headers;}
public function setRequest(?string $request): void{$this->request = $request;}
public function setBody(?array $body): void{$this->body = $body;}
public function setIsReturnable(?bool $isReturnable): void{$this->isReturnable = $isReturnable;}
private function areMainParametersNotSet(): bool{
return $this->url == NULL || $this->request == NULL || $this->headers == NULL;
}
/**
* @throws InvalidCurlStructureException
*/
public function getCurlRequestObject(): CurlRequest{
if($this->areMainParametersNotSet()){
throw new InvalidCurlStructureException("Invalid structure for making a request");
}
return new CurlRequest($this->url, $this->request, $this->headers, $this->body, $this->isReturnable);
}
}