...

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
  • Several actions, "cooked" into a "bowl"
  • And an expected dish

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! It's hosted, developed, and maintained on GitHub by folks like you.


View GitHub Project

Example



<?php

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;

require 
'vendor/autoload.php';

$recipe = new Recipe();

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

$recipe $recipe->cook(
    function (\
DateTime $dateChefInterface $chef) {
        
$date $date->setTimezone(new \DateTimeZone('UTC'));

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

$recipe $recipe->cook(
    function (\
DateTime $dateChefInterface $chef) {
        
$immutable = \DateTimeImmutable::createFromMutable($date);

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

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

$chef = new Chef;
$chef->read($recipe);
$chef->process(['date' => new \DateTime('2017-12-25 00:00:00', new \DateTimeZone('Europe/Paris'))]);
echo 
$output.PHP_EOL;
//Output : 2017-12-24 23:00:00 UTC