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

Class: HTML_QuickForm2_Rule_Length

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

Class Overview

HTML_QuickForm2_Rule
   |
   --HTML_QuickForm2_Rule_Length

Rule checking the value's length


Author(s):

Version:

  • Release: 0.2.0

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 91]
Rule checking the value's length

The rule needs an "allowed length" parameter for its work, it can be either

  • a scalar: the value will be valid if it is exactly this long
  • an array: the value will be valid if its length is between the given values (inclusive). If one of these evaluates to 0, then length will be compared only with the remaining one.
Parameters can be passed to setOptions() in either of the following formats
  • scalar (if no parameters were registered with Factory then it is treated as an exact length, if 'min' or 'max' was already registered then it is treated as 'max' or 'min', respectively)
  • array(minlength, maxlength)
  • array(['min' => minlength, ]['max' => maxlength])
and also may be passed to HTML_QuickForm2_Factory::registerRule() in either of the following formats
  • scalar (exact length)
  • array(minlength, maxlength)
  • array(['min' => minlength, ]['max' => maxlength])
global config registered with the Factory overrides options set for the particular Rule instance.

The Rule considers empty fields as valid and doesn't try to compare their lengths with provided limits.

For convenience this Rule is also registered with the names 'minlength' and 'maxlength' (having, respectively, 'max' and 'min' parameters set to 0):

  1.  $password->addRule('minlength''The password should be at least 6 characters long'6);
  2.  $message->addRule('maxlength''Your message is too verbose'1000);



[ Top ]


Method Detail

checkValue   [line 102]

bool checkValue( $value)

Validates the element's value
  • Return: whether length of the element's value is within allowed range
  • Throws: HTML_QuickForm2_Exception if rule configuration is missing
  • Throws: HTML_QuickForm2_InvalidArgumentException if a bogus $registeredType was passed to constructor or bogus allowed length(s) were used for rule configuration
  • Access: protected

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

Parameters:

   $value   — 

[ Top ]

findAllowedLength   [line 160]

int|array findAllowedLength( mixed $globalConfig)

Searches in global config and Rule's options for allowed length limits
  • Throws: HTML_QuickForm2_InvalidArgumentException if bogus length limits were provided
  • Throws: HTML_QuickForm2_Exception if length limits weren't found anywhere
  • Access: protected

Parameters:

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

[ Top ]

mergeMinMaxLength   [line 130]

array mergeMinMaxLength( array $length, array $config)

Adds the 'min' and 'max' fields from one array to the other
  • Access: protected

Parameters:

array   $length   —  Rule configuration, array with 'min' and 'max' keys
array   $config   —  Additional configuration, fields will be added to $length if it doesn't contain such a key already

[ Top ]


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