teknoo / recipe
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.
Requires
- php: ^8.4
- teknoo/immutable: ^3.0.22
- teknoo/states: ^7.1.11
Requires (Dev)
- behat/behat: ^3.33
- nikic/php-parser: ^5.9
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.2.16
- phpunit/phpunit: ^13.3.5
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^4.0.4
- symfony/property-access: ^6.4||^7.4||^8.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 7.3.0
- 7.2.3
- 7.2.2
- 7.2.1
- 7.2.0
- 7.1.1
- 7.1.0
- 7.0.0
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.2
- 5.0.1
- 5.0.0
- 4.6.1
- 4.6.0
- 4.5.2
- 4.5.1
- 4.5.0
- 4.4.0
- 4.3.0
- 4.2.8
- 4.2.7
- 4.2.6
- 4.2.5
- 4.2.4
- 4.2.3
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.5
- 4.1.4
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.4.0
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.1.0-beta5
- 2.1.0-beta4
- 2.1.0-beta3
- 2.1.0-beta2
- 2.1.0-beta1
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-beta7
- 2.0.0-beta5
- 2.0.0-beta4
- 2.0.0-beta3
- 2.0.0-beta2
- 2.0.0-beta1
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.1.0-beta5
- 1.1.0-beta4
- 1.1.0-beta3
- 1.1.0-beta2
- 1.1.0-beta1
- 1.0.2
- 1.0.1
- 1.0.0
- 1.0.0-beta2
- 1.0.0-beta1
- dev-release/v7
- dev-fix/opti
- dev-release/v6
This package is auto-updated.
Last update: 2026-10-01 12:45:21 UTC
README
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 :
instanceofinstead of reflection to resolve parameters, cachedTransformattributes, 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/Afterwith 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 callingfail()) does not throw anAlreadyCalledPromiseException. - Add
allowReuse()andprohibitReuse()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()andfail()can be called only once (seeallowReuse()). CookbookInterfaceandBaseCookbookTrait(deprecated since 6.0) are removed, usePlanInterfaceandBasePlanTrait.- Switch to Teknoo States 7 and PHPStan 2.
- The license is now the 3-Clause BSD License.
News from Teknoo Recipe 6.0
Cookbookis renamedPlan(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
Valueto inject a fixed value through a step's mapping. - Promises :
allowNextis true by default,onFailis called whenonSuccessthrows (callOnFailOnException),fetchResult/fetchResultIfCalledbehaviors 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_NAMEis final. - Support
FiberintoPromise. - Support
Fiberinto steps thanks to the dedicated classesFiberBowlandDynamicFiberBowl:- callable will be automatically wrapped by a fiber,
- the fiber object will be available as parameter for bowls.
- Add
Fibersupport to RecipeBowl, also in a dedicated classFiberRecipeBowl. The Fiber instance is also passed into workplan. - Add a
CookingSupervisorInterfaceand its default implementationCookingSupervisorto manage Bowls Fibers executions and loop on each active fiber.CookingSupervisorare also available as parameter for bowls.
News from Teknoo Recipe 3.1
This library requires PHP 8.0 or newer.
- Add
MergeableInterfaceandChefInterface::merge()to allow merge ingredient instead of replace it withupdateWorkPlanwithout fetch it into step. - Add
TransformableInterfaceand attributeTransformto 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
interruptCookingmethod to stop execution of chef without execute finals steps (dish validation or error handlers) - Add
stopErrorReportingmethod 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.