PHPackages                             expresspaygh/exp-refine - 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. expresspaygh/exp-refine

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

expresspaygh/exp-refine
=======================

A request filtering and sanitization package with custom validations

1.0.3(5y ago)22072MITPHPPHP ^7.0CI failing

Since Jun 21Pushed 5y agoCompare

[ Source](https://github.com/expresspaygh/refine)[ Packagist](https://packagist.org/packages/expresspaygh/exp-refine)[ RSS](/packages/expresspaygh-exp-refine/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (3)Versions (3)Used By (2)

Table of Contents
=================

[](#table-of-contents)

1. \[Expresspay Refines\]
    1. \[Basic Usage\]
    2. \[Custom field types\]
    3. \[Writing custom rules\]

Expresspay Refine
=================

[](#expresspay-refine)

A simple server-side request filter, sanitizer and validator

Basic Usage
-----------

[](#basic-usage)

`Expay\\Refine\\Filter` does most of the work. Most calls to the class will only use the methods `addField` and `check`.

A field is defined with its key in the request and a value indicating its type. When this value is a string, its used to lookup a stored list of rules to filter the request value with.

```
use Expay\Refine\Filter;
use Expay\Refine\Rules;

$result = (new Filter())
	->addField("password", "string")
	->addField("email", "email")
	->check([
	"email" => "someone@expresspaygh.com",
	"password" => "hackme"
]);

print_r($result);
```

```
Array
(
	[status] => 0
	[message] => Success
	[output] => Array
		(
			[password] => hackme
			[email] => someone@expresspaygh.com
		)

)

```

Custom field types
------------------

[](#custom-field-types)

Custom field types can be added by specifying the rules to apply to them. This can be done with the following code:

```
use Expay\Refine\Filter;
use Expay\Refine\Rules;

$result = (new Filter())
	// add a field type called boolean_value
	->addRule("uppercase_bool", new Rules\Boolean('upper'))
	->addRules("email", [
		new Rules\Required,
		new Rules\PHPFilter([
			'filter' => FILTER_VALIDATE_EMAIL | FILTER_SANITIZE_EMAIL
		])])
	->addField("is_admin", "uppercase_bool")
	->addField("email", "email")
	->check([
		"is_admin" => "true",
		"email" => "admin@example.com"
	]);

print_r($result);
```

```
Array
(
	[status] => 0
	[message] => Success
	[output] => Array
		(
			[is_admin] => TRUE
			[email] => admin@example.com
		)

)

```

A factory function can be used to avoid repeating definitions.

```
use Expay\Refine\Filter;
use Expay\Refine\Rules;

function filter() {
	return (new Filter())
	// add a field type called boolean_value
	->addRule("uppercase_bool", new Rules\Boolean('upper'))
	->addRules("email", [
		new Rules\Required,
		new Rules\PHPFilter([
			'filter' => FILTER_VALIDATE_EMAIL | FILTER_SANITIZE_EMAIL
	])]);
}

print_r(filter()->check([
	"is_admin" => "true",
	"email" => "admin@example.com"
]));
```

```
Array
(
	[status] => 0
	[message] => Success
	[output] => Array
		(
			[email] => admin@example.com
		)

)

```

Writing custom rules
--------------------

[](#writing-custom-rules)

Custom rules can be written by sub-classing `\Expay\Refine\Rules\Rule` and implementing the apply method.

```
use Expay\Refine\Filter;
use Expay\Refine\Rules\Rule;
use Expay\Refine\Exceptions\InvalidField;

class CVV extends Rule
{
	public function apply($value, string $key, array $request): string
	{
		if (preg_match("/^\d\d\d$/", $value))
			return $value;
		throw new InvalidField("Invalid cvv");
	}
}

$result = (new Filter())
	->addRule("cvv", new CVV)
	->check(["cvv" => "123"]);

var_dump($result);
```

```
array(3) {
  'status' =>
  int(0)
  'message' =>
  string(7) "Success"
  'output' =>
  array(1) {
    'cvv' =>
    string(3) "123"
  }
}

```

---

Writing validations
-------------------

[](#writing-validations)

Validations can be written by adding the filter rule and validation rules.

Visit this github repository [Rakit/Validation](https://github.com/rakit/validation#available-rules) for more validation rule options you can use.

```
use Expay\Refine\Rules;
use Expay\Refine\Filter;
use Expay\Refine\Exceptions\ValidationError;

try
{
	$filter=new Filter;

	$vRules=["email"=>"required|present|email"];
	$fields=["email"=>[new Rules\Validate($vRules),new Rules\CleanTags]];
	$data=["email"=>"info@expresspaygh.com"];

	$result=$filter->addFields($fields)->check($data);
}
catch(ValidationError $e)
{
	$result=$e->getMessage();
}

var_dump($result);
```

```
array(3) {
  ["status"]=>
  int(0)
  ["message"]=>
  string(7) "Success"
  ["output"]=>
  array(1) {
    ["email"]=>
    string(19) "info@expresspaygh.com"
  }
}

```

Writing Custom Validation Rules
-------------------------------

[](#writing-custom-validation-rules)

Custom validation rules can be written by adding the filter rule, then add validation rules as first argument and key value pairs containing your custom validation rule names and their respective classes as a second argument to the filter rule.

Visit this github repository [Rakit/Validation/Override/Rules](https://github.com/rakit/validation#registeroverride-rule) for more custom validation rule options you can use.

```
use Expay\Refine\Rules;
use Expay\Refine\Filter;
use Expay\Refine\Exceptions\ValidationError;
use Rakit\Validation\Rule as ValidationRule;

/**
 * ValidationRuleObjectProvider
 */
class ValidationRuleObjectProvider extends ValidationRule
{
  /**
   * message
   *
   * @var string
   */
  protected $message = "";

  /**
   * __construct
   *
   * @return void
   */
  public function __construct()
  {
    $this->message=":value is not a valid object";
  }

  /**
   * check
   *
   * @param  mixed $value
   * @return bool
   */
  public function check($value) : bool
  {
    return is_object($value);
  }
}

try
{
	$filter=new Filter;

	$vRules=['randomObj'=>'required|object_value'];
	$customRules=["object_value"=>new ValidationRuleObjectProvider];

	$fields=["obj_field"=>[new Rules\Validate($vRules,$customRules)]];

	$objData=new \stdClass();
	$objData->{"hello"}="hello sir";
	$data=["obj_field"=>$objData];

	$result=$filter->addFields($fields)->check($data);
}
catch(ValidationError $e)
{
	$result=$e->getMessage();
}

var_dump($result);
```

```
array(3) {
  ["status"]=>
  int(0)
  ["message"]=>
  string(7) "Success"
  ["output"]=>
  array(1) {
    ["obj_field"]=>
    object(stdClass)#900 (1) {
      ["hello"]=>
      string(9) "hello sir"
    }
  }
}

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 67.5% 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 ~233 days

Total

2

Last Release

1915d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5dfe48dadea582a8a1879ddc335a27e5c7477a9ffd9d99bee004d9b49ffa8eed?d=identicon)[expressPay](/maintainers/expressPay)

---

Top Contributors

[![because-i-had-to](https://avatars.githubusercontent.com/u/66310808?v=4)](https://github.com/because-i-had-to "because-i-had-to (27 commits)")[![expclonne101](https://avatars.githubusercontent.com/u/66310158?v=4)](https://github.com/expclonne101 "expclonne101 (9 commits)")[![kweihesse](https://avatars.githubusercontent.com/u/61884208?v=4)](https://github.com/kweihesse "kweihesse (4 commits)")

---

Tags

cleanerfilter-rulephprequesthandlerrequestssanitizer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/expresspaygh-exp-refine/health.svg)

```
[![Health](https://phpackages.com/badges/expresspaygh-exp-refine/health.svg)](https://phpackages.com/packages/expresspaygh-exp-refine)
```

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