PHPackages                             proteins/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. proteins/filter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

proteins/filter
===============

Class trait for permitting users to override data via callback hooks

1.0.3(6y ago)0494MITPHPPHP ^7.2

Since May 28Pushed 6y ago1 watchersCompare

[ Source](https://github.com/php-protein/filter)[ Packagist](https://packagist.org/packages/proteins/filter)[ RSS](/packages/proteins-filter/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (4)Used By (4)

[![](https://raw.githubusercontent.com/php-protein/docs/master/assets/protein-large.png)](https://raw.githubusercontent.com/php-protein/docs/master/assets/protein-large.png)

Protein | Filter
================

[](#protein--filter)

Class trait for permitting users to override data via callback hooks
--------------------------------------------------------------------

[](#class-trait-for-permitting-users-to-override-data-via-callback-hooks)

### Install

[](#install)

---

```
composer require proteins/filter

```

Require the global class via :

```
use Proteins\Filter;
```

or the include the trait in your classes via :

```
use Proteins\Filters;

class MyClass {
    use Filters;
}
```

### Adding a filter

[](#adding-a-filter)

---

You can attach a filter function to a custom named group via the `add` method.

```
Filter::add('title',function($title){
   return strtoupper($title);
});
```

Multiple calls to the same group attach multiple filter functions.

```
// Concatenate effects :
Filter::add('title',function($title){
   return strtoupper($title);
});

Filter::add('title',function($title){
   return $title . '!';
});
```

You can assign a single callback to multiple filters defining them with an array of keys :

```
Filter::add(['href','src'], function($link){
   return BASE_URL . $link;
});
```

> This is the same as :
>
> ```
> Filter::add('href', function($link){
>   return BASE_URL . $link;
> });
>
> Filter::add('src', function($link){
>   return BASE_URL . $link;
> });
> ```

You can also pass an array map filter =&gt; callback :

```
Filter::add([
   'src' => function($src){
     return BASE_URL . $src;
    },
   'href' => function($href){
     return HTTPS . $href;
    },
]);
```

> This is the same as :
>
> ```
> Filter::add('href', function($href){
>   return HTTPS . $href;
> });
>
> Filter::add('src', function($src){
>   return BASE_URL . $src;
> });
> ```

### Removing a filter

[](#removing-a-filter)

---

You can remove an attached filter function to a custom named group via the `remove` method.

```
$the_filter = function($title){
   return strtoupper($title);
};

Filter::add('title',$the_filter);

...

Filter::remove('title',$the_filter);
```

You can remove all filters attached to a group by not passing the filter function.

```
Filter::remove('title');
```

### Applying a filter

[](#applying-a-filter)

---

You can apply a filter to a value via the `with` method.

```
Filter::with('title','This was a triumph')
```

**Example**

```
Filter::add('title',function($title){
   return strtoupper($title);
});

Filter::add('title',function($title){
   return $title . '!';
});

echo Filter::with('title','This was a triumph');

// THIS WAS A TRIUMPH!
```

Multiple fallback keys can be passed, the first non-empty queue will be used for the current filter.

```
Filter::with(["document.title", "title"],'This was a triumph')
```

**Example**

```
Filter::add("title", "strtoupper");
echo Filter::with(["document.title", "title"],'This was a triumph');
```

The `title` filter will be executed instead of the empty `document.title`.

```
THIS WAS A TRIUMPH

```

```
Filter::add("title", "strtoupper");
Filter::add("document.title", "str_rot13");
echo Filter::with(["document.title", "title"],'This was a triumph');
```

Here the `document.title` filter will be executed instead of `title`.

```
Guvf jnf n gevhzcu

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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 ~0 days

Total

3

Last Release

2544d ago

### Community

Maintainers

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

---

Top Contributors

[![lastguest](https://avatars.githubusercontent.com/u/178900?v=4)](https://github.com/lastguest "lastguest (3 commits)")

### Embed Badge

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

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

PHPackages © 2026

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