PHPackages                             redbean-fvm/redbean-fvm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. redbean-fvm/redbean-fvm

ActiveLibrary[Search &amp; Filtering](/categories/search)

redbean-fvm/redbean-fvm
=======================

Redbean FVM makes Filtering,Validating , and Generating RedBean Models easy.

1.10(8y ago)8159[7 issues](https://github.com/r3wt/RedBeanFVM/issues)MITPHP

Since May 16Pushed 8y ago2 watchersCompare

[ Source](https://github.com/r3wt/RedBeanFVM)[ Packagist](https://packagist.org/packages/redbean-fvm/redbean-fvm)[ RSS](/packages/redbean-fvm-redbean-fvm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (12)Used By (0)

RedBeanFVM
==========

[](#redbeanfvm)

RedbeanFVM makes Filtering, Validating , and Generating RedBean Models easy.

**Features:**

- 16 built in filter and validation functions.
- simple api allows users to define custom named filters.
- chainable filters
- fully automates the process of creating a redbean Model - simply pass in a the bean and a list of required rules Multi-deminsional Array: `Array(datakey => rules)`, a list of optional rules, and the data source, which defaults to the `$_POST` superglobal. RedBeanFVM searches your data source for the key, performs the filtering rule(s) and stores this into the model. pretty flippin sweet huh?
- automatically converts datakeys to snake case as required by RedBean.
- Singleton Interface with dynamic methods. No need to juggle references across business logic or pass it down through functions. create custom filters anywhere, and they will persist via static references. simply retrieve a reference to the library at anytime like so `$fvm = \RedBeanFVM\RedBeanFVM::getInstance();`

### Installation

[](#installation)

**Install via Composer:**

1. install with composer:

    ```
    composer require redbean-fvm/redbean-fvm
    ```
2. add code to project:

    ```
    require 'vendor/autoload.php';
    $fvm = \RedBeanFVM\RedBeanFVM::getInstance();
    ```

**Download and Manually Install:**

1. download/clone the package:

    ```
    git clone https://github.com/r3wt/RedBeanFVM.git
    ```
2. add this snipped of code:

    ```
    require 'RedBeanFVM/RedBeanFVM.php';
    \RedBeanFVM\RedBeanFVM::registerAutoloader(); // for future use
    $fvm = \RedBeanFVM\RedBeanFVM::getInstance();
    ```

### Examples

[](#examples)

1. basic usage:

    ```
    $bean = R::dispense('user'); // the redbean model

    $required = [
        'Name'=>'name', // post key + rule(s)
        'Email'=>'email',
        'User_Name'=>['rmnl','az_lower'],
        'Password'=>'password_hash',
    ];

    $fvm->generate_model($bean,$required); //the magic

    R::store($bean);
    ```
2. optional parameters:

    ```
    $bean = R::dispense('user'); // the redbean model

    $required = [
        'Name'=>'name', // post key + rule(s)
        'Email'=>'email',
        'User_Name'=>['rmnl','az_lower'],
        'Password'=>'password_hash',
    ];
    //here we are adding the optional array. these fields are optional, so we raise no exception for missing values.
    $optional = [
        'username'=>'min' //min is the minimum validation/filter
    ];

    $fvm->generate_model($bean,$required,$optional); //the magic

    R::store($bean);
    ```
3. custom data source

    ```
    $bean = R::dispense('user'); // the redbean model

    $required = [
        'Name'=>'name', // post key + rule(s)
        'Email'=>'email',
        'User_Name'=>['rmnl','az_lower'],
        'Password'=>'password_hash',
    ];
    $optional = [
        'username'=>'min' //min is the minimum validation/filter
    ];

    // here we add a custom data source

    $data = array_merge($_POST,$_GET);

    $fvm->generate_model($bean,$required,$optional,$data); //the magic

    R::store($bean);
    ```
4. manual usage of the methods.

    ```
    $unsafeData = 'alfjasldfajsl1000afdasjlkl';
    //we can use RedBeanFVM manually too.
    $bean->someProperty = $fvm->cast_int($unsafeData);
    ```
5. chainable methods with chain()

    ```
    $input = $_POST['username'];

    $rules = ['rmnl','az','name'];

    $bean->user_name = $fvm->chain($rules,$input);
    ```
6. custom filters(named closures)

    ```
    $fvm = \RedBeanFVM\RedBeanFVM::getInstance();

    $bean = R::dispense('automobile');

    $required = [
        'make'=>'min',
        'model'=>'min',
        'year'=>'car_year', //this is custom filter
        'vin-number'=>'car_vin_number',// so is this
    ];

    //now we must create the custom filters ...

    //create a custom filter to validate the `year` of the automobile
    $fvm->custom_filter('car_year',function($input){
        if(!preg_match('/^[0-9]{4}$/',$input)){
            throw new \exception('Invalid Year entered');
        }
        return $input;
    });

    //create a custom filter to validate the vin number of the automobile.
    $fvm->custom_filter('car_vin_number',function($input){
        // vin numbers are 17 in length alphanumeric
        if(!preg_match('/^[0-9A-Za-z]{17}$/',$input)){
            throw new \exception('Invalid VIN entered.');
        }
        return strtoupper($input);//we dont really care if they typed lower case. we can fix it for them.
    });

    //now we can use our custom filters for year and vin.
    $required = [
        'make'=>'min',
        'model'=>'min',
        'year'=>'car_year', //this is custom filter
        'vin-number'=>'car_vin_number',// so is this
    ];

    $fvm->generate_model($bean,$required);
    ```
7. advanced custom filters.

- Some functions like `name` accept optional second parameters.
- by design, FVM only accepts 1 argument, the $input to be filtered.
- we can work around this like so: ```
    $min_length = 10;
    $max_length = 55;

    $fvm->custom_filter('name_custom',function($input) use($fvm,$min_length,$max_length){
        return $fvm->name($input,$min_length,$max_length);
    });
    ```

8. calling custom filter directly on $fvm is possible.

    ```
    $fvm->custom_filter('foo',function($input){
        return 'foo';
    });

    $input = 'abcdefg';

    $bean->foo = $fvm->foo($input);
    ```
9. checkboxes

    ```
    $checkboxes = [
    	'remember_me'=>1,//the expected value of the input field.
    	'email_subscribe'=>1,
    ];

    $fvm->checkbox($bean,$checkboxes,$_POST);
    ```
10. loading a custom filter class.

    ```
    //latest version of RedbeanFVM introduces the ability to load a custom class of filters. this way you
    //can write code for your filters in a normal class instead of relying on `RedbeanFVM::custom_filter()`
    //at present time, it is only possible to load a single class, in future support for passing an array of classes is possible,
    //although personally i believe it to be cleaner to use a single class.

    //note: namespaces must be escaped as shown

    \RedBeanFVM\RedBeanFVM::configure([
    	'user_filters'=>'\\App\\Util\\CustomFilters'
    ]);
    ```
11. required and optional can be called directly.

    ```
    $required = [...rules];
    $optional = [...rules;

    $fvm->required($bean,$required,$_POST);
    $fvm->optional($bean,$optional,$_POST);

    ```
12. file uploads (coming soonish)
13. all config options and their default values.

    ```
    \RedbeanFVM\RedbeanFVM::configure([
        'password'=>[
            'cost'=>12, //cost of password_hash
            'algo'=>PASSWORD_DEFAULT //password algo. see PHP Manual entry for password_hash() for more info.
        ],
        'locale'=>'\\RedBeanFVM\\Locale\\US', //default locale is this.
        'user_filters'=>'',//load a custom class of filters. filter methods must be public.
    	'optional_defaults'=>false //require that optional parameters are provided a default. see example 13 for more info.
    ]);
    ```
14. optional defaults explained.

    ```
    //say you want a field to be optional, but it needs a default value if not specified right?
    //FVM will expect that you provide an array of rules, with the last rule being the default value like so
    $optional = [
    	'about_me'=>['paragraph','no info provided'],
    	'phone_number'=>['us_phone','not provided']
    ];
    //as you can see its pretty convenient to type and should be simple to get the hang of.
    //if users don't like this, please open an issue and we can think of an alternative way to handle it.
    //this option is disabled by default.
    ```

### Requirements:

[](#requirements)

RedBean, obviously `http://www.redbeanphp.com/`

### Development

[](#development)

Want to contribute? Great! Pull Requests welcomed!

### Todo's

[](#todos)

- Write Tests
- Language Packs (Locale's)
- Expand Features.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance3

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~90 days

Recently: every ~11 days

Total

11

Last Release

3117d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8095bc3c11193dd1da855b5bb1301a5bc6a6ea812294cf1b054352930f06e014?d=identicon)[r3wt](/maintainers/r3wt)

---

Top Contributors

[![r3wt](https://avatars.githubusercontent.com/u/4483325?v=4)](https://github.com/r3wt "r3wt (8 commits)")

---

Tags

pluginvalidationdatamodelfilterredbeanredbeanphp

### Embed Badge

![Health badge](/badges/redbean-fvm-redbean-fvm/health.svg)

```
[![Health](https://phpackages.com/badges/redbean-fvm-redbean-fvm/health.svg)](https://phpackages.com/packages/redbean-fvm-redbean-fvm)
```

###  Alternatives

[aura/filter

Filters to validate and sanitize objects and arrays.

173561.0k10](/packages/aura-filter)[codewithdennis/filament-price-filter

A simple and customizable price filter for FilamentPHP, allowing users to easily refine results based on specified price ranges.

163.2k](/packages/codewithdennis-filament-price-filter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
