Download the PHP package jgswift/filtratr without Composer
On this page you can find all versions of the php package jgswift/filtratr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jgswift/filtratr
More information about jgswift/filtratr
Files in jgswift/filtratr
Informations about the package filtratr
filtratr
filtering & mapping component
Installation
Install via cli using composer:
Install via composer.json using composer:
Description
filtratr is an extensible lightweight filtering component that facilitates filtering and mapping of data structures. filtratr provides a functional programming interface and a fluid interface.
Dependency
- php 5.5+
- jgswift/qinq - quasi integrated query
Usage
Filter
Includes or excludes data from result depending on provided predicate. Predicates may be implemented functionally or through strings.
Is & Not
and are an inverse subset of . The statement is simply an alias of to minimize conceptual overhead. The filter is the inverse version of and reverses whatever filtering is applied.
Conversely...
Using callbacks
Custom callbacks may easily be applied to every member of an array or object. Filter callbacks that return true or any values other than false or null will be kept in the subject array/object.
Using named callbacks
Specifying a key name before the callback will then only apply the callback to items that match that key and exclude processing anything else. Non-matching keys will be retained by default.
Predicates & Filters
- equals(comparison)
- identical(comparison)
- greaterthan(comparison)
- greaterthanorequals(comparison)
- lessthan(comparison)
- lessthanorequals(comparison)
- validate(filter, options)
- serial
Map
Map performs a transformation on selected keys/properties using a callback function.
Using callbacks
Much like filter, map may receive a callback, optional key pattern, and callback arguments array. Unlike filter, map is not inclusive and as such map can only effectively result with a transformed value or the original value.
Callbacks of any type (string, Closures, arrays) may be used. The following example is functionally identical to the previous
Using named callbacks
Concatenated Expressions
Mapping may be chained easily using the pipe operation. Method chaining is alternatively an option as well.
Same method using chaining...
Predicates & Filters
- contains
- nuller
- empty_nuller
- serializearray(array)
- unserializestring(string)
Reduce
Like , the reduce statement will apply a callback to many items and produce a single result.
Object support
filtratr will technically work on objects however filtratr currently only tests on public properties. Objects are passed by reference and the query will assume the object is mutable.
Extending fluid interface
The extension class...
Attaching per-filter extensions...
Attaching globally...