Download the PHP package datashaman/array-filter without Composer
On this page you can find all versions of the php package datashaman/array-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download datashaman/array-filter
More information about datashaman/array-filter
Files in datashaman/array-filter
Package array-filter
Short Description Match an array against a filter
License MIT
Homepage http://github.com/datashaman/array-filter
Informations about the package array-filter
Array Filter
A literal port of the excellent Javascript library mmckegg / json-filter to PHP.
Credit to Matt McKegg for creating an incredibly useful, well-tested piece of software.
Match PHP arrays against filters.
Installation
Filters
Filters are just arrays that have the keys and values you want your final array to have. e.g. if you wanted to require that the field type
was always person
your filter would be {type: 'person'}
.
If things aren't so black and white, the following conditionals are available:
$present
Specify that the value must not be null or false (i.e. 'truthy').
$any
Specify that the value can be anything. Useful when matching all keys.
$contains
For matching against an array. The array must contain all of the values specified.
$excludes
For matching against an array. The array cannot contain any of the values specified.
$only
The value can only be one of the ones specified.
$not
The value can be anything except one of the ones specified.
$matchAny
Allows a filter to branch into multiple filters when at least one must match.
$query
Specify a query to get the value to match. Uses options.queryHandler
.
$optional
A shortcut for specifying a lot of $any filters at the same time.
Is equivalent to:
API
checkFilter(source, filter, options)
options:
- match: specify: 'filter', 'source', 'any', 'all'
- filter: every filter permission must be satisfied (i.e. required fields)
- source: every source key must be specified in filter
- any: the keys don't matter, but if there is a match, they must pass
- all: all keys must be exactly the same, otherwise fails - for finding changed items - no $conditionals work in this mode
- queryHandler: Accepts a function(query, localContext) that returns resulting value
- context: Array to pass to the query handler