Download the PHP package beeblebrox3/caster without Composer
On this page you can find all versions of the php package beeblebrox3/caster. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package caster
Caster
PHP Library to cast arrays of values
Requirements
- PHP 7
Usage
Basic example:
The $types
parameter specifies how the $input
values should be transformed.
You do this specifying an array of rules to be applyied. A rule is identified by a string.
You can also apply multiple rules to the same value:
Rules can have arguments:
You can use nested arrays too:
Available rules
to pass options you don't use their names, but pass the values in the displayed order. Example:
'a' => 'bool|1'
. arguments with*
are mandatory
Rule | Arguments | Details |
---|---|---|
bool | nullIfEmpty * |
cast to boolean. If nullIfEmpty is 1 , cast empty strings and null to null, else cast to false |
date_format | output format * input format |
format the given date to an specific format. You can also specify the format of the input date |
float | precision round mode |
cast to float and optionally round the value using precision and round mode (using the round function) |
integer | cast to integer | |
lpad | length str |
pad the string on the left site to length length using str to fill |
rpad | length str |
pad the string on the right site to length length using str to fill |
string | max length |
casto so string, optionally limiting the string size to max length (using substr ) |
Custom Rules
You can create your own rules with a class implementing the Beeblebrox3\Caster\Rules\IRule
interface:
The PipeRule
will only return the same input.
Function as custom rule
new on version
0.1.0
Now you created the same pipe rule as before, but without the class.
Changelog
0.1.0
Add support functions as custom rules;0.0.2
Add custom rules support;