diff --git a/src/LEClient.php b/src/LEClient.php index b1eca45..4861f48 100644 --- a/src/LEClient.php +++ b/src/LEClient.php @@ -64,8 +64,9 @@ class LEClient * @param array $certificateKeys Optional array containing location of all certificate files. Required paths are public_key, private_key, order and certificate/fullchain_certificate (you can use both or only one of them) * @param string $accountKeys The directory in which the account keys are stored. Is a subdir inside $certificateKeys. Defaults to '__account/'.(optional) * @param array $accountKeys Optional array containing location of account private and public keys. Required paths are private_key, public_key. + * @param array $leDirectoryConfig Optional array containing URLs obtained by "/directory" API */ - public function __construct($email, $acmeURL = LEClient::LE_PRODUCTION, $log = LEClient::LOG_OFF, $certificateKeys = 'keys/', $accountKeys = '__account/') + public function __construct($email, $acmeURL = LEClient::LE_PRODUCTION, $log = LEClient::LOG_OFF, $certificateKeys = 'keys/', $accountKeys = '__account/', $leDirectoryConfig = null) { $this->log = $log; @@ -152,7 +153,7 @@ public function __construct($email, $acmeURL = LEClient::LE_PRODUCTION, $log = L throw LEClientException::InvalidArgumentException('accountKeys must be string or array.'); } - $this->connector = new LEConnector($this->log, $this->baseURL, $this->accountKeys); + $this->connector = new LEConnector($this->log, $this->baseURL, $this->accountKeys, $leDirectoryConfig); $this->account = new LEAccount($this->connector, $this->log, $email, $this->accountKeys); if($this->log instanceof \Psr\Log\LoggerInterface) @@ -173,6 +174,17 @@ public function getAccount() return $this->account; } + + /** + * Returns the LetsEncrypt connector used in the current client. + * + * @return LEConnector + */ + public function getConnector() + { + return $this->connector; + } + /** * Returns a LetsEncrypt order. If an order exists, this one is returned. If not, a new order is created and returned. * diff --git a/src/LEConnector.php b/src/LEConnector.php index 0809a1f..c4aca9d 100644 --- a/src/LEConnector.php +++ b/src/LEConnector.php @@ -57,31 +57,42 @@ class LEConnector /** * Initiates the LetsEncrypt Connector class. - * * @param int $log The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted. * @param string $baseURL The LetsEncrypt server URL to make requests to. * @param array $accountKeys Array containing location of account keys files. + * @param array $leDirectoryConfig Optional array containing URLs obtained by "/directory" API */ - public function __construct($log, $baseURL, $accountKeys) + public function __construct($log, $baseURL, $accountKeys, $leDirectoryConfig = null) { $this->baseURL = $baseURL; $this->accountKeys = $accountKeys; $this->log = $log; - $this->getLEDirectory(); + $this->getLEDirectory( $leDirectoryConfig ); $this->getNewNonce(); } /** * Requests the LetsEncrypt Directory and stores the necessary URLs in this LetsEncrypt Connector instance. + * @param array $leDirectoryConfig Optional array containing URLs obtained by "/directory" API */ - private function getLEDirectory() + private function getLEDirectory( $leDirectoryConfig = null ) { - $req = $this->get('/directory'); - $this->keyChange = $req['body']['keyChange']; - $this->newAccount = $req['body']['newAccount']; - $this->newNonce = $req['body']['newNonce']; - $this->newOrder = $req['body']['newOrder']; - $this->revokeCert = $req['body']['revokeCert']; + if( $leDirectoryConfig ) { + $this->keyChange = $leDirectoryConfig['keyChange']; + $this->newAccount = $leDirectoryConfig['newAccount']; + $this->newNonce = $leDirectoryConfig['newNonce']; + $this->newOrder = $leDirectoryConfig['newOrder']; + $this->revokeCert = $leDirectoryConfig['revokeCert']; + + } else { + $req = $this->get('/directory'); + + $this->keyChange = $req['body']['keyChange']; + $this->newAccount = $req['body']['newAccount']; + $this->newNonce = $req['body']['newNonce']; + $this->newOrder = $req['body']['newOrder']; + $this->revokeCert = $req['body']['revokeCert']; + } } /**