PHP Classes
elePHPant
Icontem

QValidation: Validate several types of value

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (19)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2009-05-14 (6 years ago) RSS 2.0 feedNot enough user ratingsTotal: 300 All time: 6,775 This week: 1,280Up
Version License PHP version Categories  
qvalidation 0.1GNU General Publi...5.0PHP 5, Validation
Description Author  

This package can be used to validate several types of value.

It provides several classes that can validate different types of values.

Currently it can validate strings, integers, arrays, objects, resources, dates and ISBN numbers.

Picture of Tom Schaefer
Name: Tom Schaefer is available for providing paid consulting. Contact Tom Schaefer .
Classes: 39 packages by
Country: Germany Germany
Age: ???
All time rank: 1109 in Germany Germany
Week rank: 190 Down6 in Germany Germany Up
Innovation award
Innovation award
Nominee: 9x

Winner: 1x

Details provided by the author  
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 folder image Files  
File Role Description
Files folder imageValidation (2 files, 3 directories)
Files folder imagesamples (5 files)
Accessible without login Plain text file readme Doc. README

  Files folder image Files  /  Validation  
File Role Description
Files folder imageDataType (8 files)
Files folder imageVendor (1 file)
Files folder imageRule (2 files)
  Plain text file Validation.php Class Main class
  Plain text file ValidInterface.php Class Interface

  Files folder image Files  /  Validation  /  DataType  
File Role Description
  Plain text file Array.php Class coming soon
  Plain text file Common.php Class common validations
  Plain text file Date.php Class date validations
  Accessible without login Plain text file index.php Aux. autoloader
  Plain text file Integer.php Class integer validations
  Plain text file Object.php Class object validations
  Plain text file Resource.php Class resource validations
  Plain text file String.php Class string validations

  Files folder image Files  /  Validation  /  Vendor  
File Role Description
  Plain text file ISBN.php Class vendor isbn class

  Files folder image Files  /  Validation  /  Rule  
File Role Description
  Accessible without login Plain text file index.php Aux. autoloader
  Plain text file ISBN.php Class sample rule object

  Files folder image Files  /  samples  
File Role Description
  Accessible without login Plain text file config.inc.php Conf. configuration
  Accessible without login Plain text file isbn.php Example sample isbn validation
  Accessible without login Plain text file object.php Example sample object validation instance
  Accessible without login Plain text file object2.php Example sample object validation callable
  Accessible without login Plain text file rule.php Example sample rule

 Version Control Unique User Downloads Download Rankings  
 0%Total:300All time:6,775
 This week:0This week:1,280Up