teknoo / recipe
Inspired by cooking, allows the creation of dynamics 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.
Fund package maintenance!
Patreon
TeknooSoftware
Installs: 22 681
Dependents: 8
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- teknoo/immutable: ^3.0.18
- teknoo/states: ^6.4.1
Requires (Dev)
- behat/behat: ^3.15
- nikic/php-parser: ^4.18||^5.3.1
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^1.12.7
- phpunit/phpunit: ^11.4
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.10.3
- symfony/console: ^6.3||^7
- symfony/property-access: ^6.3||^7
- dev-master
- 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-feature-v6
This package is auto-updated.
Last update: 2024-11-02 11:38:37 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;
Others examples are available into demo
A complete documentation is available in documentation/README.md
Support this project
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.
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 MIT License - see the licenses folder for details.
Installation & Requirements
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.
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
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.
News from Teknoo Recipe 3.1
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
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 DockBlocks
- 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. Fork it on Github