/
example-01.php
46 lines (35 loc) · 1018 Bytes
/
example-01.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
<?php
namespace Examples;
use Remix\Pipelines\Interfaces\StageInterface;
use Remix\Pipelines\Pipeline;
use Remix\Pipelines\SimpleState;
require_once __DIR__ . '/../vendor/autoload.php';
$state = new class extends SimpleState
{
public $data = '';
public function append(string $paragraph)
{
$this->data .= $paragraph . " ";
return $this;
}
};
$sayHello = new class implements StageInterface
{
public function __invoke($state)
{
return $state->append('Hello!');
}
};
$sayMyNameIsAlessandro = new class implements StageInterface
{
public function __invoke($state)
{
return $state->append('My name is Alessandro!');
}
};
$pipeline = new Pipeline();
$state = $pipeline
->pipe($sayHello) // Append "Hello!" to TextState
->pipe($sayMyNameIsAlessandro) // Append "My name is Alessandro" to TextState
->run($state); // Pass an initial State
echo $state->get(); // Print: Hello! My name is Alessandro!