PHPackages                             layliaiyong/former - 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. layliaiyong/former

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

layliaiyong/former
==================

Form validate with annotation

v1.0.0(7y ago)013MITPHPPHP &gt;=5.4

Since Jul 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/layliaiyong/former)[ Packagist](https://packagist.org/packages/layliaiyong/former)[ RSS](/packages/layliaiyong-former/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

former
======

[](#former)

Form validate with annotation

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

[](#installation)

Package is available on [Packagist](http://packagist.org/packages/layliaiyong/former), you can install it using [Composer](http://getcomposer.org).

```
composer require layliaiyong/former
```

[PHP](https://php.net) 5.4+

Annotation
----------

[](#annotation)

Property must be protected. Annotation option value must be json string.

Annotation Patterns:

- Former...

End with [https://github.com/Respect/Validation](https://github.com/Respect/Validation "respect/Validation") validator

```
class TestFormer extends Former
{
    /**
     * @FormerNotEmpty {"message":"ID must not be empty"}
     * @FormerIntVal {"message":"ID must be integer"}
     */
    protected $id;
}

$data = new \stdClass();
$validator = new TestFormer();
// pass
$data->id = 1;
$valid = $validator->input($data)->validate();// true
$errors = $validator->errors();// []
// error
$data->id = 'abc';
$valid = $validator->input($data)->validate();// false
$errors = $validator->errors();// ["ID must be integer"]
```

- NotFormer...

End with `respect/Validation` validator

```
class TestFormer extends Former
{
    /**
     * @NotFormerIntVal {"message":"ID must not be integer"}
     */
    protected $id;
}

$data = new \stdClass();
$validator = new TestFormer();
// pass
$data->id = 1;
$valid = $validator->input($data)->validate();// false
$errors = $validator->errors();// ["ID must be integer"]
// error
$data->id = 'abc';
$valid = $validator->input($data)->validate();// true
$errors = $validator->errors();// []
```

- Former

```
class TestFormer extends Former
{
    /**
     * @FormerObjectType {"message":"former must be object"}
     * @Former {"message":"invalid former","former":"\\TestObjectFormer"}
     */
    protected $former;
}
class TestObjectFormer extends Former
{
    /**
     * @FormerNotEmpty {"message":"ID must not be empty"}
     * @FormerIntVal {"message":"ID must be integer"}
     */
    protected $id;
}

$data = new \stdClass();
$former = new \stdClass();
$validator = new TestFormer();
// pass
$former->id = 1;
$data->former = $former;
$valid = $validator->input($data)->validate();// true
$errors = $validator->errors();// []
// error
$former->id = 'abc';
$data->former = $former;
$valid = $validator->input($data)->validate();// false
$errors = $validator->errors();// ["[former]invalid former","[id]ID must be integer"]
```

- Formers

```
class TestFormer extends Former
{
    /**
     * @FormerObjectType {"message":"formers must be object array"}
     * @Former {"message":"invalid formers","former":"\\TestObjectFormer"}
     */
    protected $formers;
}
class TestObjectFormer extends Former
{
    /**
     * @FormerNotEmpty {"message":"ID must not be empty"}
     * @FormerIntVal {"message":"ID must be integer"}
     */
    protected $id;
}

$data = new \stdClass();
$former = new \stdClass();
$validator = new TestFormer();
// pass
$former->id = 1;
$data->formers = [$former];
$valid = $validator->input($data)->validate();// true
$errors = $validator->errors();// []
// error
$former->id = 'abc';
$data->formers = [$former];
$valid = $validator->input($data)->validate();// false
$errors = $validator->errors();// ["[formers]invalid formers","[id]ID must be integer"]
```

- CaseFormer

```
class TestFormer extends Former
{
    /**
     * @CaseFormer [{"message":"invalid case when value is 1","when":"FormerEquals","params":[1],"former":"\\TestCaseFormer"}]
     */
    protected $case;
    protected $case1;
}
class TestCaseFormer extends Former
{
    /**
     * @FormerNotEmpty {"message":"ID must not be empty"}
     * @FormerIntVal {"message":"ID must be integer"}
     */
    protected $case1;
}

$data = new \stdClass();
$validator = new TestFormer();
// pass
$data->case = 1;
$data->case1 = 2;
$valid = $validator->input($data)->validate();// true
$errors = $validator->errors();// []
// error
$data->case = 1;
$data->case1 = 'abc';
$valid = $validator->input($data)->validate();// false
$errors = $validator->errors();// ["[case]invalid case when value is 1","[case1]ID must be integer"]
```

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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

2898d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34503?v=4)[Lay](/maintainers/Lay)[@lay](https://github.com/lay)

---

Top Contributors

[![aiyongli](https://avatars.githubusercontent.com/u/62636704?v=4)](https://github.com/aiyongli "aiyongli (8 commits)")[![layliaiyong](https://avatars.githubusercontent.com/u/20119813?v=4)](https://github.com/layliaiyong "layliaiyong (1 commits)")

---

Tags

annotationformvalidatevalidateformannotation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/layliaiyong-former/health.svg)

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

###  Alternatives

[webmozart/assert

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

7.6k917.5M1.5k](/packages/webmozart-assert)[awurth/slim-validation

A wrapper around the respect/validation PHP validation library for easier error handling and display

65393.6k9](/packages/awurth-slim-validation)[progsmile/request-validator

Simple PHP Request Validator

33114.0k1](/packages/progsmile-request-validator)[stefangabos/zebra_form

A jQuery augmented PHP library for creating and validating HTML forms

961.2k](/packages/stefangabos-zebra-form)

PHPackages © 2026

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