PHPackages                             ride/lib-validation - 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. ride/lib-validation

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

ride/lib-validation
===================

Validation library of the Ride framework

1.6.2(1y ago)06.3k20MITPHP

Since Nov 29Pushed 1y ago7 watchersCompare

[ Source](https://github.com/all-ride/ride-lib-validation)[ Packagist](https://packagist.org/packages/ride/lib-validation)[ RSS](/packages/ride-lib-validation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (32)Used By (20)

Ride: Validation Library
========================

[](#ride-validation-library)

Validation library of the PHP Ride framework.

What's In This Library
----------------------

[](#whats-in-this-library)

- [Filters](#filters)
    - [AllowCharacterFilter](#allowcharacterfilter-characters)
    - [LowerCaseFilter](#lowercasefilter-lower)
    - [ReplaceFilter](#replacefilter-replace)
    - [SafeStringFilter](#safestringfilter-safestring)
    - [StripTagsFilter](#striptagsfilter-striptags)
    - [TrimFilter](#trimfilter-trim)
    - [UpperCaseFilter](#uppercasefilter-upper)
- [Validators](#validators)
    - [ClassValidator](#classvalidator-class)
    - [DsnValidator](#dsnvalidator-dsn)
    - [EmailValidator](#emailvalidator-email)
    - [FileExtensionValidator](#fileextensionvalidator-extension)
    - [JsonValidator](#jsonvalidator-json)
    - [MinMaxValidator](#minmaxvalidator-minmax)
    - [NumericValidator](#numericvalidator-numeric)
    - [RegexValidator](#regexvalidator-regex)
    - [RequiredValdiator](#requiredvalidator-required)
    - [SizeValidator](#sizevalidator-size)
    - [UrlValidator](#urlvalidator-url)
    - [WebsiteValdiator](#websitevalidator-website)
- [Constraints](#constraints)
    - [GenericConstraint](#genericconstraint-generic)
    - [OrConstraint](#orconstraint-or)
    - [EqualsConstraint](#equalsconstraint-equals)
    - [ConditionalConstraint](#conditionalconstraint-conditional)
    - [ChainConstraint](#chainconstraint-chain)
- [ValidationFactory](#validationfactory)
- [ValidationError](#validationerror)
- [ValidationException](#validationexception)
- [Code Sample](#code-sample)

### Filters

[](#filters)

The *Filter* interface is used to pre-process a value to fix input automatically. A filter should return the original value if it can't handle the input type.

Different implementations are available.

#### AllowCharacterFilter (characters)

[](#allowcharacterfilter-characters)

Filters all non-allowed characters from a string.

This filter has the following option:

- **characters**: all allowed characters, characters not found in this string, will be trimmed out (string)

#### LowerCaseFilter (lower)

[](#lowercasefilter-lower)

Transforms all upper case characters to lower case.

This filter has no options.

#### ReplaceFilter (replace)

[](#replacefilter-replace)

Replaces values in a string.

This filter has the following options:

- **search**: string to search for (string)
- **replacement**: replacement for the matches of search (string|optional)

#### SafeStringFilter (safeString)

[](#safestringfilter-safestring)

- **replacement**: replacement for special characters, defaults to - (string|optional)
- **lower**: transform to lower case, defaults to true (boolean|optional)

#### StripTagsFilter (stripTags)

[](#striptagsfilter-striptags)

Strips HTML and PHP tags from a string, using PHP's internal [strips\_tags](http://php.net/manual/en/function.strip-tags.php) function

This filter has the following option:

- **allowedTags**: a set of html tags that are allowed and won't be stripped, for example: ``.

#### TrimFilter (trim)

[](#trimfilter-trim)

Trims the provided value from spaces.

This filter has the following options:

- **trim.lines**: trim all lines, or values if the provided value is an array (boolean|optional)
- **trim.empty**: remove empty lines or values, only when *trim.lines* is enabled (boolean|optional)

#### UpperCaseFilter (upper)

[](#uppercasefilter-upper)

Transforms all lower case characters to upper case.

This filter has no options.

### Validators

[](#validators)

The *Validator* interface is used to validate a single value.

Different implementations are available.

#### ClassValidator (class)

[](#classvalidator-class)

Checks if the provided string is a valid class name

This validator has the following options:

- **class**: class which the provided class should implement or extend (string|optional)
- **required**: flag to see if a value is required (boolean|optional)

This validator generates the following errors:

- **error.validation.class**: default error message
- **error.validation.class.extends**: when the class does not extend the required class
- **error.validation.class.implements**: when the class does not implement the required interface

#### DsnValidator (dsn)

[](#dsnvalidator-dsn)

Checks if the provided string is a valid DSN.

This validator has the following option:

- **required**: flag to see if a value is required (boolean|optional)

This validator generates the following errors:

- **error.validation.dsn**: default error message (string|optional)
- **error.validation.required**: required error message (string|optional)

#### EmailValidator (email)

[](#emailvalidator-email)

Checks if the provided value is a valid email address.

This validator has the following option:

- **required**: flag to see if a value is required (boolean|optional)

This validator generates the following errors:

- **error.validation.email**: default error message
- **error.validation.required**: required error message

#### FileExtensionValidator (extension)

[](#fileextensionvalidator-extension)

Checks if the provided path string has an allowed extension.

This validator has the following options:

- **extensions**: allowed extensions (array)
- **required**: flag to see if a value is required (boolean|optional)

This validator generates the following errors:

- **error.validation.file.extension**: default error message
- **error.validation.required**: required error message

#### JsonValidator (json)

[](#jsonvalidator-json)

Checks if the json string is valid.

This validator has the following options:

- **required**: flag to see if a value is required (boolean|optional)

This validator generates the following errors:

- **error.validation.json**: default error message
- **error.validation.required**: required error message

#### MinMaxValidator (minmax)

[](#minmaxvalidator-minmax)

Checks if the provided numeric value is in the provided range.

This validator has the following options:

- **error.minimum**: error code when the value is less then minimum (string|optional)
- **error.maximum**: error code when the value is more then maximum (string|optional)
- **error.minimum.maximum**: error code when the value is not between minimum and maximum (string|optional)
- **error.numeric**: error code when the value is not numeric (string|optional)
- **minimum**: minimum value (numeric|optional)
- **maximum**: maximum value (numeric|optional)
- **required**: flag to see if a value is required (boolean|optional)

*Note: Minimum and maximum are both optional both at least one of them is required. The values for minimum and maximum are included in the range.*

This validator generates the following errors:

- **error.validation.minimum**: when the value is less then the provided minimum
- **error.validation.maximum**: when the value is greater then the provided maximum
- **error.validation.minmax**: when the value is less then the provided minimum or greater then the provided maximum
- **error.validation.required**: required error message

#### NumericValidator (numeric)

[](#numericvalidator-numeric)

Checks if the provided value is a numeric value.

This validator has the following options:

- **error.numeric**: error code when the value is not numeric (string|optional)
- **required**: flag to see if a value is required (boolean|optional)

This validator generates the following error:

- **error.validation.numeric**: default error message
- **error.validation.required**: required error message

#### RegexValidator (regex)

[](#regexvalidator-regex)

Checks if the provided string matches a regular expression.

This validator has the following options:

- **error.regex**: error code when the value did not match the regular expression (string|optional)
- **error.required**: error code when the required value was empty (string|optional)
- **regex**: regular expression to match (string)
- **required**: flag to see if a value is required (boolean|optional)

This validator generates the following errors:

- **error.validation.regex**: default error message
- **error.validation.required**: required error message

#### RequiredValdiator (required)

[](#requiredvaldiator-required)

Checks if a value is provided

This validator has the following option:

- **error.required**: error code when no value is provided (string|optional)

This validator generates the following error:

- **error.validation.required**: required error message

#### SizeValidator (size)

[](#sizevalidator-size)

Checks if the length of the provided string or the size of the provided array.

This validator has the following options:

- **minimum**: minimum value (numeric|optional)
- **maximum**: maximum value (numeric|optional)

*Note: Minimum and maximum are both optional both at least one of them is required. The values for minimum and maximum are included in the range.*

This validator generates the following errors:

- **error.validation.maximum.array**: when the number of array elements is greater then the provided maximum
- **error.validation.maximum.string**: when the size of a string is greater then the provided maximum
- **error.validation.minimum.array**: when the number of array elements is less then the provided minimum
- **error.validation.minimum.string**: when the size of a string is less then the provided minimum
- **error.validation.minmax.array**: when the number of array elements is less then the provided minimum or greater then the provided maximum
- **error.validation.minmax.string**: when the size of a string is less then the provided minimum or greater then the provided maximum
- **error.validation.object**: when the value is an object

#### UrlValidator (url)

[](#urlvalidator-url)

Checks if the provided string is a valid URL.

This validator has the following option:

- **required**: flag to see if a value is required (boolean|optional)

This validator generates the following errors:

- **error.validation.required**: required error message
- **error.validation.url**: default error message

#### WebsiteValdiator (website)

[](#websitevaldiator-website)

Checks if the provided string is a valid website. This is the same as the URL validator but limited to http(s)://.

This validator has the following option:

- **required**: flag to see if a value is required (boolean|optional)

This validator generates the following errors:

- **error.validation.required**: required error message
- **error.validation.website**: default error message

### Constraints

[](#constraints)

The *Constraint* interface is used to validate a data container. A data container can be an array or an object.

Different implementations are available.

#### GenericConstraint (generic)

[](#genericconstraint-generic)

The *GenericConstraint* is a combination of filters and validators which can be applied on specific properties of the data container.

```
