PHPackages                             phly/phly-rule-validation - 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. phly/phly-rule-validation

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

phly/phly-rule-validation
=========================

Simple rule-based validation framework

0.2.1(1y ago)42691BSD-2-ClausePHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0

Since Nov 9Pushed 1y ago3 watchersCompare

[ Source](https://github.com/phly/phly-rule-validation)[ Packagist](https://packagist.org/packages/phly/phly-rule-validation)[ RSS](/packages/phly-phly-rule-validation/feed)WikiDiscussions 0.2.x Synced 1mo ago

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

phly/phly-rule-validation
=========================

[](#phlyphly-rule-validation)

[![Build Status](https://github.com/phly/phly-rule-validation/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/phly/phly-rule-validation/actions/workflows/continuous-integration.yml)

This library provides a barebones validation framework.

Goals of this library
---------------------

[](#goals-of-this-library)

The explicit goals of this library are:

- Provide an idempotent way to validate individual items and/or data sets.
- Provide an extensible framework for developing validation rules.
- Allow handling optional data, with default values.
- Allow reporting validation error messages.
- Ensure missing required values are reported as validation failures.
- Use as few dependencies as possible.

Non-goals:

- Creating an extensive set of validation rule classes.
- Providing extensive mechanisms for validating and returning nested data sets.
- Providing a configuration-driven mechanism for creating rule sets.
- Providing HTML form input representations or all metadata required to create HTML form input representations.

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

[](#installation)

```
composer require phly/phly-rule-validation
```

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

[](#basic-usage)

```
use Phly\RuleValidation\Result\Result;
use Phly\RuleValidation\RuleSet\RuleSet;
use Phly\RuleValidation\Rule\CallbackRule;

$rules = new RuleSet();
$rules->add(new CallbackRule('flag', function (mixed $value, array $data): Result {
    if (! is_bool($value)) {
        return Result::forInvalidValue('flag', $value, 'Not a boolean value');
    }
    return Result::forValidValue('flag', $value);
}, default: false));
$rules->add(new MyCustomRule());
// and so on

$resultSet = $rules->validate($someFormData);

if ($resultSet->isValid()) {
    $values = $resultSet->getValues();
    // do something with values
} else {
    $messages = $resultSet->getMessages();
    // do something with error messages
}

// Get a result for a single key:
$flagResult = $resultSet->flag; // or $resultSet->getResult('flag')

// Get the value from a single result
$flag = $flagResult->value();

// Get the validation status from a single result
if ($flagResult->isValid()) {
    // ...
}

// Get an error message for a single result
if (! $flagResult->isValid()) {
    echo $flagResult->message();
}
```

Documentation
-------------

[](#documentation)

Please see the [documentation tree (docs/)](./docs/README.md).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

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

Recently: every ~95 days

Total

6

Last Release

530d ago

PHP version history (3 changes)0.1.0PHP ~8.2.0

0.2.0PHP ~8.2.0 || ~8.3.0

0.2.1PHP ~8.2.0 || ~8.3.0 || ~8.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25943?v=4)[Matthew Weier O'Phinney](/maintainers/weierophinney)[@weierophinney](https://github.com/weierophinney)

---

Top Contributors

[![weierophinney](https://avatars.githubusercontent.com/u/25943?v=4)](https://github.com/weierophinney "weierophinney (60 commits)")

---

Tags

validation

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phly-phly-rule-validation/health.svg)

```
[![Health](https://phpackages.com/badges/phly-phly-rule-validation/health.svg)](https://phpackages.com/packages/phly-phly-rule-validation)
```

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k489.6M671](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M415](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M381](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M106](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

64236.9M185](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

8412.9M47](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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