Download the PHP package smoren/schemator without Composer
On this page you can find all versions of the php package smoren/schemator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package schemator
Schematic data mapper
Schematic data mapper is a tool for converting nested data structures (any composition of associative arrays, non-associative arrays and objects) according to the given conversion schema.
How to install to your project
Usage
Simple usage
Setting errors level
Using base filters
Using smart filter and replace
Using custom filters
Mass usage
Filters
const
Sets the value from const param.
Schema:
Result:
sum
Returns the sum of given array.
Given:
Schema:
Result:
average
Returns the average of given array.
Given:
Schema:
Result:
date
Returns formatted date from the Unix timestamp given value.
Params:
- Date format
- required
- data type — string
- example:
d.m.Y H:i:s
- more about formats
- Time zone offset from GMT
- optional
- data type — integer
- default — 0
Given:
Schema:
Result:
implode
Returns string of imploded items of given array with separator from args list.
params:
- Separator
- required
- data type — string
- example:
;
Given:
Schema:
Result:
explode
Returns array of exploded strings from given string with separator from args list
params:
- Separator
- required
- data type — string
- example:
;
Given:
Schema:
Result:
flatten
Returns flat array contains all the dead end leaves of tree array.
Given:
Schema:
Result:
sort
Sorts and returns given array.
Given:
Schema:
Result:
rsort
Sorts reversely and returns given array.
Given:
Schema:
Result:
filter
Returns array containing elements from given array that match the predicates from the params list.
Rules:
- Every predicate has such format
["predicate name", ...parans]
. - Predicates in one filter apply according the "OR" logic.
- To apply "AND" logic use chain of filters.
- Available predicates:
["=", 10]
meansvalue = 10
[">", 10]
meansvalue > 10
[">=", 10]
meansvalue >= 10
["<", 10]
meansvalue < 10
["<=", 10]
meansvalue <= 10
["in", [1, 2]]
meansvalue = 1 OR value = 2
["not in", [1, 2]]
meansvalue != 1 AND value != 2
["between", 1, 5]
means1 <= value <= 5
["between strict", 1, 5]
means1 < value < 5
Given:
Schema:
Result:
replace
Returns array of elements with values replaced according to the rules in the params list.
Rules:
- Every rule has such format
["value to replace", "rule name", ...params]
. - Rules in one filter apply according the "OR" logic.
- To apply "AND" logic use chain of filters.
- Available rules:
["=", 10]
meansvalue = 10
[">", 10]
meansvalue > 10
[">=", 10]
meansvalue >= 10
["<", 10]
meansvalue < 10
["<=", 10]
meansvalue <= 10
["in", [1, 2]]
meansvalue = 1 или value = 2
["not in", [1, 2]]
meansvalue != 1 и value != 2
["between", 1, 5]
means1 <= value <= 5
["between strict", 1, 5]
means1 < value < 5
["else"]
— no rules matched for value (If ruleelse
did not use, by default such values are replaced withnull
)
Given:
Schema:
Result:
Chain of filters
Given:
Schema:
Result:
Unit testing
Standards
Schemator conforms to the following standards:
- PSR-1 — Basic coding standard
- PSR-4 — Autoloader
- PSR-12 — Extended coding style guide
License
Schemator is licensed under the MIT License.