PHPackages                             phpfluent/filter - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. phpfluent/filter

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

phpfluent/filter
================

0.3.0(11y ago)12332MITPHP

Since May 6Pushed 3y ago5 watchersCompare

[ Source](https://github.com/PHPFluent/Filter)[ Packagist](https://packagist.org/packages/phpfluent/filter)[ Docs](http://github.com/PHPFluent/Filter)[ RSS](/packages/phpfluent-filter/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

PHPFluent\\Filter
=================

[](#phpfluentfilter)

[![Build Status](https://camo.githubusercontent.com/bd4a3a03a3737f39cf7adcd3152ef6048d6a92917b7b37f494ed2d4ec862cb33/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f504850466c75656e742f46696c7465722e706e67)](http://travis-ci.org/PHPFluent/Filter)[![Total Downloads](https://camo.githubusercontent.com/088086de9fddec31195c34f246c0a982cc47b03e9d225f18ca732bafdfd4aede/68747470733a2f2f706f7365722e707567782e6f72672f706870666c75656e742f66696c7465722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/phpfluent/filter)[![License](https://camo.githubusercontent.com/61d20142a5c67b987ec922a34aa34e9cde91833bd6b0d60021aed5c61e2c3cb4/68747470733a2f2f706f7365722e707567782e6f72672f706870666c75656e742f66696c7465722f6c6963656e73652e706e67)](https://packagist.org/packages/phpfluent/filter)[![Latest Stable Version](https://camo.githubusercontent.com/19cb370f8f7a39595820168639fc68a6589398aa4def9a683bd19fec490d6287/68747470733a2f2f706f7365722e707567782e6f72672f706870666c75656e742f66696c7465722f762f737461626c652e706e67)](https://packagist.org/packages/phpfluent/filter)[![Latest Unstable Version](https://camo.githubusercontent.com/f8a385a376bdbea41c35695436ea7f80d121a75175e478922b12eec98d1a5315/68747470733a2f2f706f7365722e707567782e6f72672f706870666c75656e742f66696c7465722f762f756e737461626c652e706e67)](https://packagist.org/packages/phpfluent/filter)

Provider a better API to handle Zend filters.

Installation
------------

[](#installation)

Package is available on [Packagist](https://packagist.org/packages/phpfluent/filter), you can install it using [Composer](http://getcomposer.org).

```
composer require phpfluent/filter
```

Usage
-----

[](#usage)

The static API was inspired on [Respect\\Validation](https://github.com/Respect/Validation).

### Namespace Import

[](#namespace-import)

*PHPFluent\\Filter* is namespaced, but you can make your life easier by importing a single class into your context:

```
use PHPFluent\Filter\Builder as f;
```

### Calling a filter

[](#calling-a-filter)

```
f::stringToUpper()->filter('phpfluent'); // returns: 'PHPFLUENT'
```

### Calling multiple filters

[](#calling-multiple-filters)

```
f::stringToUpper()
 ->stringTrim()
 ->filter('filter    '); // returns 'FILTER'
```

### Calling native PHP functions

[](#calling-native-php-functions)

```
f::json_encode(JSON_PRETTY_PRINT)
 ->filter(array('key' => 'value')); // returns: '{"key": "value"}'
```

### Non-static API

[](#non-static-api)

You also can simply create an instance of `PHPFluent\Filter\Builder`.

```
$builder = new PHPFluent\Filter\Builder();
$builder->ucfirst();
$builder->str_pad(10, '-');
$builder->filter('filter'); // returns: 'Filter----'
```

### Calling Builder class

[](#calling-builder-class)

`PHPFluent\Filter\Builder` implements `__invoke()` method, so you can do like:

```
$builder('filter'); // returns: 'Filter----'
```

### Custom filters

[](#custom-filters)

You can use your own Zend filters.

```
f::myFilter();
```

For that purpose we provide a way to add your own namespaces/prefixes:

```
f::getDefaultFactory()->appendPrefix('My\\Filter\\Prefix');
```

So, in the example above `v::myFilter()` will call `My\Filter\PrefixMyFilter`.

You can implement your own filter.

```
use PHPFluent\Filter\FilterInterface;

class UrlFilter implements FilterInterface
{
    public function filter($value)
    {
        return filter_var($value, FILTER_SANITIZE_URL);
    }
}
```

### Filter factory

[](#filter-factory)

To create the filters by its name we use our Factory; there are two ways to change the Factory to be used.

#### Static calls

[](#static-calls)

```
$factory = new PHPFluent\Filter\Factory();
$factory->prependPrefix('My\\Zend\\Filters\\');

PHPFluent\Filter\Builder::setDefaultFactory($factory);
```

In the example above the defined factory will be used for all static calls.

#### Non-static calls

[](#non-static-calls)

```
$factory = new PHPFluent\Filter\Factory();
$factory->prependPrefix('My\\Zend\\Filters\\');

$builder = new PHPFluent\Filter\Builder($factory);
```

In the example above the defined factory will be used only for the `$builder` instance variable.

As you could note, the factory instance if optional, so, when you did defined a factory for the builder object it will use the default one, defined on `getDefaultFactory()`.

### PHPFluent filters

[](#phpfluent-filters)

#### key()

[](#key)

Allows to perform filters over an array key.

```
f::key('foo', f::boolean())
    ->filter(array('foo' => 1, 'baz' => 'Whatever')); // array('foo' => true)
```

If you're looking for something more specific you should take a look on [Zend\\InputFilter](http://framework.zend.com/manual/current/en/modules/zend.input-filter.intro.html).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~172 days

Total

3

Last Release

4051d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/154023?v=4)[Henrique Moody](/maintainers/henriquemoody)[@henriquemoody](https://github.com/henriquemoody)

![](https://www.gravatar.com/avatar/d0ac2250592af3b5a1971d373e9dc5bbc2a3279e3f92045bfbb5abe9eeb4d113?d=identicon)[kinncj](/maintainers/kinncj)

---

Top Contributors

[![henriquemoody](https://avatars.githubusercontent.com/u/154023?v=4)](https://github.com/henriquemoody "henriquemoody (8 commits)")[![halfer](https://avatars.githubusercontent.com/u/480975?v=4)](https://github.com/halfer "halfer (2 commits)")[![kinncj](https://avatars.githubusercontent.com/u/292542?v=4)](https://github.com/kinncj "kinncj (2 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/phpfluent-filter/health.svg)

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)[xemlock/htmlpurifier-html5

HTML5 support for HTML Purifier

1052.9M11](/packages/xemlock-htmlpurifier-html5)

PHPackages © 2026

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