Source for file ExtendsValidatorRule.class.php

Documentation is available at ExtendsValidatorRule.class.php

  1. <?php
  2.  
  3. require_once(HARMONI."utilities/FieldSetValidator/rules/ValidatorRule.interface.php");
  4.  
  5. /**
  6. * The ExtendsValidatorRule checks if a given object is extends a given class.
  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: ExtendsValidatorRule.class.php,v 1.5 2007/09/04 20:25:55 adamfranco Exp $
  14. */
  15. class ExtendsValidatorRule
  16. extends ValidatorRuleInterface
  17. {
  18.  
  19. /**
  20. * The name of the parent class.
  21. * The name of the parent class. Will check whether the given object extends
  22. * this parent class.
  23. * @access private
  24. * @var mixed $_regex
  25. */
  26. var $_parentClassName;
  27.  
  28. /**
  29. * The constructor.
  30. * @access public
  31. * @param string $parentClassName The name of the parent class. Will check
  32. * whether the given object extends this parent class.
  33. * @return void
  34. ***/
  35. function ExtendsValidatorRule($parentClassName) {
  36. $this->_parentClassName = strtolower($parentClassName);
  37. }
  38.  
  39. /**
  40. * Checks that the given object extends a specified class.
  41. * Checks that the given object extends a specified class.
  42. * @param mixed $val The value to check.
  43. * @access public
  44. * @return boolean TRUE, if the object extends the class; FALSE if it is not.
  45. ***/
  46. function check( $val ) {
  47. return is_a($val, $this->_parentClassName);
  48. }
  49. /**
  50. * This is a static method to return an already-created instance of a validator
  51. * rule. There are at most about a hundred unique rule objects in use durring
  52. * any given execution cycle, but rule objects are instantiated hundreds of
  53. * thousands of times.
  54. *
  55. * This method follows a modified Singleton pattern.
  56. *
  57. * @param string $parentClassName The name of the parent class. Will check
  58. * whether the given object extends this parent class.
  59. * @return object ValidatorRule
  60. * @access public
  61. * @static
  62. * @since 3/28/05
  63. */
  64. function getRule ($parentClassName) {
  65. if (!isset($GLOBALS['validator_rules']) || !is_array($GLOBALS['validator_rules']))
  66. $GLOBALS['validator_rules'] = array();
  67. $class = __CLASS__;
  68. $ruleKey = $class."(".strtolower($parentClassName).")";
  69. if (!isset($GLOBALS['validator_rules'][$ruleKey]))
  70. $GLOBALS['validator_rules'][$ruleKey] = new $class($parentClassName);
  71. return $GLOBALS['validator_rules'][$ruleKey];
  72. }
  73. /**
  74. * Return a key that can be used to identify this Rule for caching purposes.
  75. * If this rule takes no arguments, the class name should be sufficient.
  76. * otherwise, append the arguments.
  77. *
  78. * This method should only be called by ValidatorRules.
  79. *
  80. * @return string
  81. * @access protected
  82. * @since 3/29/05
  83. */
  84. function getRuleKey () {
  85. return get_class($this)."(".$this->_parentClassName.")";
  86. }
  87. }
  88.  
  89. ?>

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