Created
May 22, 2009 17:40
-
-
Save walterdavis/116259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Evaluates current object property by means of a comparison operator (< > == etc.) against a provided value. | |
* | |
* @param string $strKey Property name | |
* @param string $strComparisonOperator A comparison operator, < > == etc. | |
* @param string $strComparisonValue The value to compare with | |
* @param string $strErrorMessage (optional) a meaningful error message | |
* @return boolean | |
*/ | |
function validate_comparison($strKey,$strComparisonOperator,$strComparisonValue,$strErrorMessage=null){ | |
if(!$this->$strKey){ | |
$this->add_error($strKey,'This object does not have a property named ' . $strKey); | |
return false; | |
} | |
if(empty($strComparisonOperator) || empty($strComparisonValue)){ | |
$this->add_error($strKey,'Could not evaluate ' . $strKey . '! No comparison possible.'); | |
return false; | |
} | |
if(empty($strErrorMessage)) $strErrorMessage = $strKey . ' is not ' . $strComparisonOperator . ' ' . $strComparisonValue; | |
if($this->$strKey . $strComparisonOperator . $strComparisonValue){ | |
return true; | |
}else{ | |
$this->add_error($strKey,$strErrorMessage); | |
return false; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment