jdomenechb/promised-entities

Fetch entities or value objects asynchronously by using promises

v0.1.3 2020-10-05 07:17 UTC

This package is auto-updated.

Last update: 2024-04-29 04:45:52 UTC


README

Actions Status codecov

Have you ever wondered how you can integrate asynchronous PHP features with code structures like Domain Driven Design?

This library, among other uses, will allow you to use promises to instantiate objects asynchronously without having to compromise your code structure or use third-party classes in contract definition.

What does this library try to solve?

Installation

Run in the root of your project:

composer require jdomenechb/promised-entities

Usage

// ...

$promisedEntityFactory = PromisedEntityFactory::create(new GuzzleMethodBodyGenerator());
$promisedEntityFactory->build(YourEntity::class, $promise);

$promise is the Promise instance which resolution will return the loaded entity. It should match the given MethodBodyGenerator class which will know how to deal with it.

An example of implementation using this library can be seen in the test src files.