PHP code example of fg / cascade

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

    

fg / cascade example snippets


$Cascade = new Cascade\Cascade([
	function($value) {
		return $value + $value;
	},
	function($value) {
		return $value * $value;
	}
]);

echo $Cascade->filter(2); // 16

$Cascade = new Cascade\Cascade([
	function($value, $factor) {
		return $value * $factor;
	}
]);

echo $Cascade->filter(2, 10); // 20

class SquareFilter {
	public function __invoke($value) {
		return $value * $value;
	}
}

$Cascade = new Cascade\Cascade([
	new SquareFilter()
]);

echo $Cascade->filter(2); // 4

// constructor
$Cascade = new Cascade\Cascade();
$Cascade = new Cascade\Cascade($filters);

// accessors for the list of filters
$Cascade->filters();
$Cascade->setFilters($filters);
$Cascade->addFilter($filter);

// filter
$Cascade->filter($value [, $args...]);