Checks if dependencies between given items are matched

package Formagic\Rule
author Florian Sonnenburg
since 1.0.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

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.

Checks if given item's value matches the specified requirements.

validate(string $value) : boolean

Subclasses have to implement their behavior here.

inherited_from \Formagic_Rule_Abstract::validate()

Parameters

$value

string

Value to be checked

Returns

booleanTrue if conditions are matched

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

Defines dependent items and validate condition.

_init(array $arguments) 

Supported keys:

item:
Dependent item
condition:
Dependency condition. One of the constants Formagic_Rule_ItemDependency::COND_VALUE_EQUALS, Formagic_Rule_ItemDependency::COND_VALUE_NOT_EQUALS
requirement:
Required value the dependent item is checked against with the specified condition

Scenario: Given item $item shall be valid if dependent item $dep has a value of 1. $arguments = array(

 ['item'] => $dep,
 ['condition'] => Formagic_Rule_ItemDependency::COND_VALUE_EQUALS,
 ['requirement'] => 1,

);

inherited_from \Formagic_Rule_Abstract::_init()

Parameters

$arguments

array

Rule options.

Exceptions

\Formagic_Exception If key "item", "condition" or "requirement" is not provided or has invalid value

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

 

Check condition

$_condition : integer

Default

 

Items the validity of this item is dependent on

$_item : \Formagic_Item_Abstract

Default

array()
 

Default message

$_message : string

Default

'Please enter a value'
inherited_from \Formagic_Rule_Abstract::_message
 

Message string

$_message : string

Default

'Please enter a valid value'
 

Required item value

$_requirement : mixed

Default

 

Rule type identifier.

$_name : string

Default

 Constants

 

Condition: Positive value match on requirement ("value is .

COND_VALUE_EQUALS = 1 

..")

 

Condition: Negative value match on requirement ("value is not .

COND_VALUE_NOT_EQUALS = 2 

..")

 

Reuqirement: Dependent item has to have any value

VALUE_ANY = true 
 

Requirement: Dependent item has to have no value

VALUE_NONE = '' 
 

Requirement: Either parent item value or dependent item value NOT YET IMPLEMENTED

VALUE_XOR = '__FM__VALUE_XOR__' 
todo Implement Formagic_Rule_ItemDependency::VALUE_XOR