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

Class: HTML_QuickForm2_Rule_Callback

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

Class Overview

HTML_QuickForm2_Rule
   |
   --HTML_QuickForm2_Rule_Callback

Rule checking the value via a callback function (method)


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 101]
Rule checking the value via a callback function (method)

The Rule needs a valid callback as a configuration parameter for its work, it may also be given additional arguments to pass to the callback alongside the element's value.

Parameters can be passed to setOptions() in either of the following formats

  • callback or arguments (the semantics depend on whether the Rule was registered in the Factory with the callback already given)
  • array(['callback' => callback, ]['arguments' => array(...)])
and also may be passed to HTML_QuickForm2_Factory::registerRule() in either of the following formats
  • callback
  • array(['callback' => callback, ]['arguments' => array(...)])
global config registered with the Factory overrides options set for the particular Rule instance. In any case you are advised to use the associative array format to prevent ambiguity.

The callback will be called with element's value as the first argument, if additional arguments were provided they'll be passed as well. It is expected to return false if the value is invalid and true if it is valid.

Checking that the value is not empty:

  1.  $str->addRule('callback''The field should not be empty''strlen');
Checking that the value is in the given array:
  1.  $meta->addRule('callback''Unknown variable name',
  2.                 array('callback' => 'in_array',
  3.                       'arguments' => array(array('foo''bar''baz'))));
The same, but with rule registering first:
  1.      'in_array''HTML_QuickForm2_Rule_Callback',
  2.      'HTML/QuickForm2/Rule/Callback.php''in_array'
  3.  );
  4.  $meta->addRule('in_array''Unknown variable name'array(array('foo''bar''baz')));



[ Top ]


Class Variables

$registeredCallback =  false

[line 107]

Set to true if callback function was registered in Factory
  • Access: protected

Type:   bool


[ Top ]



Method Detail

checkValue   [line 117]

bool checkValue( $value)

Validates the element's value
  • Return: the value returned by a callback function
  • Throws: HTML_QuickForm2_Exception if the callback is missing
  • Throws: HTML_QuickForm2_InvalidArgumentException if a bogus $registeredType was passed to constructor or a bogus callback was provided
  • Access: protected

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

Parameters:

   $value   — 

[ Top ]

findArguments   [line 175]

array findArguments( mixed $globalConfig)

Searches in global config and Rule's options for callback's additional arguments
  • Return: additional arguments to pass to a callback
  • Access: protected

Parameters:

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

[ Top ]

findCallback   [line 143]

callback findCallback( mixed $globalConfig)

Searches in global config and Rule's options for a callback function to use
  • Throws: HTML_QuickForm2_Exception if a callback wasn't found anywhere
  • 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.