Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/felixgirault/cascade
A lightweight API to filter values.
https://github.com/felixgirault/cascade
Last synced: about 2 months ago
JSON representation
A lightweight API to filter values.
- Host: GitHub
- URL: https://github.com/felixgirault/cascade
- Owner: felixgirault
- Created: 2014-07-05T15:05:51.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-04-05T17:00:26.000Z (almost 10 years ago)
- Last Synced: 2024-11-21T08:39:10.585Z (2 months ago)
- Language: PHP
- Size: 106 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Cascade
=======A lightweight API to filter values.
Installation
------------```sh
composer require fg/cascade
```Usage
-----Filtering a value:
```php
$Cascade = new Cascade\Cascade([
function($value) {
return $value + $value;
},
function($value) {
return $value * $value;
}
]);echo $Cascade->filter(2); // 16
```Filtering a value depending on additionnal arguments:
```php
$Cascade = new Cascade\Cascade([
function($value, $factor) {
return $value * $factor;
}
]);echo $Cascade->filter(2, 10); // 20
```Filtering a value with a filter object:
```php
class SquareFilter {
public function __invoke($value) {
return $value * $value;
}
}$Cascade = new Cascade\Cascade([
new SquareFilter()
]);echo $Cascade->filter(2); // 4
```API
---```php
// 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...]);
```