Recommend this page to a friend! |
Download .zip |
Info | View files (19) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2009-05-14 (7 years ago) | Not enough user ratings | Total: 303 | All time: 6,958 This week: 936 |
Version | License | PHP version | Categories | |||
qvalidation 0.1 | GNU General Publi... | 5.0 | PHP 5, Validation |
Description | Author | |
This package can be used to validate several types of value. |
Validation A set of validation classes which can be chained to rule set. - supported data types + Array (coming soon) + Bool (coming soon) + Common + Date + Float (coming soon) + Object + Resource + String - Vendor + ISBN - Rule The idea behind. A value has to pass a chain of validations. Once a value passed all validations it seems to be valid. These validation chains could be combinated to complex rule sets which each incoming data has to pass. A first sample: $valid = Validation_DataType_String::getInstance(); $valid->setValue("3827370191"); $valid->chain( "string", "Validation_DataType_String::validateISBN13" ); On a higher abstraction level you can design a rule class which takes an atomic validation set to compute multiple validation on a single value. class Validation_Rule_ISBN { private $value; private $validationObject; public function __construct($value) { $this->value = $value; } public function firstLevel() { if(!$this->validationObject instanceof Validation_DataType_String) { $this->validationObject = Validation_DataType_String::getInstance(); } $this->validationObject->setValue(array($this->value,10)); $this->validationObject->chain( "Validation_DataType_String::validateLengthEqual" ); return $this; } public function secondLevel(){ if(!$this->validationObject instanceof Validation_DataType_String) { $this->validationObject = Validation_DataType_String::getInstance(); } $this->validationObject->setValue($this->value); $this->validationObject->chain( "string", "Validation_DataType_String::validateISBN10" ); return $this; } } Thus makes your code more readable. No big twisted if/else source anymore. Just capsule you validation logic in such rule classes and maintaining of bigger projects validations will come easy. $rule = new Validation_Rule_ISBN("3827370191"); if($rule->firstLevel()->secondLevel()->isValid()){ echo "succeed"; } else { echo "failed"; } or even shorter: if($Validation_Rule_ISBN::getInstance("3827370191")->firstLevel()->secondLevel()->isValid()){ echo "succeed"; } else { echo "failed"; } These classes are still not complete. If you want some enhancements, then just added your check to one of the DataType classes and it will magically work within the set of rules. |
Files |
File | Role | Description | ||
---|---|---|---|---|
Validation (2 files, 3 directories) | ||||
samples (5 files) | ||||
readme | Doc. | README |
Files | / | Validation |
File | Role | Description | ||
---|---|---|---|---|
DataType (8 files) | ||||
Vendor (1 file) | ||||
Rule (2 files) | ||||
Validation.php | Class | Main class | ||
ValidInterface.php | Class | Interface |
Files | / | Validation | / | DataType |
File | Role | Description |
---|---|---|
Array.php | Class | coming soon |
Common.php | Class | common validations |
Date.php | Class | date validations |
index.php | Aux. | autoloader |
Integer.php | Class | integer validations |
Object.php | Class | object validations |
Resource.php | Class | resource validations |
String.php | Class | string validations |
Files | / | Validation | / | Rule |
Files | / | samples |
File | Role | Description |
---|---|---|
config.inc.php | Conf. | configuration |
isbn.php | Example | sample isbn validation |
object.php | Example | sample object validation instance |
object2.php | Example | sample object validation callable |
rule.php | Example | sample rule |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
0% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.