Download the PHP package harp-orm/validate without Composer
On this page you can find all versions of the php package harp-orm/validate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package validate
Harp Validate
Harp Validate is a validation library. It generates errors for objects based on a predefined assertions.
Quick Example:
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.
You can also traverse through the Errors object using getFirst and getNext methods.
ValidateTrait
You can also add a special trait to an object to make it "validatable".
It will addd these methods to your class:
| Method | Description |
|---|---|
| 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 errors |
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.
Assert if the value is not a proper email address. uses a small and fast regex which should handle most cases.
EmailStrict
Assert if the value is not a proper email address. Uses a slower but more comprehensive check thane Email.
GreaterThan
Assert that the value is greater than a set length. Value can be int or float or even numeric string
InArray
Assert if the value is present in an array, uses a simple in_array call. Will throw InvalidArgumentException if the array is empty.
IP
Assert that the value's is a valid IP address uses filter_var() internally
IsInstanceOf
Assert if the value is an object of a given class is_a call. Will throw InvalidArgumentException if the class does not exist.
LengthBetween
Assert that the value's string length is between two set lengths (including). Uses mb_strlen() internally.
LengthEquals
Assert that the value is of exact string length. Uses mb_strlen() internally.
LengthGreaterThan
Assert that the value's string length is longer than a set length. Uses mb_strlen() internally.
LengthLessThan
Assert that the value's string length is shorter than a set length. Uses mb_strlen() internally.
LessThan
Assert that the value is less than a set length. Value can be int or float or even numeric string
Matches
Assert that a value of one property matches to the value of another
IsInteger
Assert that the value is a integer number.
IsFloat
Assert that the value is a float number.
Present
Assert if the value is empty
RegEx
Assert that the value matches a given regex. Passed directly to preg_match()
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.
URLStrict
Assert if the value is a valid url. Uses php's filter_var() method.
AssertsTrait
This trait gives you the ability to easily add assertions to another object.
Here are all the methods added by this trait.
| Method | Description |
|---|---|
| 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 object |
License
Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin as part of clippings.com
Under BSD-3-Clause license, read LICENSE file.

