Source for file HasMethodsValidatorRule.class.php

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

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