Skip to content

Commit

Permalink
Use default values for optional registration properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Feb 4, 2016
1 parent 130bb00 commit 01c72e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
18 changes: 16 additions & 2 deletions lib/AcmeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 01c72e7

Please sign in to comment.