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

Source for file Callback.php

Documentation is available at Callback.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Bertrand Mansion <bmansion@mamasam.com>                     |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Callback.php,v 1.7 2003/11/11 12:41:13 avb Exp $
  20.  
  21. require_once('HTML/QuickForm/Rule.php');
  22.  
  23. /**
  24. * Validates values using callback functions or methods
  25. @version     1.0
  26. */
  27. {
  28.     /**
  29.      * Array of callbacks
  30.      *
  31.      * Array is in the format:
  32.      * $_data['rulename'] = array('functionname', 'classname');
  33.      * If the callback is not a method, then the class name is not set.
  34.      *
  35.      * @var     array 
  36.      * @access  private
  37.      */
  38.     var $_data = array();
  39.  
  40.    /**
  41.     * Whether to use BC mode for specific rules
  42.     * 
  43.     * Previous versions of QF passed element's name as a first parameter
  44.     * to validation functions, but not to validation methods. This behaviour
  45.     * is emulated if you are using 'function' as rule type when registering.
  46.     * 
  47.     * @var array 
  48.     * @access private
  49.     */
  50.     var $_BCMode = array();
  51.  
  52.     /**
  53.      * Validates a value using a callback
  54.      *
  55.      * @param     string    $value      Value to be checked
  56.      * @param     mixed     $options    Options for callback
  57.      * @access    public
  58.      * @return    boolean   true if value is valid
  59.      */
  60.     function validate($value$options = null)
  61.     {
  62.         if (isset($this->_data[$this->name])) {
  63.             $callback $this->_data[$this->name];
  64.             if (isset($callback[1])) {
  65.                 return call_user_func(array($callback[1]$callback[0])$value$options);
  66.             elseif ($this->_BCMode[$this->name]{
  67.                 return $callback[0](''$value$options);
  68.             else {
  69.                 return $callback[0]($value$options);
  70.             }
  71.         elseif (is_callable($options)) {
  72.             return call_user_func($options$value);
  73.         else {
  74.             return true;
  75.         }
  76.     // end func validate
  77.  
  78.     /**
  79.      * Adds new callbacks to the callbacks list
  80.      *
  81.      * @param     string    $name       Name of rule
  82.      * @param     string    $callback   Name of function or method
  83.      * @param     string    $class      Name of class containing the method
  84.      * @param     bool      $BCMode     Backwards compatibility mode
  85.      * @access    public
  86.      */
  87.     function addData($name$callback$class = null$BCMode = false)
  88.     {
  89.         if (!empty($class)) {
  90.             $this->_data[$name= array($callback$class);
  91.         else {
  92.             $this->_data[$name= array($callback);
  93.         }
  94.         $this->_BCMode[$name$BCMode;
  95.     // end func addData
  96.  
  97.  
  98.     function getValidationScript($options = null)
  99.     {
  100.         if (isset($this->_data[$this->name])) {
  101.             $callback $this->_data[$this->name][0];
  102.             $params   ($this->_BCMode[$this->name]"'', {jsVar}"'{jsVar}'.
  103.                         (isset($options)? ", '{$options}'": '');
  104.         else {
  105.             $callback is_array($options)$options[1]$options;
  106.             $params   '{jsVar}';
  107.         }
  108.         return array(''"{jsVar} != '' && !{$callback}({$params})");
  109.     // end func getValidationScript
  110.  
  111. // end class HTML_QuickForm_Rule_Callback
  112. ?>

Documentation generated on Mon, 11 Mar 2019 14:16:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.