HTML_QuickForm2
[ class tree: HTML_QuickForm2 ] [ index: HTML_QuickForm2 ] [ all elements ]

Class: HTML_QuickForm2_Rule_Compare

Source Location: /HTML_QuickForm2-0.2.0/QuickForm2/Rule/Compare.php

Class Overview

HTML_QuickForm2_Rule
   |
   --HTML_QuickForm2_Rule_Compare

Rule comparing the value of the field with some other value


Author(s):

Version:

  • Release: 0.2.0

Variables

Methods


Inherited Variables

Inherited Methods

Class: HTML_QuickForm2_Rule

HTML_QuickForm2_Rule::__construct()
Class constructor
HTML_QuickForm2_Rule::and_()
Adds a rule to the chain with an "and" operator
HTML_QuickForm2_Rule::checkValue()
Validates the element's value
HTML_QuickForm2_Rule::getMessage()
Returns the error message output by the rule
HTML_QuickForm2_Rule::getOptions()
Returns the rule's configuration data
HTML_QuickForm2_Rule::or_()
Adds a rule to the chain with an "or" operator
HTML_QuickForm2_Rule::setMessage()
Sets the error message output by the rule
HTML_QuickForm2_Rule::setOptions()
Sets additional configuration data for the rule
HTML_QuickForm2_Rule::setOwner()
Sets the element that will be validated by this rule
HTML_QuickForm2_Rule::validate()
Performs validation

Class Details

[line 90]
Rule comparing the value of the field with some other value

The Rule needs two configuration parameters for its work

  • comparison operator (defaults to equality)
  • operand to compare with; this can be either a constant or another form element (its value will be used)
Parameters can be passed to setOptions() in either of the following formats
  • operand
  • array([operator, ]operand)
  • array(['operator' => operator, ]['operand' => operand])
and also may be passed to HTML_QuickForm2_Factory::registerRule() in either of the following formats
  • operator
  • array(operator[, operand])
  • array(['operator' => operator, ]['operand' => operand])
global config registered with the Factory overrides options set for the particular Rule instance.

Note that 'less than [or equal]' and 'greater than [or equal]' operators compare the operands numerically, since this is considered as more useful approach by the authors.

For convenience, this Rule is already registered in the Factory with the names 'eq', 'neq', 'lt', 'gt', 'lte', 'gte' corresponding to the relevant operators:

  1.  $password->addRule('eq''Passwords do not match'$passwordRepeat);
  2.  $orderQty->addRule('lte''Should not order more than 10 of these'10);



[ Top ]


Class Variables

$operators = array('==', '!=', '===', '!==', '<', '<=', '>', '>=')

[line 96]

Possible comparison operators
  • Access: protected

Type:   array


[ Top ]



Method Detail

checkValue   [line 108]

bool checkValue( $value)

Validates the element's value
  • Return: whether (element_value operator operand) expression is true
  • Throws: HTML_QuickForm2_Exception if an operand to compare with is missing
  • Throws: HTML_QuickForm2_InvalidArgumentException if a bogus $registeredType was passed to constructor or a bogus comparison operator is used for configuration
  • Access: protected

Overrides HTML_QuickForm2_Rule::checkValue() (Validates the element's value)

Parameters:

   $value   — 

[ Top ]

findOperand   [line 178]

mixed findOperand( mixed $globalConfig)

Finds an operand to compare element's value with in global config and Rule's options
  • Return: an operand to compare with
  • Throws: HTML_QuickForm2_Exception if an operand is missing
  • Access: protected

Parameters:

mixed   $globalConfig   —  config returned by HTML_QuickForm2_Factory::getRuleConfig(), if applicable

[ Top ]

findOperator   [line 136]

string findOperator( mixed $globalConfig)

Finds a comparison operator to use in global config and Rule's options
  • Return: operator to use, defaults to '==='
  • Throws: HTML_QuickForm2_InvalidArgumentException if a bogus comparison operator is used for configuration
  • Access: protected

Parameters:

mixed   $globalConfig   —  config returned by HTML_QuickForm2_Factory::getRuleConfig(), if applicable

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:10:21 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.