PHPackages                             mivir/pupil - 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. mivir/pupil

AbandonedArchivedLibrary

mivir/pupil
===========

1.2.0(12y ago)017BSDPHPPHP &gt;=5.3.0

Since Sep 15Pushed 12y ago1 watchersCompare

[ Source](https://github.com/Dragory/Pupil.php)[ Packagist](https://packagist.org/packages/mivir/pupil)[ RSS](/packages/mivir-pupil/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Pupil
=====

[](#pupil)

An easy and powerful string-based validation library.

This is **Pupil.php**, the PHP version of the library.

Other available versions:

- [Pupil.js](https://github.com/Dragory/Pupil.js)

Features
--------

[](#features)

- Nested validation rules
- String-based validation rules for compatibility between different languages
- Light revalidation via caching

Changelog
---------

[](#changelog)

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

[](#installation)

### Via Composer

[](#via-composer)

Add `"mivir/pupil": "1.*"` to the "require" section of composer.json.

### Via downloading

[](#via-downloading)

Download the repository. Point a PSR-0 autoloader at the src folder or require the files manually.

Usage
-----

[](#usage)

The basic syntax is this:

```
$pupil = new \Mivir\Pupil\Pupil();
$pupil->validate($rules, $values);
```

Where `$rules` and `$values` are arrays with matching keys. The rules are specified as `rule strings`; more information on those below.

For example:

```
$rules = array(
	'name' => 'min(3) && max(8) && regex("^[a-zA-Z]+$")',
	'country' => 'min(2)'
);

$values = array(
	'name' => $nameInput,
	'country' => $countryInput
);
```

The two arrays don't have to have identical keys, but values without a matching key in rules won't be evaluated at all.

The `validate()` method returns an object that has the following methods:

```
isValid()   // Whether the validation was successful or not
hasErrors() // The opposite of isValid()
errors()    // Returns the fields that didn't pass validation
fields()    // Returns all of the fields and their validation results
```

Rule strings
------------

[](#rule-strings)

Rule strings are Pupil's primary method of specifying validation rules.

The syntax aims to mimic C-like languages. You can use logical operators (`&& (and)`, `|| (or)`, `! (not)`), ternaries (`condition ? thenRule : elseRule`), nested "blocks" (`rule && (some || nested || rules)`) and validation functions (`validationFunction("arg1", "arg2")`).

**String parameters for validation functions, such as the regex in the "regex" function, should be quoted.**
Non-quoted parameters will be cast to floats (numbers with decimals).

For each validation function, there is also a matching function prepended by `other` that allows you to run functions on other values than the one the rule string is for. This can be useful for fields that have differing requirements depending on another field. For example:

```
array(
	'state' => 'otherEquals("country", "US") ? lenMin(2) : lenMin(0)'
)
```

Validation function arguments can be either strings or numerical values. Numerical arguments should not be wrapped in quotation marks or apostrophes: `lenMin(5)`.

Validation functions
--------------------

[](#validation-functions)

The following functions are available by default:

```
equals
iEquals      # A case-insensitive comparison
sEquals      # A strict comparison
siEquals
lenMin
lenMax
lenEquals
min
max
between
in           # Compare to a list of values
required
optional
numeric
alpha
alphaNumeric
email
regex        # Supply a custom regex
integer
equalsTo     # Compare to another field by its key

```

### Adding custom functions

[](#adding-custom-functions)

You can use the following syntax to add your own validation functions:

```
$pupil->addFunction($name, $callable);
```

Where callable is either an anonymous function or one created with create\_function and should, at the very least, accept two arguments: `$allValues` and `$value`. `$allValues` is an object containing every value that's being validated at the moment while `$value` contains the value we're validating at the moment. Further arguments can be passed in rule strings like so:

```
customFunction("arg1", "arg2")
```

The function names are case-insensitive.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

4620d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/59a3a34ea964f827d01b8a66805683e780d7c9e92b7b1f106683fb249b39a9e9?d=identicon)[Dragory](/maintainers/Dragory)

---

Top Contributors

[![Dragory](https://avatars.githubusercontent.com/u/2606411?v=4)](https://github.com/Dragory "Dragory (5 commits)")

### Embed Badge

![Health badge](/badges/mivir-pupil/health.svg)

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

PHPackages © 2026

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