Example #1
0
 function testMapFormSchema()
 {
     $registry = \Fulfil\Registry::standard();
     $check = new \Fulfil\Ext\FormSchema(['schemas' => new \Fulfil\Schema(['props' => ['foo' => new \Fulfil\Schema(['props' => ['bar' => true]])]], ['mapper' => new \Fulfil\Mapper\Vars()])], ['registry' => $registry]);
     $in = (object) ['foo' => (object) ['bar' => 'yep']];
     $out = $check->map($in);
     $this->assertEquals(['foo' => ['bar' => 'yep']], $out);
 }
Example #2
0
<?php

require __DIR__ . '/config.php';
// pretend this is the thing that came out of the DB
// i.e. $amiss->getById(Advertiser::class, $request->get['id']);
$obj = (object) ['foo' => (object) ['bar' => 2, 'bag' => (object) ['ass' => 'x'], 'nope' => 'nope']];
$registry = \Fulfil\Registry::standard();
$schema = new \Fulfil\Ext\FormSchema(['schemas' => $registry->import('check', ['check' => 'schema', 'props' => ['foo' => [new \Fulfil\Schema(['props' => ['bar' => new \Fulfil\Check\String_(), 'bag' => new \Fulfil\Check\Any(['message' => ['id' => 'foo'], 'checks' => [new \Fulfil\Check\Int_(), new \Fulfil\Check\String_(), new \Fulfil\Check\List_(['defaultItem' => new \Fulfil\Check\String_()])]])]])]]])], ['registry' => $registry]);
$mapped = $schema->map($obj);
$schema->apply($mapped, $ctx = new \Fulfil\Context());
dump($mapped);
// dump($ctx->flatten());