PHPackages                             danbettles/morf - 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. danbettles/morf

ActiveLibrary

danbettles/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.

v2.0.0(11mo ago)0877—0%ISCPHPPHP ^8.3

Since Nov 13Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/danbettles/morf)[ Packagist](https://packagist.org/packages/danbettles/morf)[ RSS](/packages/danbettles-morf/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

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
-------

[](#example)

It's pretty straightforward:

```
use DanBettles\Morf\Filter;

$definitions = [
    [
        'name' => 'anything',  // N.B. `name` is the only required element
        // 'type' => 'string',  // The default output-type
    ],
    [
        'name' => 'show_retirement',
        'type' => 'bool',  // Or use `"boolean"`
        // 'default' => false,  // The built-in default value of a Boolean
    ],
    [
        'name' => 'show_under_offer',
        'type' => 'bool',
        'default' => true,  // N.B. the same type as named in `type`
    ],
    [
        'name' => 'location_id',
        'type' => 'int',  // Or use `"integer"`
        'default' => 7,
        'validator' => 'positiveInteger',  // See Built-In Validators, below
    ],
    [
        'name' => 'num_rooms',
        'type' => 'int',
        'default' => -1,
        'validValues' => [-1, 1, 2, 3],  // `validValues` takes precedence over `validator`
    ],
    [
        'name' => 'a_floating_point_number',
        'type' => 'float',  // Or use `"double"`
    ],
    [
        'name' => 'an_array',
        'type' => 'array',
    ],
];

// Empty request, so defaults applied:

$actual = Filter::create($definitions)->filter([]);

$expected = [
    'anything' => '',
    'show_retirement' => false,
    'show_under_offer' => true,
    'location_id' => 7,
    'num_rooms' => -1,
    'a_floating_point_number' => 0.0,
    'an_array' => [],
];

assert($expected === $actual);

// Form submitted, say:

$actual = Filter::create($definitions)->filter([
    'anything' => 'Hello, World!',
    'show_retirement' => '0',
    'show_under_offer' => '0',
    'location_id' => '2',
    'num_rooms' => '2',
    'a_floating_point_number' => '3.142',
    'an_array' => ['foo', 'bar', 'baz'],
]);

$expected = [
    'anything' => 'Hello, World!',
    'show_retirement' => false,
    'show_under_offer' => false,
    'location_id' => 2,
    'num_rooms' => 2,
    'a_floating_point_number' => 3.142,
    'an_array' => ['foo', 'bar', 'baz'],
];

assert($expected === $actual);
```

Valid Inputs
------------

[](#valid-inputs)

TypeValid Input`bool`, `boolean``"1"`, `"0"`[1](#user-content-fn-1-387810427460059444229d89b7d2e7a2)`int`, `integer`Any integer in string form`float`, `double`Any float/integer in string form`string`Any string`array`Any arrayDefault Values
--------------

[](#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`](https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/HttpFoundation/ParameterBag.php), 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](#example).

Built-In Validators
-------------------

[](#built-in-validators)

NameValid Value`positiveInteger`Integer &gt; 0`nonNegativeInteger`Integer &gt;= 0Footnotes
---------

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. [↩](#user-content-fnref-1-387810427460059444229d89b7d2e7a2)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance52

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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

Total

4

Last Release

335d ago

Major Versions

v0.0.0 → v1.0.02023-11-13

v1.1.0 → v2.0.02025-06-18

PHP version history (2 changes)v0.0.0PHP ^7.4|^8.1.3

v2.0.0PHP ^8.3

### Community

Maintainers

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

---

Top Contributors

[![danbettles](https://avatars.githubusercontent.com/u/736672?v=4)](https://github.com/danbettles "danbettles (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/danbettles-morf/health.svg)

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

PHPackages © 2026

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