Source for file OrValidatorRule.class.php

Documentation is available at OrValidatorRule.class.php

  1. <?php
  2.  
  3. require_once(HARMONI."utilities/FieldSetValidator/rules/ValidatorRule.interface.php");
  4.  
  5. /**
  6. * the OrValidatorRule takes 2 other rules and validates if at least one of the 2 validates.
  7. *
  8. * @package harmoni.utilities.fieldsetvalidator.rules
  9. *
  10. * @copyright Copyright &copy; 2005, Middlebury College
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  12. *
  13. * @version $Id: OrValidatorRule.class.php,v 1.6 2007/09/04 20:25:55 adamfranco Exp $
  14. */
  15. class OrValidatorRule extends ValidatorRuleInterface {
  16.  
  17.  
  18. /**
  19. * the constructur
  20. *
  21. * @param object ValidatorRule $rule1 the first rule
  22. * @param object ValidatorRule $rule2 the second rule
  23. * @access public
  24. * @return void
  25. ***/
  26. function OrValidatorRule( $rule1, $rule2 ) {
  27. $this->_rule1 =$rule1;
  28. $this->_rule2 =$rule2;
  29. }
  30.  
  31.  
  32.  
  33. /**
  34. * the OrValidatorRule takes 2 other rules and validates if at least one of the 2 validates.
  35. * @param mixed $rule1 The first rule.
  36. * @access public
  37. * @return boolean TRUE, if the value is an integer; FALSE if it is not.
  38. ***/
  39. function check( $val ) {
  40. return ($this->_rule1->check($val) || $this->_rule2->check($val));
  41. }
  42. /**
  43. * This is a static method to return an already-created instance of a validator
  44. * rule. There are at most about a hundred unique rule objects in use durring
  45. * any given execution cycle, but rule objects are instantiated hundreds of
  46. * thousands of times.
  47. *
  48. * This method follows a modified Singleton pattern.
  49. *
  50. * @param object ValidatorRule $rule1 the first rule
  51. * @param object ValidatorRule $rule2 the second rule
  52. * @return object ValidatorRule
  53. * @access public
  54. * @static
  55. * @since 3/28/05
  56. */
  57. function getRule ($rule1, $rule2) {
  58. // Because there is no way in PHP to get the class name of the descendent
  59. // class on which this method is called, this method must be implemented
  60. // in each descendent class.
  61.  
  62. if (!isset($GLOBALS['validator_rules']) || !is_array($GLOBALS['validator_rules']))
  63. $GLOBALS['validator_rules'] = array();
  64. $class = __CLASS__;
  65. $ruleKey = $class."(".$rule1->getRuleKey().", ".$rule2->getRuleKey().")";
  66. if (!isset($GLOBALS['validator_rules'][$ruleKey]))
  67. $GLOBALS['validator_rules'][$ruleKey] = new $class($rule1, $rule2);
  68. return $GLOBALS['validator_rules'][$ruleKey];
  69. }
  70. /**
  71. * Return a key that can be used to identify this Rule for caching purposes.
  72. * If this rule takes no arguments, the class name should be sufficient.
  73. * otherwise, append the arguments.
  74. *
  75. * This method should only be called by ValidatorRules.
  76. *
  77. * @return string
  78. * @access protected
  79. * @since 3/29/05
  80. */
  81. function getRuleKey () {
  82. return get_class($this)."(".$this->_rule1->getRuleKey().", ".$this->_rule2->getRuleKey().")";
  83. }
  84. }
  85.  
  86. ?>

Documentation generated on Wed, 19 Sep 2007 10:25:24 -0400 by phpDocumentor 1.3.0RC3