PHPackages                             oligriffiths/validation-component - 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. oligriffiths/validation-component

ActiveNooku-component[Validation &amp; Sanitization](/categories/validation)

oligriffiths/validation-component
=================================

A validation component for the Nooku platform

0.0.1(11y ago)07GPLPHP

Since Oct 3Pushed 11y ago1 watchersCompare

[ Source](https://github.com/oligriffiths/Nooku-Validation-Component)[ Packagist](https://packagist.org/packages/oligriffiths/validation-component)[ RSS](/packages/oligriffiths-validation-component/feed)WikiDiscussions master Synced today

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

---

Validation component for Nooku Framework 0.9
============================================

[](#validation-component-for-nooku-framework-09)

---

The component consists of 4 major parts

- Validatable controller behavior
- Validatable database behavior
- Constraints
- Validators &amp; Filters

This component is designed to be plug and play very easily. Database schemas are also converted into constraints and applied automatically.

---

Controller behavior:
--------------------

[](#controller-behavior)

The controller behavior is responsible for handling validation before add/edit/save/apply. Errors are caught and raised as notices as opposed to exceptions thrown by the database behavior.

To implement this, add 'com://oligriffiths/validation.controller.behavior.validatable' to the controller that will save the entity

Database behavior:
------------------

[](#database-behavior)

The database behavior is responsible for reading the database schema and converting this into associated constraints. It also handles running validation before insert/update, storing the current data should validation fail, and re-populating the object after select, so no need to handle storing the data yourself.

To implement this, add 'com://oligriffiths/validation.database.behavior.validatable' to the database table for the entity

Constraints:
------------

[](#constraints)

The concept of constraints and validators is borrowed from symphony. A constraint holds the meta data that is used to perform a validation. Constraints has types, different constraints contain different validation parameters, for example:

- min - holds a minimum value and a specific error message should validation fail
- image - holds mime types, min/max width/height and related error messages

A constraint must implement `Nooku\Component\Validation\ConstraintInterface`

Validators:
-----------

[](#validators)

A validator is where the leg work happens for validation. Validators take a value and a constraint, and validate the value against the constraints parameters. If validation fails, validators must throw an exception with the specific error message or true on success. If a validator does not have a specific implementation (class in the validators folder) then the default validator class will be loaded. This in turn loads a corresponding Filter from the Nooku library. Some validators have custom implementations that can not be achieved with a filter, usually validators that require the input to be an array (Nooku filters automatically iterate arrays and validate the values)

There are 2 additional types that are of importance

Constraint sets:
----------------

[](#constraint-sets)

Constraint sets hold a set of constraints, and all those constraints can be validated by the `validate()` method

Validator sets:
---------------

[](#validator-sets)

Validator sets hold constraint sets by key and are used to validate an array of key/value pairs

---

Validators:
-----------

[](#validators-1)

Here is a list of the available validators (explainations provided where necessary):

```
alnum        array(
                'constraints' => array(
                    'password' => array('md5')
                )
            )
        )
    ))
}
```

The example above attached the MD5 constraint to the password column.

Note: passing through a constraint for a column will cause the constraints loaded from the database to be merged with the custom constraints. To surpress this functionality pass 'replace' =&gt; true through.

#### Controller Behavior

[](#controller-behavior-1)

If you are attaching the database behavior, it is advised to also attached the controller behavior so that errors thrown by the database behavior are caught, and the appropriate redirect is set.

To do so add the behavior in the \_initialize method of the controller:

```
protected function _initialize(\Nooku\Library\Config $config)
{
    $config->append(array(
        'behaviors' => array(
            'com:validation.controller.behavior.validatable'
        )
    ))
}
```

#### Custom uses

[](#custom-uses)

Constraints and validators can also be used in a stand alone mode for any time you wish to validate some data. All you need to do it get an instance of the constraint, and call validate on the constraint, passing your data value in.

E.g.:

```
$this->getObject('com:validation.constraint.email')->validate('test@test.com');
```

If the email address is valid, true will be returned, else an exception will be thrown.

For simple validation that just required true/false without the error itself;

```
$valid = $this->getObject('com:validation.constraint.email')->isValid('test@test.com');
```

The exception will be caught and true/false returned. To access the specific error that was thrown, call `getError()` on the constraint;

##### Constraint sets

[](#constraint-sets-1)

Constraints can also be added to a constraint set; a group on constraints upon which a value can be validated against. All constraints in the set must validate for the set to be valid.

```
$set = $this->getObject('com:validation.constraint.set', array(
    'constraints' => array(
        'com:validation.constraint.email',
        'com:validation.constraint.length' => array('min' => 0, 'max' => 150)
    )
));

$valid = $set->validate('test@test.com');
$errors = $set->getErrors();
```

You can also add constraints to an existing set by calling `$set->addConstraint()`

`$set->validate()` will return true/false for success/failure. The specific errors raised can be retrieved using `$set->getErrors()`;

##### Validator sets

[](#validator-sets-1)

Validator sets hold multiple constraint sets by key name. An array of data can then be validated against the constraint sets, each key of the data array corresponds to a key holding a constraint set.

For the validator set to be valid, all constraint sets must validate/return true;

```
$set = $this->getObject('com:validation.validator.set',
    array('constraints' =>
        'email' => array('com:validation.constraint.email'),
        'name' => array('com:validation.constraint.length' => array('min' => 0, 'max' => 150))
    )
));

$valid = $set->validate(array('email' => 'test@test.com', 'name' => 'Jon Doe'));
$errors = $set->getErrors();
```

The above will validate an array/iterable object with the keys email and name, against the constraints passed in to the validator set.

`$set->validate()` will return true/false on success/failure. The specific errors raised can be retrieved using `$set->getErrors()`;

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

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

4290d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1246671?v=4)[Oli Griffiths](/maintainers/oligriffiths)[@oligriffiths](https://github.com/oligriffiths)

---

Top Contributors

[![organicdevelopment](https://avatars.githubusercontent.com/u/1405452?v=4)](https://github.com/organicdevelopment "organicdevelopment (9 commits)")[![oligriffiths](https://avatars.githubusercontent.com/u/1246671?v=4)](https://github.com/oligriffiths "oligriffiths (6 commits)")

---

Tags

validationcomponentnooku

### Embed Badge

![Health badge](/badges/oligriffiths-validation-component/health.svg)

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

###  Alternatives

[composer/semver

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

3.3k522.3M990](/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.0k159.6M526](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

6.0k39.9M415](/packages/respect-validation)[propaganistas/laravel-phone

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

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

Json Schema Validator for PHP

65243.6M302](/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

9216.6M75](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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