From 01c72e7a3d844e715a0c35e7fe43b35e06b9f7d0 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Thu, 4 Feb 2016 20:46:56 +0100 Subject: [PATCH] Use default values for optional registration properties --- lib/AcmeService.php | 18 ++++++++++++++++-- lib/Registration.php | 10 +++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/AcmeService.php b/lib/AcmeService.php index 6ec9670..77ddff3 100644 --- a/lib/AcmeService.php +++ b/lib/AcmeService.php @@ -59,6 +59,12 @@ private function doRegister($email, $agreement = null) { $response = (yield $this->acmeClient->post(AcmeResource::NEW_REGISTRATION, $payload)); if ($response->getStatus() === 201) { + if (!$response->hasHeader("location")) { + throw new AcmeException("Protocol Violation: No Location Header"); + } + + list($location) = $response->getHeader("location"); + $payload = json_decode($response->getBody()); if ($response->hasHeader("link")) { @@ -73,7 +79,12 @@ private function doRegister($email, $agreement = null) { } } - yield new CoroutineResult(new Registration($response->getHeader("location"), $payload->contact, $payload->agreement, $payload->authorizations, $payload->certificates)); + $contact = isset($payload->contact) ? $payload->contact : []; + $agreement = isset($payload->agreement) ? $payload->agreement : null; + $authorizations = isset($payload->authorizations) ? $payload->authorizations : []; + $certificates = isset($payload->certificates) ? $payload->certificates : []; + + yield new CoroutineResult(new Registration($location, $contact, $agreement, $authorizations, $certificates)); } if ($response->getStatus() === 409) { @@ -112,7 +123,10 @@ private function doRegister($email, $agreement = null) { } } - yield new CoroutineResult(new Registration($location, $payload->contact, $payload->agreement)); + $contact = isset($payload->contact) ? $payload->contact : []; + $agreement = isset($payload->agreement) ? $payload->agreement : null; + + yield new CoroutineResult(new Registration($location, $contact, $agreement)); return; } diff --git a/lib/Registration.php b/lib/Registration.php index 2b7a921..8e5f9be 100644 --- a/lib/Registration.php +++ b/lib/Registration.php @@ -14,7 +14,7 @@ class Registration { private $authorizations; private $certificates; - public function __construct(string $location, array $contact, string $agreement = null, array $authorizations = [], array $certificates = []) { + public function __construct(string $location, array $contact = [], string $agreement = null, array $authorizations = [], array $certificates = []) { $this->location = $location; $this->contact = $contact; $this->agreement = $agreement; @@ -25,19 +25,19 @@ public function __construct(string $location, array $contact, string $agreement public function getLocation() { return $this->location; } - + public function getContact() { return $this->contact; } - + public function getAgreement() { return $this->agreement; } - + public function getAuthorizations() { return $this->authorizations; } - + public function getCertificates() { return $this->certificates; }