static function standard_instance($input = null) { if ($input === null) { $input = self::input(); } $conform = new self($input); $conform->add_conformer('f', \Grithin\Conform\Filter::init()); $conform->add_conformer('v', new \Grithin\Conform\Validate()); return $conform; }
function __construct() { $this->input = $input = ['bob' => 'bob', 'email' => '*****@*****.**', 'price' => '$14,240.02', 'float' => 12.1, 'int' => 2, 'int_string' => ' 2']; $this->conform = new \Grithin\Conform($input); $this->conform->add_conformer('f', \Grithin\Conform\Filter::init()); $this->conform->add_conformer('v', new \Grithin\Conform\Validate()); $e = function () { throw new \Exception(); }; $this->conform->add_conformer('e', $e); }
function age_min($v, $min) { self::min(Filter::init()->age($v), $min); return $v; }
'type' : 'v.int' 'params' : [] ] ] */ Debug::out($conform->output); /* [ 'clicks' : 2 ] */ # input assumed from normal stdin and POST and GET $rules = ['hits' => 'v.int', 'clicks' => 'v.int v.min|1']; $_POST = ['hits' => 'v.int', 'clicks' => 'v.int v.min|1']; $conform = new \Grithin\Conform($input); $conform->add_conformer('f', \Grithin\Conform\Filter::init()); $conform->add_conformer('v', new \Grithin\Conform\Validate()); $e = function () { throw new \Exception(); }; $conform->add_conformer('e', $e); Debug::out($conform->fields_rules($rules)); /* [ 'clicks' : 2 ] */ Debug::out($conform->standardise_errors()); /* 0 : [ 'fields' : [