afosto / yaac

Yet another ACME client: a decoupled LetsEncrypt client
Other
219 stars 85 forks source link

Allow Data classes to be JSON serialized and unserialized #48

Closed mrspence closed 2 years ago

mrspence commented 2 years ago

Fix #47

This pull request introduces...

Example use

use Afosto\Acme\Data\Authorization;

// Serialize...

$authorization = new Authorization(...);

$json = $authorization->toJson();
// or
$json = json_encode($authorization);

// Un-serialize...
$authorization = Authorization::fromJson($json);

Testing

The fork used to develop this pull request has been used in a staging area, to generate real LetsEncrypt certificates with success. This fork allows our staging area to run the certificate generation step by step, in different PHP instances.

No breaking changes detected (or expected).

This repo doesn't come with a testing suite and I didn't want to clutter this pull request! 😅

Use case

It is useful to be able to split an SSL Certificate generation over separate "Jobs" / PHP instances, particularly between running 'self tests' VS real LetsEncrypt tests for authorizations.

This commit allows Data objects to be JSON serialized / unserialized, so the developer can store an unfinished generation and the SSL Certificate generation can easily be picked up by a later PHP process.

This uses PHP's in-built JSON serialization interface and extends it to provide the useful helper functions as shown in the examples above..

bakkerpeter commented 2 years ago

Thanks for the PR. Just a question regarding the usecase / workflow. Why would you not just store the orderID and fetch the existing order to continue the process later on?

//Obtain ID and store it somewhere
$id = $order->getId();

//Load the order by the stored ID
$client->getOrder($id);

See https://github.com/afosto/yaac/issues/28

bakkerpeter commented 2 years ago

Closing this PR. Please re-open if this is still needed.