Beispiel #1
0
 function testSchemaCanModifyWhenChildChecksCanModify()
 {
     $schema = new \Fulfil\Schema(['props' => ['foo' => new \Fulfil\Filter\String_(['trim' => true])]]);
     $this->assertTrue($schema->canModify());
 }
Beispiel #2
0
<?php

require __DIR__ . '/config.php';
use Fulfil\Check;
use Fulfil\Filter;
use Fulfil\Rule;
use Fulfil\Schema;
$schema = new Schema(['props' => ['foo' => true, 'minDate' => [new Filter\DateFormat(['initial' => '2014-01-01', 'formats' => ['Y-m-d']]), new Check\Date(['required' => false, 'message' => ['text' => 'PANTS']])], 'maxDate' => new Check\Date(['required' => false]), 'gg' => [new Filter\String_(['trim' => true]), new Check\String_(['name' => 'Governor General', 'initial' => ' boom ', 'lengthMax' => 15, 'values' => ['boom', 'bang', 'biff']])], 'boom' => new Check\Any(['name' => 'boom', 'message' => ['text' => "IT DIDN'T WORK"], 'checks' => [new Schema(['props' => ['quack' => new Check\Basic(['required' => true])]]), new Check\String_(), new Check\Bool_(), new Check\Int_(['min' => 10, 'max' => 30])]]), 'pow' => new Check\Bool_(), 'biff' => new Check\Bool_(['name' => 'BIFF']), 'whack' => new Check\Bool_(['name' => 'WHACK']), 'hello' => new Check\Email(['initial' => 'a@b', 'required' => true])], 'rules' => [new Rule\DateRange(['dateMin' => 'minDate', 'dateMax' => 'maxDate'])]]);
$registry = new \Fulfil\Registry();
// var_dump($schema->groups());
// initial values
$ctx = new \Fulfil\Context();
$initial = $schema->initial();
var_dump($schema->apply($initial, $ctx));
$flat = $ctx->flatten();
foreach ($flat->messages as $error) {
    echo implode(".", $error->path) . ": " . $error->text . "\n";
}
// actual validation process
$in = ['foo' => 'yep', 'minDate' => new \DateTime('yesterday'), 'maxDate' => new \DateTime('now'), 'gg' => 'boom', 'boom' => ['quack' => 'yep'], 'pow' => false, 'biff' => false, 'whack' => true, 'hello' => 'a@b'];
$ctx = new \Fulfil\Context();
var_dump($schema->apply($in, $ctx));
$flat = $ctx->flatten();
foreach ($flat->messages as $error) {
    echo implode(".", $error->path) . ": " . $error->msg . "\n";
}
echo "\n";
echo "Schema can modify  : " . ($schema->canModify() ? 'yes' : 'no') . "\n";
echo "Input modified     : " . ($flat->change ? 'yes' : 'no') . "\n";
echo "Validation complete: " . ($flat->complete ? 'yes' : 'no') . "\n";