Download the PHP package guyliangilsing/php-validation without Composer

On this page you can find all versions of the php package guyliangilsing/php-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-validation

PHPValidation

A simple validation library that allows you to write custom validators for your data.

Table of Contents

Features

PHPValidation comes with the following features:

Installation

IMPORTANT: PHPValidation requires php version 8 or higher to work properly.

Usage

Obtaining a validator

A validator can be obtained through the ValidatorBuilder class:

The validator builder has the following options:

Note: The builder already comes preconfigured with a strategy and validator class name, the example above just lists all possible configuration options.

Through a factory

A validator can also be obtained through the default factory:

Note: Adding more methods to this default factory class is possible by inheriting it.

Configuring array field validation

Within the validation builder, an array must be set that defines how a given array should be validated. This uses the following structure:

The structure itself is quite simple. It is just an array that defines the names of the fields through keys, and the field validation through classes that implement the FieldValidatorInterface interface. Nested fields are also supported, you just have a key point to an array with the basic key => array\<FieldValidatorInterface> structure, this can be done infinitely.

Configuring custom error messages

Each built-in field validator comes with their own default error messages. These messages can be overriden by providing the builder with an array that has the following structure:

This structure needs a field name key that points to an array that has the field validator key and an error message as a key => value pair. Nested fields are also supported and can be used by wrapping the structure for a singular field, inside an array that gets pointed to by a key.

Using the validator

Once you have configured the validator builder, the validator can be built by using the build() method:

The validator can then be used to validate an array:

Creating custom field validators

Creating a custom field validator is quite easy. The only thing you have to do is implement the FieldValidatorInterface interface:

It is recommended to create a simple function that wraps your custom validator. PHPValidation comes with some basic built-in validators that are being wrapped in the following way:

Wrapping your custom validator with a function will prevent the following code from being written:

And makes the final code easier to read:

Available field validators

PHPValidation comes with some built-in field validators that should cover basic use cases.

required

When added, this field key must be present in an array.

notEmpty

When added, and the field exists, and the field is of the type string or array, it cannot be empty or contain only whitespace.

isArray

When added, and the field exists, it must be of the type array.

hasKeys

When added, and the field exists, and the field is of the type array, it must have all of the stated keys.

hasValues

When added, and the field exists, and the field is of the type array, it must have all of the stated values.

confirmValues

When added, and the field exists, the field value must be equal to the value of another field. When specifying which array field value the current field must match, dot notation is used to denote the key tree: key1.nestedKey1 translates to the following php array:

in

When added, and the field exists, and the field is of the type string, int, float, bool, or array, it can only contain one of the stated values.

Note: When this validator has an array value passed to it, it will only validate the first level of the array.

notIn

When added, and the field exists, and the field is of the type string, int, float, or bool, it cannot contain one of the stated values.

minLength

When added, and the field exists, and the field is of the type string, it must have a minimum amount of characters.

maxLength

When added, and the field exists, and the field is of the type string, it cannot have more than a certain amount of characters.

minCount

When added, and the field exists, and the field is of the type array, it must have a minimum amount of values.

maxCount

When added, and the field exists, and the field is of the type array, it cannot have more than a certain amount of values.

email

When added, and the field exists, and the field is of the type string, it will check for an RFC 5322 compliant email address.

phoneNumber

When added, and the field exists, and the field is of the type string, it will check for a valid international phone number.

Note: This validator does not accept phone numbers delimitted by any characters and/or whitespace.
Note: It probably will be better to create your own phone number validator since a phone number can differ greatly depending on the country/location.

isAlphabetic

When added, and the field exists, and the field is of the type string, it will check if its value only contains normal, non-special, characters and whitespace.

isNumeric

When added, and the field exists, and the field is of the following types: string, float, or int, it will check if the given value is numeric.

isAlphaNumeric

When added, and the field exists, and the field is of the type string, it will check if the given value only contains normal, non-special, characters, numbers, and whitespace. The validator also supports whitelisting extra characters.

isInt

When added, and the field exists, and the field is of the following types: string or int, it will check if the given value can be converted to an integer, and thus is an integer.

isFloat

When added, and the field exists, and the field is of the following types: string, float, or int, it will check if the given value can be converted to a float without losing any data, and thus is an float.

isString

When added, and the field exists, it will check if the given value is of the type string.

isObject

When added, and the field exists, it will check if the given value is of the type object.

objectOfType

When added, and the field exists, and the field is of the type object, it will check if the given value has a desired object type.

equals

When added, and the field exists, it will check if the given value matches the field value. This validator supports strict and non-strict value validation.

contains

When added, and the field exists, and the field is of the type string, it will check if the given value contains a specific substring.

greaterThan

When added, and the field exists, and the field is of the following types: string, float, or int, it will check if the given value is greater than the field value.

greaterEqual

When added, and the field exists, and the field is of the following types: string, float, or int, it will check if the given value is greater than, or equal to, the field value.

lowerThan

When added, and the field exists, and the field is of the following types: string, float, or int, it will check if the given value is lower than the field value.

lowerEqual

When added, and the field exists, and the field is of the following types: string, float, or int, it will check if the given value is lower than, or equal to, the field value.

between

When added, and the field exists, and the field is of the following types: string, float, or int, it will check if the given value is between two given values.

isDate

When added, and the field exists, and the field is of the following type string or implements the DateTimeInterface interface, it will check if the field is a date string or an object that implements the DateTimeInterface interface.

Note: This field uses php's strtotime() function to check if a string is indeed a date string.

dateHasFormat

When added, and the field exists, and the field is of the following type string or implements the DateTimeInterface interface, it will check if the field uses a given php datetime format.

Note: It is recommended to only use this validator with date strings. Objects that implement the DateTimeInterface interface will always be valid since they are internally cast back to a string with the given format.

dateEquals

When added, and the field exists, and the field is of the following type string or implements the DateTimeInterface interface, it will check if the field value is equal to a pre-determined date object.

dateLowerThan

When added, and the field exists, and the field is of the following type string or implements the DateTimeInterface interface, it will check if the given value is lower than the field value.

dateLowerEqual

When added, and the field exists, and the field is of the following type string or implements the DateTimeInterface interface, it will check if the given value is lower than, or equal to, the field value.

dateGreaterThan

When added, and the field exists, and the field is of the following type string or implements the DateTimeInterface interface, it will check if the given value is greater than the field value.

dateGreaterEqual

When added, and the field exists, and the field is of the following type string or implements the DateTimeInterface interface, it will check if the given value is greater than, or equal to, the field value.

dateBetween

When added, and the field exists, and the field is of the following type string or implements the DateTimeInterface interface, it will check if the given value is between two given dates.


All versions of php-validation with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package guyliangilsing/php-validation contains the following files

Loading the files please wait ....