Download the PHP package danbettles/morf without Composer
On this page you can find all versions of the php package danbettles/morf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danbettles/morf
More information about danbettles/morf
Files in danbettles/morf
Package morf
Short Description Morf was designed to filter request-parameters *en masse* but it is also useful in many other situations. A Morf *Filter* is created from an array of definitions that describes each parameter you're interested in, and serves-up valid, type-cast values; it'll spit-out an exception when something's overtly wrong.
License ISC
Informations about the package morf
Morf
Morf was designed to filter request-parameters en masse but it is also useful in many other situations.
A Morf Filter is created from an array of definitions that describes each parameter you're interested in, and serves-up valid, type-cast values; it'll spit-out an exception when something's overtly wrong.
For safety's sake, Morf is strict and opinionated, and uses PHP built-ins whenever possible.
Example
It's pretty straightforward:
Valid Inputs
| Type | Valid Input |
|---|---|
bool, boolean |
"1", "0"[^1] |
int, integer |
Any integer in string form |
float, double |
Any float/integer in string form |
string |
Any string |
array |
Any array |
[^1]: We take the view that being explicit is better (safer) in the long run. So, for example, a Boolean parameter with a blank value is treated as invalid because you can easily represent a Boolean value using "1" or "0"—which we think is more intuitive in any case.
Default Values
The built-in default values for each output-type—the values returned when parameters aren't set—are the same as those used in Symfony\Component\HttpFoundation\ParameterBag, which we think are intuitive. No problem if you disagree, or if your application requires something different, because you can specify parameter-level default values—see the example above.
Built-In Validators
| Name | Valid Value |
|---|---|
positiveInteger |
Integer > 0 |
nonNegativeInteger |
Integer >= 0 |