PHP code example of darkwood / flow
1. Go to this page and download the library: Download darkwood/flow library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
darkwood / flow example snippets
use Flow\Flow\Flow;
use Flow\Ip;
class D1 {
public function __construct(public int $n1) {}
}
class D2 {
public function __construct(public int $n2) {}
}
class D3 {
public function __construct(public int $n3) {}
}
class D4 {
public function __construct(public int $n4) {}
}
$flow = Flow::do(static function() {
yield fn (D1 $data1) => new D2($data1->n1 += 1);
yield fn (D2 $data2) => new D3($data2->n2 * 2);
yield function(D3 $data3) {
printf("my number %d\n", $ip->data->n3)); // display 'my number 10'
return new D4($data3->n3);
};
});
$ip = new Ip(new D1(4));
$flow($ip);
$flow->await();