PHP code example of projx-io / fluent

1. Go to this page and download the library: Download projx-io/fluent 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/ */

    

projx-io / fluent example snippets


// Requires two parameters.
function greet($greeting, $name) {
    return sprintf("%s, %s!\n", $greeting, $name);
}

// Creates a stream with 'World'.
// $stream is a stream node, which is a callable value.
// This particular node is a 'with' node, and will return
// the value 'World' when the stream is executed.
// If call() is called directly on this node, then 'World'
// will be the result. Otherwise, 'World' will be passed as
// a parameter to the next node.
$stream = Fluent('World');

// Creates a stream node whose callback is 'greet',
// and has a bound parameter of 'Hello'.
// 'Hello' will be provided as the first parameter to `greet`.
// In this particular stream, the value of 'World' returned
// from the previous node will be provided as the second
// parameter to this node.
$stream = $stream->then('greet', 'Hello');

// Executes the stream then prints the returned value of
// "Hello, World!"
echo $stream->call();

Fluent::registerMethods([
    'someMethod' => new ConstantCallbackFactory(function () {
        return ...
    }),
]);

Fluent::then(...)->someMethod();

Fluent::registerMethods([
    'someMethod' => new BindCallbackFactory(new ConstantCallbackFactory(function ($a, $b) {
        return ...
    })),
]);

Fluent::then(...)->someMethod($a, $b);