Abstract implementation of range comparsion rules

package Formagic\Rule
author Florian Sonnenburg
since 1.1.0 First time introduced
inherited_from \Formagic_Rule_Abstract

 Methods

Constructor

__construct(array $arguments = array()
Inherited

The default error message that is displayed if the rule is violated can be overwritten by $errorMessage.

see

Parameters

$arguments

array

The rule options.

Returns translated error message of rule

getMessage() : string
Inherited

Returns

stringMessage string

Returns rule type identification string.

getName() : string
Inherited

Returns

stringThe rule name

Not supported by range comparison rules.

setMessage(string $message) 

Usually a rule will have one error message string that is used if the validation fails. If neccessary, Formagic_Rule_Abstract::_errorMessage can hold other variables, eg. an array of error messages for different outcomes of the validation process.

Implements a fluent interface pattern.

inherited_from \Formagic_Rule_Abstract::setMessage()

Parameters

$message

string

New message string

Exceptions

\Formagic_Exception

Sets the error message property.

setMessage(mixed $message) : \Formagic_Rule_Abstract
Inherited

Usually a rule will have one error message string that is used if the validation fails. If neccessary, Formagic_Rule_Abstract::_errorMessage can hold other variables, eg. an array of error messages for different outcomes of the validation process.

Implements a fluent interface pattern.

see

Parameters

$message

mixed

The error message value.

Returns

\Formagic_Rule_Abstract$this object.

Sets messages array

setMessages(array $messages) : \Formagic_Rule_RangeComparison_Abstract

Parameters

$messages

array

Array of messages

Returns

\Formagic_Rule_RangeComparison_Abstract

Performs rule check

validate(string $value) : boolean

Length rule checks if value is between min and max length. The validation method depends on $this->_type.

inherited_from \Formagic_Rule_Abstract::validate()

Parameters

$value

string

The item to checked

Returns

booleanThe validation result

Abstract of main validate method. Returns boolean value of check success.

validate(string $value) : boolean
Inherited

Subclasses have to implement their behavior here.

Parameters

$value

string

The value to be validated.

Returns

booleanThe rule check result

Evaluate between range (including limits).

_execBetween(integer $range) : boolean

Parameters

$range

integer

Range value

Returns

booleanEvaluation result

Evaluate maximum range (lessers or equals).

_execMax(integer $range) : boolean

Parameters

$range

integer

Upper limit

Returns

booleanEvaluation result

Evaluate minimum range (greater or equals).

_execMin(integer $range) : boolean

Parameters

$range

integer

Lower limit

Returns

booleanEvaluation result

Returns a translates message string.

_getMessage(string $key) : string

Parameters

$key

string

Message type

Returns

stringTranslated filled message

Returns range check value.

_getRange(string $value) : mixed

Parameters

$value

string

Item value

Returns

mixedCheck range value

Allows subclass initialization.

_init(array $arguments) : void

Allowed options for this rule are:

(integer)min:
Minimal length to be checked (optional, defaults to 0)
(integer)max:
Maximal length to be checked (optional, defaults to 0)

Will throw an exception, if neither "min" nor "max" option provided.

inherited_from \Formagic_Rule_Abstract::_init()

Parameters

$arguments

array

Array of arguments passed to __construct()

Allows subclass initialization.

_init(array $arguments) : void
Inherited

Parameters

$arguments

array

Array of arguments passed to __construct()

Checks if value is not entered by a user or if the field has not been assigned to the form.

_isNoUserValue($value) : boolean
Inherited

The value 0 (zero) for example could be something the user entered willingly and would be skipped from rule checks when using empty().

Parameters

$value

mixed Value to be checked

Returns

boolean

 Properties

 

The maximal length

$_max : integer

Default

 

Message string

$_message : string

Default

'Please enter a valid value'
 

Array of messages

$_messages : array

Default

array('min' => '', 'max' => '', 'between' => '')
 

The minimal length

$_min : integer

Default

 

Rule type identifier.

$_name : string

Default