Search by

teknoo / recipe

frenchcomp

Inspired by cooking, allows the creation of dynamic workflows, called here recipe, following the #east programming and using middleware, configurable via DI or any configuration, if a set of conditions (ingredients) are available.

Package info

github.com/TeknooSoftware/recipe

Homepage

pkg:composer/teknoo/recipe

Fund package maintenance!

Patreon

TeknooSoftware

Statistics

Installs: 32 163

Dependents: 10

Suggesters: 0

Stars: 3

Open Issues: 0

7.3.0 2026-09-27 14:03 UTC

README

Latest Stable Version Latest Unstable Version Total Downloads License PHPStan

Inspired by cooking, allows the creation of dynamic algorithm, called here recipe, following the #east programming and using middleware, configurable via DI or any configuration, if a set of conditions (ingredients) are available.

A complete documentation is available in documentation/README.md

Quick Example

<?php

declare(strict_types=1);

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 $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'))]);

//Show : 2020-06-26 22:00:00 UTC
echo $output.PHP_EOL;

Other examples are available in the demo folder.

Support this project

This project is free and will remain free. It is fully supported by commercial activities of SASU Teknoo Software and EIRL Richard DELOGE. If you like it and help me maintain it and evolve it, don't hesitate to support me on Patreon or Github.

Thanks :) Richard.

Credits

EIRL Richard Déloge - https://deloge.io - Lead developer. SASU Teknoo Software - https://teknoo.software

About Teknoo Software

Teknoo Software is a PHP software editor, founded by Richard Déloge, as part of EIRL Richard Déloge. Teknoo Software's goals : Provide to our partners and to the community a set of high quality services or software, sharing knowledge and skills.

License

Recipe is licensed under the 3-Clause BSD License - see the LICENSE file for details.

Installation & Requirements

To install this library with composer, run this command :

composer require teknoo/recipe

This library requires :

* PHP 8.4+
* A PHP autoloader (Composer is recommended)
* Teknoo/Immutable 3.0.22+
* Teknoo/States 7.1.11+

News from Teknoo Recipe 7.3

  • Fix several bugs : chef cleaning after an escaped exception, relative and zero positions of steps, repeated sub recipes on a new cooking, fibers resumed twice by the supervisor, never started fibers, optional scalar ingredients, interfaces and non object values in ingredients checking, "Class::method" callables, variadic parameters, falsy aliases in mappings, step named "0", chef cloning, promises flags.
  • Optimizations : instanceof instead of reflection to resolve parameters, cached Transform attributes, scalar type checker of ingredients resolved once.
  • On PHP 8.5, the transformer of #[Transform] can be a first-class callable (MyTransformer::toDateTime(...)).

News from Teknoo Recipe 7.2

  • Steps and sub recipes can be inserted relatively to another step (RecipeRelativePositionEnum::Before / After with the name of the offset step).
  • Switch to Teknoo States 7.1.

News from Teknoo Recipe 7.1

  • A promise passed the same exception several times to fail() (a try/catch calling fail()) does not throw an AlreadyCalledPromiseException.
  • Add allowReuse() and prohibitReuse() to promises, to get the reusable behavior of Recipe 6.

News from Teknoo Recipe 7.0

This library requires PHP 8.4 or newer. Some changes cause BC breaks.

  • Promises' success() and fail() can be called only once (see allowReuse()).
  • CookbookInterface and BaseCookbookTrait (deprecated since 6.0) are removed, use PlanInterface and BasePlanTrait.
  • Switch to Teknoo States 7 and PHPStan 2.
  • The license is now the 3-Clause BSD License.

News from Teknoo Recipe 6.0

  • Cookbook is renamed Plan (PlanInterface, BasePlanTrait).
  • Add editable plans (EditablePlanInterface, EditablePlanTrait, Plan\Step) to add steps and error handlers to a plan from a container definition, without a custom mechanism.

News from Teknoo Recipe 5.0

This library requires PHP 8.2 or newer (8.1 dropped in 5.1). Some changes cause BC breaks.

  • Add Value to inject a fixed value through a step's mapping.
  • Promises : allowNext is true by default, onFail is called when onSuccess throws (callOnFailOnException), fetchResult / fetchResultIfCalled behaviors fixed, setDefaultResult() and __invoke() added.

News from Teknoo Recipe 4.0

This library requires PHP 8.1 or newer. Some change causes bc breaks.

  • Use readonly properties for immutables objects.
  • Constant BowlInterface::METHOD_NAME is final.
  • Support Fiber into Promise.
  • Support Fiber into steps thanks to the dedicated classes FiberBowl and DynamicFiberBowl :
    • callable will be automatically wrapped by a fiber,
    • the fiber object will be available as parameter for bowls.
  • Add Fiber support to RecipeBowl, also in a dedicated class FiberRecipeBowl. The Fiber instance is also passed into workplan.
  • Add a CookingSupervisorInterface and its default implementation CookingSupervisor to manage Bowls Fibers executions and loop on each active fiber. CookingSupervisor are also available as parameter for bowls.

News from Teknoo Recipe 3.1

This library requires PHP 8.0 or newer.

  • Add MergeableInterface and ChefInterface::merge() to allow merge ingredient instead of replace it with updateWorkPlan without fetch it into step.
  • Add TransformableInterface and attribute Transform to allow transform an ingredient before to put it into the bowl

News from Teknoo Recipe 3.0

This library requires PHP 8.0 or newer. Some change causes bc breaks.

  • Promise immutable check is performed before var assignment
  • Some optimisations on array functions to limit O(n)
  • Subs chefs executing an embedded recipe inherit also of error handler with the workplan but can be changed without impact the original handler in the main chef.
  • Subs chefs call also theirs top chef's callErrors method on error
  • Add interruptCooking method to stop execution of chef without execute finals steps (dish validation or error handlers)
  • Add stopErrorReporting method to stop error reporting to top chef

News from Teknoo Recipe 2.0

This library requires PHP 7.4 or newer. Some change causes bc breaks :

  • PHP 7.4 is the minimum required
  • Most methods have been updated to include type hints where applicable. Please check your extension points to make sure the function signatures are correct.
  • Switch to typed properties
  • All files use strict typing. Please make sure to not rely on type coercion.
  • Replace array_merge by "..." operators for integer indexed arrays
  • Remove some PHP useless DocBlocks
  • Enable PHPStan in QA Tools and disable PHPMd
  • Enable PHPStan extension dedicated to support Stated classes

Contribute :)

You are welcome to contribute to this project. Read the contributing guide first.