-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repeat_sub_recipe.php
99 lines (84 loc) · 2.34 KB
/
repeat_sub_recipe.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/*
* Recipe.
*
* LICENSE
*
* This source file is subject to the MIT license
* it is available in LICENSE file at the root of this package
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
*
* @copyright Copyright (c) EIRL Richard Déloge (https://deloge.io - [email protected])
* @copyright Copyright (c) SASU Teknoo Software (https://teknoo.software - [email protected])
*
* @link https://teknoo.software/libraries/recipe Project website
*
* @license https://teknoo.software/license/mit MIT License
* @author Richard Déloge <[email protected]>
*/
declare(strict_types=1);
namespace Acme2;
use Teknoo\Recipe\Bowl\RecipeBowl;
use Teknoo\Recipe\Chef;
use Teknoo\Recipe\ChefInterface;
use Teknoo\Recipe\Ingredient\Attributes\Transform;
use Teknoo\Recipe\Ingredient\TransformableInterface;
use Teknoo\Recipe\Recipe;
require __DIR__ . '/../vendor/autoload.php';
class IntValue implements TransformableInterface
{
public function __construct(
public int $value = 0,
) {
}
public function transform(): mixed
{
return (int) $this->value;
}
}
$subRecipe = new Recipe();
$subRecipe = $subRecipe->cook(
static function (IntValue $value): void {
$value->value++;
},
'increaseCounter'
);
$subRecipe = $subRecipe->cook(
static function (): void {
echo "I MUST NOT WRITE ALL OVER THE WALLS" . PHP_EOL;
},
'displayInformation'
);
$recipe = new Recipe();
$recipe = $recipe->cook(
static function (ChefInterface $chef): void {
$chef->updateWorkPlan([
IntValue::class => new IntValue(0),
]);
},
'createArray'
);
$recipe = $recipe->execute(
$subRecipe,
'subrecipeCall',
static function (#[Transform(IntValue::class)] int $value, RecipeBowl $bowl): void {
if ($value > 5) {
$bowl->stopLooping();
}
}
);
$chef = new Chef;
$chef->read($recipe);
$chef->process([]);
/**
* Will show :
* I MUST NOT WRITE ALL OVER THE WALLS
* I MUST NOT WRITE ALL OVER THE WALLS
* I MUST NOT WRITE ALL OVER THE WALLS
* I MUST NOT WRITE ALL OVER THE WALLS
* I MUST NOT WRITE ALL OVER THE WALLS
* I MUST NOT WRITE ALL OVER THE WALLS
*/