Esempio n. 1
0
$pathValidator = function ($inPath) {
    if (file_exists($inPath)) {
        return true;
    }
    return "The file which path is \"{$inPath}\" does not exist.";
};
// We say that:
//   - The name of the input is "Path".
//   - The input is mandatory.
//   - The input can not be null.
//   - The input has a validator.
$pathSpecification = new Specification("Path", true, false, $pathValidator);
// You can also use mutators to specify an input.
// The input named "token" is not mandatory and its value can be null.
// It does not have any specific validator.
$tokenSpecification = new Specification("Token");
$tokenSpecification->setMandatory(false)->setCanBeNull();
// Create a set of specifications.
$set = new SpecificationsSet();
$set->addInputSpecification($pathSpecification)->addInputSpecification($tokenSpecification);
// Print a summary.
foreach ($set->inputsSummary() as $_name => $_summary) {
    echo "{$_name} => {$_summary}\n";
}
// Note: you may specify a final validator.
// If the file exists, and if a token is specified, then make sure that the token is found in the file.
// If everything is OK, the validator must return an empty array.
// Otherwise, it must return a list of errors' identifiers (you are free to return any kind of values...).
// Note: here we return a list of error messages
$finalValidator = function ($inInputs) {
    $data = file_get_contents($inInputs['Path']);
Esempio n. 2
0
 function testGetValidator()
 {
     $this->assertSame($this->__inputV1->getValidator(), $this->__validator1);
     $this->assertSame($this->__inputV2->getValidator(), $this->__validator2);
 }