recipe flow example

Recipe

Inspired by cooking, allows the creation of dynamic workflow.


To link pieces of codes between them to implement a workflow and solve a problem without having to write one, while allowing to complete it by additional modules.

A workflow with recipe is composed by

  • Several ingredients
  • Transform automatically ingredients
  • Several actions, "cooked" into a "bowl"
  • And an expected dish
  • Persist recipe in Cookbook
  • Can use promise between steps
  • Compliant with Fiber

The library "East Foundation" is built on Recipe to manage the HTTP Request workflow, and allow developers to add some middlewares to manage by example sessions, or translations.

Features


Input Checking

To avoid errors during execution.

Dynamic definition

Create, complete and order tasks at runtime.

Immutable

Each update in the workflow create a new one.

PSR 11

Compliant with PSR-11, embedded with PHP DI.

GitHub


Fork the project on GitHub

It is open source! Hosted, developed, and maintained on GitHub.


View GitHub Project

Patreon


Support this project on Patreon

This project is free and will remain free, but its development is not. If you like it and help us maintain it and evolve it, don't hesitate to support us on Patreon.


Support it

Example



<?php

declare(strict_types=1);

namespace
Acme;

use
DateTime;
use
DateTimeImmutable;
use
DateTimeZone;
use
Teknoo\Recipe\Dish\DishClass;
use
Teknoo\Recipe\Ingredient\Ingredient;
use
Teknoo\Recipe\Recipe;
use
Teknoo\Recipe\Chef;
use
Teknoo\Recipe\ChefInterface;
use
Teknoo\Recipe\Promise\Promise;
use
Throwable;

require
'vendor/autoload.php';

$recipe = new Recipe();

$recipe = $recipe->require(
new
Ingredient(DateTime::class, 'date'),
);

$recipe = $recipe->cook(
function (
DateTime $date, ChefInterface $chef): void {
$date = $date->setTimezone(new DateTimeZone('UTC'));

$chef->continue(['date' => $date]);
},
'convertToUTC',
);

$recipe = $recipe->cook(
function (
DateTime $date, ChefInterface $chef): void {
$immutable = DateTimeImmutable::createFromMutable($date);

$chef->finish($immutable);
},
'immutableDate',
);

$output = '';
$recipe = $recipe->given(
new
DishClass(
DateTimeImmutable::class,
new
Promise(
function (
DateTimeImmutable $immutable) use (&$output): void {
$output = $immutable->format('Y-m-d H:i:s T');
},
function (
Throwable $error) use (&$output): void {
$output = $error->getMessage();
}
)
)
);

$chef = new Chef;
$chef->read($recipe);
$chef->process([
'date' => new DateTime('2020-06-27 00:00:00', new DateTimeZone('Europe/Paris'))
]);

echo
$output.PHP_EOL;