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
<?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;
Others examples are available into demo
A complete documentation is available in documentation/README.md
This project is free and will remain free. It is fully supported by the activities of the EIRL. If you like it and help me maintain it and evolve it, don't hesitate to support me on Patreon or Github.
Thanks :) Richard.
EIRL Richard Déloge - https://deloge.io - Lead developer. SASU Teknoo Software - https://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.
Recipe is licensed under the MIT License - see the licenses folder for details.
To install this library with composer, run this command :
composer require teknoo/recipe
This library requires :
* PHP 8.1+
* A PHP autoloader (Composer is recommended)
* Teknoo/Immutable.
* Teknoo/States.
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
intoPromise
. - Support
Fiber
intoBowl
andDynamicBowl
thanks to dynamics classes :- 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 classFiberRecipeBowl
. The Fiber instance is also passed into workplan. - Add a
CookingSupervisorInterface
and its default implementationCookingSupervisor
to manage Bowls Fibers executions and loop on each active fiber.CookingSupervisor
are also available as parameter for bowls.
This library requires PHP 8.0 or newer.
- Add
MergeableInterface
andChefInterface::merge()
to allow merge ingredient instead of replace it withupdateWorkplan
without fetch it into step. - Add
TransformableInterface
and attributeTransform
to allow transform an ingredient before to put it into the bowl
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
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 DockBlocks
- Enable PHPStan in QA Tools and disable PHPMd
- Enable PHPStan extension dedicated to support Stated classes
You are welcome to contribute to this project. Fork it on Github