PHPackages                             param-processor/param-processor - 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. param-processor/param-processor

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

param-processor/param-processor
===============================

Parameter processing library

1.12.0(5y ago)22640.0k↑61.9%4[5 issues](https://github.com/JeroenDeDauw/ParamProcessor/issues)[1 PRs](https://github.com/JeroenDeDauw/ParamProcessor/pulls)8GPL-2.0-or-laterPHPPHP &gt;=7.1

Since Nov 21Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/JeroenDeDauw/ParamProcessor)[ Packagist](https://packagist.org/packages/param-processor/param-processor)[ Docs](https://github.com/JeroenDeDauw/ParamProcessor)[ GitHub Sponsors](https://github.com/JeroenDeDauw)[ RSS](/packages/param-processor-param-processor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (8)Versions (28)Used By (8)

ParamProcessor
==============

[](#paramprocessor)

ParamProcessor is a parameter processing library that provides a way to declaratively define a set of parameters and how they should be processed. It can take such declarations together with a list of raw parameters and provide the processed values. For example, if one defines a parameter to be an integer, in the range `[0, 100]`, then ParamProcessor will verify the input is an integer, in the specified range, and return it as an actual integer variable.

Also see [ParserHooks](https://github.com/JeroenDeDauw/ParserHooks), a library that builds on top of ParamProcessor and provides MediaWiki integration.

[![Build Status](https://camo.githubusercontent.com/fdda458e0523443d43a56db129920f4241e6f2f98ec1a40c10f4ab89814743be/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f4a65726f656e4465446175772f506172616d50726f636573736f722e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/JeroenDeDauw/ParamProcessor)[![Code Coverage](https://camo.githubusercontent.com/dfdcffacfe37973190152ae2f546ceb687e7e21144fef2d416bf371ed4d8e5ce/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4a65726f656e4465446175772f506172616d50726f636573736f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/JeroenDeDauw/ParamProcessor/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1bf36dba79147716845a4c98e5b24a6eed8a2fe8365039d0c901abd53868be90/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4a65726f656e4465446175772f506172616d50726f636573736f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/JeroenDeDauw/ParamProcessor/?branch=master)

On [Packagist](https://packagist.org/packages/param-processor/param-processor): [![Latest Stable Version](https://camo.githubusercontent.com/08659a15c33b73060b96dc828befec035025f6476e52f24f38a0515c16f1002e/68747470733a2f2f706f7365722e707567782e6f72672f706172616d2d70726f636573736f722f706172616d2d70726f636573736f722f76657273696f6e2e706e67)](https://packagist.org/packages/param-processor/param-processor)[![Download count](https://camo.githubusercontent.com/7023e67a8350353f4b3b1b4c24514ada6fce6341ee0ba415efd33fa7bfff4f69/68747470733a2f2f706f7365722e707567782e6f72672f706172616d2d70726f636573736f722f706172616d2d70726f636573736f722f642f746f74616c2e706e67)](https://packagist.org/packages/param-processor/param-processor)

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

[](#installation)

The recommended way to use this library is via [Composer](http://getcomposer.org/).

### Composer

[](#composer)

To add this package as a local, per-project dependency to your project, simply add a dependency on `param-processor/param-processor` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on version 1.x of this package:

```
{
    "require": {
        "param-processor/param-processor": "~1.0"
    }
}
```

### Manual

[](#manual)

Get the code of this package, either via git, or some other means. Also get all dependencies. You can find a list of the dependencies in the "require" section of the composer.json file. Then take care of autoloading the classes defined in the src directory.

Concept
-------

[](#concept)

The goal of the ParamProcessor library is to make parameter handling simple and consistent.

In order to achieve this, a declarative API for defining parameters is provided. Passing in such parameter definitions together with a list of raw input into the processor leads to a processed list of parameters. Processing consists out of name and alias resolving, parsing, validation, formatting and defaulting.

If ones defines an "awesomeness" parameter of type "integer", one can be sure that at the end of the processing, there will be an integer value for the awesomeness parameter. If the user did not provide a value, or provided something that is invalid, while the parameter it is required, processing will abort with a fatal error. If on the other hand there is a default, the default will be set. If the value was invalid, a warning will be kept track of. In case the user provides a valid value, for instance "42" (string), it will be turned in the appropriate 42 (int).

Implementation structure
------------------------

[](#implementation-structure)

Parameters are defined using the `ParamProcessor\ParamDefinition` class. Users can also use the array format to define parameters and not be bound to this class. At present, it is preferred to use this array format as the class itself is not stable yet.

Processing is done via `ParamProcessor\Processor`.

Defining parameters
-------------------

[](#defining-parameters)

### Array definition schema

[](#array-definition-schema)

These fields are supported:

  Name Type Default Description   name string *required*    type string (enum) string    default mixed null If this value is null, the parameter has no default and is required   aliases array of string empty array Aliases for the name   trim boolean *inherited from processor options* If the value should be trimmed   islist boolean false    delimiter string , The delimiter between values if it is a list   manipulatedefault boolean true If the default value should also be manipulated   values array  Allowed values   message string *required*    post-format callback *none* Takes the value as only parameter and returns the new value The requires fields currently are: name and message

### Core parameter types

[](#core-parameter-types)

  Name PHP return type Description   string string  Default type
 Supported options: - length: int or false (overrides minlength and maxlength)
- minlength: int or false
- maxlength: int or false
- regex: string

    boolean boolean Accepts "yes", "no", "on", "off", "true" and "false"   float float  Supported options: - lowerbound: int, float or false
- upperbound: int, float or false
- range: \[lowerbound, upperbound\]
- withinrange: \[float $point, float $deviation\]

    integer integer  Supported options: same as for float    dimension string  Value for a width or height attribute in HTML
 Supported options: - allowauto: bool
- maxpercentage: int
- minpercentage: int
- units: array of string
- defaultunit: string
- lowerbound: int, float or false
- upperbound: int, float or false

  Defining parameter types
------------------------

[](#defining-parameter-types)

- `string-parser` Name of a class that implements the `ValueParsers\ValueParser` interface
- `validation-callback` Callback that gets the raw value as only parameter and returns a boolean
- `validator` Name of a class that implements the `ValueValidators\ValueValidator` interface

As an example, the Maps MediaWiki extension defines a `coordinate` parameter type that turns the input into a `DataValues\LatLongValue` value object.

Usage example
-------------

[](#usage-example)

### Defining parameters

[](#defining-parameters-1)

```
$parameterDefinitions = [
    'username' => [
        'minlength' => 1,
        'maxlength' => 20
    ],
    'job' => [
        'default' => 'unknown',
        'values' => [ 'Developer', 'Designer', 'Peasant' ]
    ],
    'favourite-numbers' => [
        'type' => 'int',
        'islist' => true,
        'default' => []
    ]
]
```

### Processing input using defined parameters

[](#processing-input-using-defined-parameters)

```
$processor = ParamProcessor\Processor::newDefault();

$processor->setParameters(
    [
        'username' => 'Jeroen',
        'favourite-numbers' => '42, 1337, not a number',
    ],
    $paramDefinitions
);

foreach ($processor->processParameters()->getParameters() $parameter) {
    echo $parameter->getName();
    var_dump($parameter->getValue());
};

// username: string(6) "Jeroen"
// job: string(7) "unknown"
// favourite-numbers: array(2) {[0]=>int(42), [1]=>int(1337)}
```

Alternative way to input parameters:

```
$processor->setFunctionParams(
    [
        'username = Jeroen',
        'favourite-numbers=42, 1337, not a number',
    ],
    $paramDefinitions
);
```

Contributing
------------

[](#contributing)

- [File an issue](https://github.com/JeroenDeDauw/ParamProcessor/issues)
- [Submit a pull request](https://github.com/JeroenDeDauw/ParamProcessor/pulls) ([tasks for newcomers](https://github.com/JeroenDeDauw/ParamProcessor/issues?q=is%3Aissue+is%3Aopen+label%3Anewcomer))

Authors
-------

[](#authors)

ParamProcessor has been written by [Jeroen De Dauw](https://www.entropywins.wtf/) to support the [Maps](https://github.com/JeroenDeDauw/Maps) and [Semantic MediaWiki](https://semantic-mediawiki.org/) projects.

Release notes
-------------

[](#release-notes)

### 1.12.0 (2021-05-04)

[](#1120-2021-05-04)

- Allowed installation with PHP 8.x

### 1.11.0 (2021-03-18)

[](#1110-2021-03-18)

- Allowed installation with new DataValue library versions

### 1.10.0 (2019-08-03)

[](#1100-2019-08-03)

- Removed `DimensionParam`
- Fixed bug in parsing of parameters of type `dimension`

### 1.9.0 (2019-08-03)

[](#190-2019-08-03)

- Added `ParamDefinitionFactory::newDefinitionsFromArrays`

### 1.8.0 (2019-08-03)

[](#180-2019-08-03)

- Removed `ParamDefinitionFactory::getComponentForType`
- Added `ParamDefinitionFactory` constructor
- Added `ParameterTypes` constructor
- Added `ParameterTypes::addType`
- Added `ParameterTypes::newCoreTypes`
- Added `ProcessingResult::getParameterArray`

### 1.7.0 (2019-08-02)

[](#170-2019-08-02)

- Added `ParameterTypes` public constants: `BOOLEAN`, `FLOAT`, `INTEGER`, `STRING`, `DIMENSION`
- Deprecated `ParamDefinition::getCleanDefinitions` in favour of `ParamDefinitionFactory`
- Deprecated `ParamDefinition::setDefault` in favour of constructor parameter
- Deprecated `Processor::getParameterValues` in favour of `processParameters` and `ProcessingResult`
- Deprecated `Processor::getErrors` in favour of `processParameters` and `ProcessingResult`
- Deprecated `Processor::getErrorMessages` in favour of `processParameters` and `ProcessingResult`
- Deprecated `Processor::hasErrors` in favour of `processParameters` and `ProcessingResult`
- Deprecated `Processor::hasFatalError` in favour of `processParameters` and `ProcessingResult`
- Deprecated parameter dependencies
    - Deprecated `ParamDefinition::hasDependency`
    - Deprecated `ParamDefinition::addDependencies`
    - Deprecated `ParamDefinition::getDependencies`
    - Deprecated `dependencies` key in `ParamDefinition::setArrayValues` parameter
    - Deprecated `TopologicalSort`
    - Deprecated `TSNode`
- Deprecated extending `ParamDefinition`
- Deprecated `StringParam`
- Deprecated `DimensionParam`
- Deprecated `ParamDefinition::setArrayValues`
- Deprecated `ParamDefinition::$acceptOverriding`
- Deprecated `ParamDefinition::$accumulateParameterErrors`
- Deprecated `Param::$accumulateParameterErrors`
- Deprecated `Settings`
- Deprecated `Options::setRawStringInputs`
- Deprecated `Options::isStringlyTyped`

### 1.6.1 (2019-07-28)

[](#161-2019-07-28)

- Fixed message defaulting bug in `ParamDefinition`

### 1.6.0 (2019-07-28)

[](#160-2019-07-28)

- Added `Processor::setParameterDefinitions`
- Deprecated second parameter of `Processor::setParameters` in favour of `setParameterDefinitions`
- Deprecated second parameter of `Processor::setFunctionParams` in favour of `setParameterDefinitions`
- Deprecated second parameter of `ParamDefinitionFactory::newDefinitionFromArray`
- Deprecated return value of `ParamDefinitionFactory::registerType`
- Deprecated `ParamDefinitionFactory::registerGlobals`
- Deprecated `typed-parser` key in parameter type definitions

### 1.5.0 (2019-07-28)

[](#150-2019-07-28)

- Improved code comments and added extra type checks

### 1.4.2 (2018-11-26)

[](#142-2018-11-26)

- Fixed defaulting behaviour of list parameters

### 1.4.1 (2018-11-26)

[](#141-2018-11-26)

- List parameters are no longer set to their default when a single value is invalid

### 1.4.0 (2018-11-25)

[](#140-2018-11-25)

- Dropped support for PHP older than 7.1
- Added `ParameterTypes` to allow gradual migration away from the now deprecated `$wgParamDefinitions`
- Deprecated `$wgParamDefinitions`
- Deprecated `$egValidatorSettings`

### 1.3.4 (2018-05-05)

[](#134-2018-05-05)

- Fixed deprecation notice occurring with PHP 7.2+

### 1.3.3 (2017-09-28)

[](#133-2017-09-28)

- Installation together with DataValues 2.x is now allowed
- Installation together with DataValues Common 0.4.x is now allowed

### 1.3.2 (2017-03-26)

[](#132-2017-03-26)

- Fixed clearing of processing errors when making multiple processing calls to one `Processor` instance

### 1.3.1 (2016-09-21)

[](#131-2016-09-21)

- Fixed `ParamDefinitionFactory` emitting a warning when initialized without the global `wgParamDefinitions` being set

### 1.3.0 (2016-07-15)

[](#130-2016-07-15)

- Dropped support for PHP 5.3 and PHP 5.4.
- Fixed bug in `ParamDefinition::format`

### 1.2.5 (2016-05-23)

[](#125-2016-05-23)

- Fixed bug in `Processor::newProcessingResult`

### 1.2.4 (2016-05-15)

[](#124-2016-05-15)

- Fixed bug in `ParamDefinition::getAllowedValues`

### 1.2.3 (2016-04-04)

[](#123-2016-04-04)

- Installation together with DataValues Interfaces 0.2.x is now allowed
- Installation together with DataValues Common 0.3.x is now allowed
- The component is now also tested against PHP 7

### 1.2.2 (2014-10-24)

[](#122-2014-10-24)

- Installation together with DataValues 1.x is now allowed.

### 1.2.0 (2014-09-12)

[](#120-2014-09-12)

- Dropped dependency on DataValues Geo.

### 1.1.0 (2014-05-07)

[](#110-2014-05-07)

- Dropped dependency on DataValues Time.
- Use PSR-4 based loading rather than PSR-0 based loading.
- Fixed Windows compatibility in PHPUnit bootstrap

### 1.0.2 (2013-12-16)

[](#102-2013-12-16)

- Removed dependency on data-values/number
- Updated required version of data-values/common from ~0.1 to ~0.2.

### 1.0.1 (2013-11-29)

[](#101-2013-11-29)

- Implemented ProcessingResult::hasFatal
- Added ProcessingResultTest

### 1.0.0 (2013-11-21)

[](#100-2013-11-21)

First release as standalone PHP library.

Links
-----

[](#links)

- [ParamProcessor on Packagist](https://packagist.org/packages/param-processor/param-processor)
- [ParamProcessor on TravisCI](https://travis-ci.org/JeroenDeDauw/ParamProcessor)
- [ParamProcessor on ScrutinizerCI](https://scrutinizer-ci.com/g/JeroenDeDauw/ParamProcessor/)
- [MediaWiki extension "Validator"](https://www.mediawiki.org/wiki/Extension:Validator) - a wrapper around this library for MediaWiki users

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance54

Moderate activity, may be stable

Popularity47

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 82.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 ~104 days

Recently: every ~160 days

Total

27

Last Release

1840d ago

PHP version history (4 changes)1.0PHP &gt;=5.3.0

1.3.0PHP &gt;=5.5.0

1.4.0PHP ~7.1

1.12.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

---

Top Contributors

[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (778 commits)")[![translatewiki](https://avatars.githubusercontent.com/u/24829418?v=4)](https://github.com/translatewiki "translatewiki (133 commits)")[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (9 commits)")[![paladox](https://avatars.githubusercontent.com/u/5727000?v=4)](https://github.com/paladox "paladox (4 commits)")[![siebrand](https://avatars.githubusercontent.com/u/210297?v=4)](https://github.com/siebrand "siebrand (4 commits)")[![mwjames](https://avatars.githubusercontent.com/u/1245473?v=4)](https://github.com/mwjames "mwjames (3 commits)")[![kghbln](https://avatars.githubusercontent.com/u/1104078?v=4)](https://github.com/kghbln "kghbln (2 commits)")[![hashar](https://avatars.githubusercontent.com/u/281689?v=4)](https://github.com/hashar "hashar (2 commits)")[![thiemowmde](https://avatars.githubusercontent.com/u/6576639?v=4)](https://github.com/thiemowmde "thiemowmde (2 commits)")[![gbirke](https://avatars.githubusercontent.com/u/223326?v=4)](https://github.com/gbirke "gbirke (1 commits)")[![ganqqwerty](https://avatars.githubusercontent.com/u/697308?v=4)](https://github.com/ganqqwerty "ganqqwerty (1 commits)")[![DanweDE](https://avatars.githubusercontent.com/u/101926?v=4)](https://github.com/DanweDE "DanweDE (1 commits)")[![addshore](https://avatars.githubusercontent.com/u/3308769?v=4)](https://github.com/addshore "addshore (1 commits)")

---

Tags

validatormediawikiparametersdeclarativeParamProcessorSMWSemantic MediaWikiVaidation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/param-processor-param-processor/health.svg)

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

###  Alternatives

[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[mediawiki/semantic-media-wiki

An extension to MediaWiki that lets you store and query structured data within wiki pages

586361.8k33](/packages/mediawiki-semantic-media-wiki)[ergebnis/json-schema-validator

Provides a JSON schema validator, building on top of justinrainbow/json-schema.

3626.9M7](/packages/ergebnis-json-schema-validator)[mediawiki/semantic-result-formats

Provides additional result formats for queries using Semantic MediaWiki

51180.7k1](/packages/mediawiki-semantic-result-formats)[mediawiki/semantic-extra-special-properties

Provides extra special properties for Semantic MediaWiki

3074.6k1](/packages/mediawiki-semantic-extra-special-properties)[mediawiki/semantic-scribunto

A Semantic Mediawiki extension to natively support the Scribunto extension

2967.5k](/packages/mediawiki-semantic-scribunto)

PHPackages © 2026

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