PHPackages                             clippings/carpo - 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. clippings/carpo

Abandoned → [harp-orm/validate](/?search=harp-orm%2Fvalidate)Library[Validation &amp; Sanitization](/categories/validation)

clippings/carpo
===============

Object validaiton library

0.4(11y ago)1193[1 PRs](https://github.com/harp-orm/validate/pulls)BSD-3-ClausePHP

Since Mar 17Pushed 11y ago5 watchersCompare

[ Source](https://github.com/harp-orm/validate)[ Packagist](https://packagist.org/packages/clippings/carpo)[ RSS](/packages/clippings-carpo/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (7)DependenciesVersions (9)Used By (0)

Harp Validate
=============

[](#harp-validate)

[![Build Status](https://camo.githubusercontent.com/92110d1e778d114562662d9e20db6a927ec843b247a6bbb1e5e81f2340b06ff9/68747470733a2f2f7472617669732d63692e6f72672f686172702d6f726d2f76616c69646174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/harp-orm/validate)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/42a50065d1c7d92efa7fe390e6b5494786baca4ae5dfe2e3ca7f128b3143a372/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686172702d6f726d2f76616c69646174652f6261646765732f7175616c6974792d73636f72652e706e673f733d36653735343163653464303933613034616238303065333461633863333133356637333130656532)](https://scrutinizer-ci.com/g/harp-orm/validate/)[![Code Coverage](https://camo.githubusercontent.com/bf23c5b473bdebcf3854ac2a68caedcaca8ba11212fb0e869c4d8106b73ec96b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686172702d6f726d2f76616c69646174652f6261646765732f636f7665726167652e706e673f733d62626633643961666462303464393366323439326130623833646564363635633933363265613762)](https://scrutinizer-ci.com/g/harp-orm/validate/)[![Latest Stable Version](https://camo.githubusercontent.com/e22c0b6fc686c910fc6b008abe5296f5aee4f3c2f5bd4763e494e2fe6ed44140/68747470733a2f2f706f7365722e707567782e6f72672f686172702d6f726d2f76616c69646174652f762f737461626c652e737667)](https://packagist.org/packages/harp-orm/validate)

Harp Validate is a validation library. It generates errors for objects based on a predefined assertions.

Quick Example:

```
use Harp\Validate\Assert;
use Harp\Validate\Asserts;

$asserts = new Asserts(array(
    new Assert\Present('title'),
    new Assert\LengthBetween('title', 20, 100),
    new Assert\Email('newsletter_email'),
));

$subject = new stdClass();
$subject->title = 'small title';
$subject->newsletter_email = 'invalid email';

// title should be between 10 and 20 letters, newsletter_email should be a valid email
echo $asserts->getErrors($subject);
```

Errors
------

[](#errors)

The result of `$asserts->getErrors($subject)` is actually an `Errors` object. It's an Iterator that holds all the erorrs and has `->humanize()` mehtod to display all the errors. You can also foreach it and get all the errors separately. Casting it to string calls `->humanize()` automatically.

```
$errors = $asserts->getErrors($subject);

foreach($errors => $error) {
    echo $error->getName();
    echo $error->getMessage();
}
```

You can also traverse through the Errors object using `getFirst` and `getNext` methods.

```
$errors = $asserts->validate($subject);

echo $errors->getFirst();
echo $errors->getNext();
```

ValidateTrait
-------------

[](#validatetrait)

You can also add a special trait to an object to make it "validatable".

```
use Harp\Validate\ValidateTrait;
use Harp\Validate\Asserts;
use Harp\Validate\Assert\Present;

class Model
{
    use ValidateTrait;

    public $test;

    public function getValidationAsserts()
    {
        return new Asserts(array(
            new Present('test'),
        ));
    }
}
```

It will addd these methods to your class:

MethodDescription**validate**()Perform the assertions, specified in the getValidationAsserts(). Will return true or false, and will set the `errors` object**getErrors**()Returns an `Errors` object. If validate has not been called yet, will return an empty `Errors` object**isEmptyErrors**()Return true or false**assertValid**()Throw Harp\\Validate\\InvalidException if there are any errorsAvailable Asserts
-----------------

[](#available-asserts)

**Callback**

Assert that the result of a given callback is true. You must use a closure object, and will recieve the subject and the value as arguments.

```
new Callback('state', function ($subject, $value) {
    return $value !== 'test';
})
```

**Email**

Assert if the value is not a proper email address. uses a small and fast regex which should handle most cases.

```
new Email('email_address')
new Email('email_address', 'some custom message')
```

**EmailStrict**

Assert if the value is not a proper email address. Uses a slower but more comprehensive check thane `Email`.

```
new EmailStrict('email_address')
new EmailStrict('email_address', 'some custom message')
```

**GreaterThan**

Assert that the value is greater than a set length. Value can be int or float or even numeric string

```
new GreaterThan('price', 20)
new GreaterThan('price', 20, 'some custom message')
```

**InArray**

Assert if the value is present in an array, uses a simple `in_array` call. Will throw InvalidArgumentException if the array is empty.

```
new InArray('state', array('big', 'small'))
new InArray('state', array('big', 'small'), 'some custom message')
```

**IP**

Assert that the value's is a valid IP address uses `filter_var()` internally

```
new IP('last_login_ip')
new IP('last_login_ip', 'some custom message')
```

**IsInstanceOf**

Assert if the value is an object of a given class `is_a` call. Will throw InvalidArgumentException if the class does not exist.

```
new IsInstanceOf('state', 'My\Example\Item')
new IsInstanceOf('state', 'My\Example\Item', 'some custom message')
```

**LengthBetween**

Assert that the value's string length is between two set lengths (including). Uses `mb_strlen()` internally.

```
new LengthLessThan('name', 10, 200)
new LengthLessThan('name', 10, 200, 'some custom message')
```

**LengthEquals**

Assert that the value is of exact string length. Uses `mb_strlen()` internally.

```
new LengthEquals('name', 20),
new LengthEquals('name', 20, 'some custom message')
```

**LengthGreaterThan**

Assert that the value's string length is longer than a set length. Uses `mb_strlen()` internally.

```
new LengthGreaterThan('name', 20)
new LengthGreaterThan('name', 20, 'some custom message')
```

**LengthLessThan**

Assert that the value's string length is shorter than a set length. Uses `mb_strlen()` internally.

```
new LengthLessThan('name', 20)
new LengthLessThan('name', 20, 'some custom message')
```

**LessThan**

Assert that the value is less than a set length. Value can be int or float or even numeric string

```
new LessThan('price', 20)
new LessThan('price', 20, 'some custom message')
```

**Matches**

Assert that a value of one property matches to the value of another

```
new Matches('password', 'password_confirmation')
new Matches('password', 'password_confirmation', 'some custom message')
```

**IsInteger**

Assert that the value is a integer number.

```
new IsInteger('quantity')
new IsInteger('quantity', 'some custom message')
```

**IsFloat**

Assert that the value is a float number.

```
new IsFloat('frequency')
new IsFloat('frequency', 'some custom message')
```

**Present**

Assert if the value is empty

```
new Present('title')
new Present('title', 'some custom message if needed')
```

**RegEx**

Assert that the value matches a given regex. Passed directly to `preg_match()`

```
new RegEx('card_number', '/\d{20}/')
new RegEx('card_number', '/\d{20}/', 'some custom message')
```

**URL**

Assert if the value is a valid url. Converts all UTF related charecters in the url to their proper encoding. It also will convert non-ASCII domain names, using "idn" if the "intl" extension is available. This is similar to what browsers normally do.

```
new URL('website')
new URL('website', 'some custom message')
```

**URLStrict**

Assert if the value is a valid url. Uses php's `filter_var()` method.

```
new URLStrict('website')
new URLStrict('website', 'some custom message')
```

AssertsTrait
------------

[](#assertstrait)

This trait gives you the ability to easily add assertions to another object.

```
class TestConfig {
    use AssertsTrait;
}

$config = new TestConfig();

$config
    ->assertPresent('name')
    ->assertURL('homepage', 'must have a valid homepage');

// Return the Asserts object
$config->getAsserts();
```

Here are all the methods added by this trait.

MethodDescription**getAsserts**()Get the Asserts object**addAssert**(AbstractAssertion)Add arbitrary asserts**assertCallback**($name, $message)Add an Assert\\Callback object**assertEmail**($name, $message)Add an Assert\\Email object**assertEmailStrict**($name, $message)Add an Assert\\EmailStrict object**assertGreaterThan**($name, $value, $message)Add an Assert\\GreaterThan object**assertInArray**($name, $array, $message)Add an Assert\\InArray object**assertIP**($name, $message)Add an Assert\\IP object**assertIsInteger**($name, $message)Add an Assert\\IsInteger object**assertIsInstanceOf**($name, $class, $message)Add an Assert\\IsInstanceOf object**assertIsFloat**($name, $message)Add an Assert\\IsFloat object**assertLengthBetween**($name, $min, $max, $message)Add an Assert\\LengthBetween object**assertLengthEquals**($name, $length, $message)Add an Assert\\LengthEquals object**assertLengthGreaterThan**($name, $length, $message)Add an Assert\\LengthGreaterThan object**assertLengthLessThan**($name, $length, $message)Add an Assert\\LengthLessThan object**assertLessThan**($name, $value, $message)Add an Assert\\LessThan object**assertMatches**($name, $property, $message)Add an Assert\\Matches object**assertPresent**($name, $message)Add an Assert\\Present object**assertRegEx**($name, $pattern, $message)Add an Assert\\RegEx object**assertURL**($name, $message)Add an Assert\\URL object**assertURLStrict**($name, $message)Add an Assert\\URLStrict objectLicense
-------

[](#license)

Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin as part of [clippings.com](http://clippings.com)

Under BSD-3-Clause license, read LICENSE file.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community12

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

Every ~27 days

Recently: every ~12 days

Total

7

Last Release

4273d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/506129?v=4)[Harry Dobrev](/maintainers/hkdobrev)[@hkdobrev](https://github.com/hkdobrev)

![](https://avatars.githubusercontent.com/u/4113307?v=4)[Danail Kyosev](/maintainers/dkyosev)[@dkyosev](https://github.com/dkyosev)

![](https://avatars.githubusercontent.com/u/7592650?v=4)[Evstati Zarkov](/maintainers/EZarkov)[@EZarkov](https://github.com/EZarkov)

![](https://avatars.githubusercontent.com/u/745771?v=4)[Filip Georgiev](/maintainers/phgeorgiev)[@phgeorgiev](https://github.com/phgeorgiev)

![](https://avatars.githubusercontent.com/u/490439?v=4)[Zdravko Evstatiev](/maintainers/zedevs)[@zedevs](https://github.com/zedevs)

---

Top Contributors

[![ivank](https://avatars.githubusercontent.com/u/4976?v=4)](https://github.com/ivank "ivank (49 commits)")

### Embed Badge

![Health badge](/badges/clippings-carpo/health.svg)

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

###  Alternatives

[webmozart/assert

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

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[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)

PHPackages © 2026

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