Validate

Contains static methods to validate model data. Checks model property data against property definition and reports the diversities.
Source
Validate.php
Depends on
IModel , T , Model

Constants

FORMAT_EMAIL = 27

Model property diversity type: Expected the property value to be an email but it was not

FORMAT_IP = 25

Model property diversity type: Expected the property value to be an IP but it was not

FORMAT_URL = 26

Model property diversity type: Expected the property value to be a URL but it was not

INVALID_ARRAY = 19

Model property diversity type: Expected the property to have array value but it did not

INVALID_BOOL = 17

Model property diversity type: Expected the property to have boolean value but it did not

INVALID_DATE = 20

Model property diversity type: Expected the property to have date value but it did not

INVALID_DATETIME = 22

Model property diversity type: Expected the property to have date-time value but it did not

INVALID_FLOAT = 18

Model property diversity type: Expected the property to have float value but it did not

INVALID_INT = 16

Model property diversity type: Expected the property to have integer value but it did not

INVALID_STRING = 15

Model property diversity type: Expected the property to have string value but it did not

INVALID_TIME = 21

Model property diversity type: Expected the property to have time value but it did not

NUMBER_LARGE = 13

Model property diversity type: The property value (number) is above than defined margin.

NUMBER_SMALL = 12

Model property diversity type: The property value (number) is smaller than defined margin.

REQUIRED = 11

Model property diversity type: Expected the property to have data but it did not (was set to null, Model::N or Model::NN).

STRING_LONG = 24

Model property diversity type: Property value (string) length is longer than than expected.

STRING_SHORT = 23

Model property diversity type: Property value (string) length is shorter than expected.

Static Methods

date

bool Validate::date(string val, string format='YMD')

Validate date. If date has time part it will be ignored, Year, month and day separator can be either '/' or '-'.

Arguments

    val (string)
    Value to be checked
    format='YMD' (string)
    Year, month and day orientation

Returns

bool
true=is valid

datetime

bool Validate::datetime(string val, string format='YMD')

Validate a date-time.

Arguments

    val (string)
    Value to be checked.
    format='YMD' (string)
    Year, month and day orientation of the date

Returns

bool
true=is valid

email

bool Validate::email(string email, bool strict=false)

Validate an e-mail.

Arguments

    email (string)
    Value to be checked
    strict=false (bool)
    true=check if the email exists in the wild

Returns

bool
true=is valid

evaluate

array Validate::evaluate(IModel model, array | [string] propertyNames=null)

Validate model properties data.

Arguments

    model (IModel)
    Model object to be checked
    propertyNames=null (array | [string])
    a list of properties to only be validated

Returns

array
An array of validation errors, if all property values are valid the array will be empty. {model-property-name: [Validate::MODEL-PROPERTY-DIVERSITY-TYPE-CONST,],}

evaluateProperty

array Validate::evaluateProperty(mixed val, array def)

Validate one model's property value.

Arguments

    val (mixed)
    Property value to be checked against property definition
    def (array)
    The property definition

Returns

array
An array of validation errors, if value is valid the array will be empty. [Validate::MODEL-PROPERTY-DIVERSITY-TYPE-CONST,]

ip

bool Validate::ip(string ip)

Validate an IP.

Arguments

    ip (string)
    Value to be checked

Returns

bool
true=is valid

number

bool Validate::number(number val, number min, number max=null)

Validate number range.

Arguments

    val (number)
    Value to be checked
    min (number)
    Min margin
    max=null (number)
    Max margin

Returns

bool
The number was in the range

time

bool Validate::time(string val)

Validate time. Valid times are 'HH', 'HH:MM', 'HH:MM:SS', 'DATE HH', 'DATE HH:MM' and 'DATE HH:MM:SS'.

Arguments

    val (string)
    Value to be checked

Returns

bool
true=is valid

url

bool Validate::url(string url)

Validate a URL.

Arguments

    url (string)
    Value to be checked

Returns

bool
true=is valid