Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Caddy v2 API helper library.",
"type": "library",
"require": {
"guzzlehttp/guzzle": "^6.4"
"guzzlehttp/guzzle": "^7.2"
},
"require-dev": {
"squizlabs/php_codesniffer": "*",
Expand Down
52 changes: 50 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ class Client
/** @var array */
public $headers;

public function __construct(string $caddyHost = 'localhost:2019', array $headers = [])
/** @var array */
public $certs;

/** @var array */
public $curlOptions;

/** @var boolean */
public $verify;

public function __construct(string $caddyHost = 'localhost:2019', array $headers = [], bool $verify = true, array $certs = [], array $curlOptions = [])
{
$this->setCaddyHost($caddyHost);
$this->setHeaders($headers);
$this->setVerify($verify);
$this->setCerts($certs);
$this->setCurlOptions($curlOptions);
}

/**
Expand All @@ -40,13 +52,49 @@ public function setHeaders(array $headers = [])
return $this;
}

/**
* Sets the verify
*
* @param boolean $verify
* @return Client
*/
public function setVerify(bool $verify = true)
{
$this->verify = $verify;
return $this;
}

/**
* Sets the certificates
*
* @param string $headers
* @return Client
*/
public function setCerts(array $certs = [])
{
$this->certs = $certs;
return $this;
}

/**
* Sets the curl options
*
* @param string $headers
* @return Client
*/
public function setCurlOptions(array $curlOptions = [])
{
$this->curlOptions = $curlOptions;
return $this;
}

/**
* Creates a new Request instance.
*
* @return Request
*/
public function request(): Request
{
return new Request($this->caddyHost, $this->headers);
return new Request($this->caddyHost, $this->headers, $this->verify, $this->certs, $this->curlOptions);
}
}
8 changes: 6 additions & 2 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ class Request
/** @var string */
public $uri = '/config';

public function __construct(string $caddyHost, array $headers = [])
public function __construct(string $caddyHost, array $headers = [], bool $verify = true, array $certs = [], array $curlOptions = [])
{
$this->http = new Client([
'verify' => $verify,
'base_uri' => $caddyHost
]);

$this->options = [
'cert' => $certs['public'],
'ssl_key' => $certs['key'],
'http_errors' => false,
'headers' => $headers
'headers' => $headers,
'curl.options' => $curlOptions,
];
}

Expand Down