Skip to content

Make HTTP client exchangable #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
69 changes: 66 additions & 3 deletions Lescript.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ class Lescript
private $client;
private $accountKeyPath;

public function __construct($certificatesDir, $webRootDir, $logger = null)
public function __construct($certificatesDir, $webRootDir, $logger = null, ClientInterface $client = null)
{
$this->certificatesDir = $certificatesDir;
$this->webRootDir = $webRootDir;
$this->logger = $logger;
$this->client = new Client($this->ca);
if($client !== null) {
$this->client = $client;
} else {
$this->client = new Client($this->ca);
}
$this->accountKeyPath = $certificatesDir . '/_account/private.pem';
}

Expand Down Expand Up @@ -379,7 +383,66 @@ protected function log($message)
}
}

class Client
interface ClientInterface
{
/**
* Constructor
*
* @param string $base the ACME API base all relative requests are sent to
*/
public function __construct($base);

/**
* Send a POST request
*
* @param string $url URL to post to
* @param array $data fields to sent via post
* @return array|string the parsed JSON response, raw response on error
*/
public function post($url, $data);

/**
* @param string $url URL to request via get
* @return array|string the parsed JSON response, raw response on error
*/
public function get($url);

/**
* Returns the Replay-Nonce header of the last request
*
* if no request has been made, yet. A GET on $base/directory is done and the
* resulting nonce returned
*
* @return mixed
*/
public function getLastNonce();

/**
* Return the Location header of the last request
*
* returns null if last request had no location header
*
* @return string|null
*/
public function getLastLocation();

/**
* Return the HTTP status code of the last request
*
* @return int
*/
public function getLastCode();

/**
* Get all Link headers of the last request
*
* @return string[]
*/
public function getLastLinks();
}


class Client implements ClientInterface
{
private $lastCode;
private $lastHeader;
Expand Down