PHPackages                             danack/params - 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. danack/params

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

danack/params
=============

Converts user input into correctly typed parameters

0.8.0(3y ago)6475↓75%1[3 issues](https://github.com/Danack/Params/issues)MITPHPPHP ^8.0

Since May 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Danack/Params)[ Packagist](https://packagist.org/packages/danack/params)[ RSS](/packages/danack-params/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependencies (13)Versions (28)Used By (0)

Library renamed to TypeSpec
===========================

[](#library-renamed-to-typespec)

So won't be any activity here.

Params
======

[](#params)

A framework agnostic library for validating input parameters.

[![Build Status](https://camo.githubusercontent.com/46ac2dd882d494b89c5888f8305f11cf57c8422bedcfa7827cc278693bdd62c8/68747470733a2f2f7472617669732d63692e6f72672f44616e61636b2f506172616d732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Danack/Params)

[![Actions Status](https://github.com/Danack/Params/workflows/Tests/badge.svg)](https://github.com/Danack/Params/actions)

Installation
============

[](#installation)

`composer require danack/params`

TL:DR - Using in an application
===============================

[](#tldr---using-in-an-application)

This library allows you to define a [set of rules](https://github.com/Danack/Params/blob/1121bda4f5e6a04fcdb4f82a21da0ed83fe79d2f/lib/ParamsExample/GetArticlesParams.php#L71-L92) that define the expected input parameters, and then validate them.

As an example, this is what the code looks like in a controller for retrieving a list of articles:

```
function getArticles(Request $request)
{
    $getArticlesParams = GetArticlesParams::createFromRequest($request);

    echo "After Id: " . $articleGetIndexParams->getAfterId() . PHP_EOL;
    echo "Limit:    " . $articleGetIndexParams->getLimit() . PHP_EOL;
}

```

The above example will throw a `ValidationException` with a list of all the validation problems if there are any.

Alternatively you can have the parameters and list of errors returned as tuple.

```
function getArticles(Request $request)
{
    [$getArticlesParams, $errors] = GetArticlesParams::createOrErrorFromVarMap($request);

    if ($errors !== null) {
        // do something about those errors.
    }

    echo "After Id: " . $articleGetIndexParams->getAfterId() . PHP_EOL;
    echo "Limit:    " . $articleGetIndexParams->getLimit() . PHP_EOL;
}

```

Under the hood, basic usage
===========================

[](#under-the-hood-basic-usage)

Given a set of rules, the library will extract the appropriate values from a 'variable map' and validate that the values meet the defined rules:

```
$rules = [
  'limit' => [
    new CheckSetOrDefault(10, $variableMap),
    new IntegerInput(),
    new MinIntValue(0),
    new MaxIntValue(100),
  ],
  'offset' => [
    new CheckSetOrDefault(null, $variableMap),
    new SkipIfNull(),
    new MinIntValue(0),
    new MaxIntValue(1000000),
  ],
];

list($limit, $offset) = Params::validate($params);
```

That code will extract the 'limit' and 'offset values from the variable map and check that the limit is an integer between 0 and 100, and that offset is either not set, or must be an integer between 0 and 1,000,000.

If there are any validation problems a ValidationException will be thrown. The validation problems can be retrieved from ValidationException::getValidationProblems.

Under the hood, basic usage without exceptions
==============================================

[](#under-the-hood-basic-usage-without-exceptions)

Alternatively, you can avoid using exceptions for flow control:

```
$validator = new ParamsValidator();

$limit = $validator->validate('limit', [
    new CheckSetOrDefault(10, $variableMap),
    new IntegerInput(),
    new MinIntValue(0),
    new MaxIntValue(100),
]);

$offset = $validator->validate('offset', [
    new CheckSetOrDefault(null, $variableMap),
    new SkipIfNull(),
    new MinIntValue(0),
    new MaxIntValue(1000000),
]);

$errors = $validator->getValidationProblems();

if (count($errors) !== 0) {
    // return an error
    return [null, $errors];
}

// return an object with null
return [new GetArticlesParams($order, $limit, $offset), null];
```

Tests
-----

[](#tests)

We have several tools that are run to improve code quality. Please run `sh runTests.sh` to run them all.

Pull requests should have full unit test coverage. Preferably also full mutation coverage through infection.

Related info
============

[](#related-info)

Json pointers - JSON Patch -

Future work
===========

[](#future-work)

Support Uri fragment encoding on paths
--------------------------------------

[](#support-uri-fragment-encoding-on-paths)

```
    #            // the whole document
    #/foo        ["bar", "baz"]
    #/foo/0      "bar"
    #/           0
    #/a~1b       1
    #/c%25d      2
    #/e%5Ef      3
    #/g%7Ch      4
    #/i%5Cj      5
    #/k%22l      6
    #/%20        7
    #/m~0n       8

```

Parameter location
------------------

[](#parameter-location)

Some people care whether a parameter is in the query string or body. This library currently doesn't support differentiating them.

TODO
----

[](#todo)

- colors.
- Error on unknown/invalid names. e.g. when the input include 'namme', and so the 'name' param uses default value, that sounds like an error.
- Generate OpenAPI stuff better.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 99% 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 ~69 days

Recently: every ~197 days

Total

23

Last Release

1392d ago

PHP version history (3 changes)0.4.1PHP ^7.2

0.6.0PHP ^7.4

0.8.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9db967c6005625e444a502fb830a30669b9fed53bfbc67e81a054508c0975a6b?d=identicon)[Danack](/maintainers/Danack)

---

Top Contributors

[![Danack](https://avatars.githubusercontent.com/u/1505719?v=4)](https://github.com/Danack "Danack (204 commits)")[![DanFuture](https://avatars.githubusercontent.com/u/28150630?v=4)](https://github.com/DanFuture "DanFuture (2 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/danack-params/health.svg)

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

###  Alternatives

[webmozart/assert

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

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[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)

PHPackages © 2026

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