<?php require __DIR__ . '/config.php'; $ctx = new \Fulfil\Context(); $check = new \Fulfil\Schema(['props' => ['a' => new \Fulfil\Schema(['props' => ['a' => new \Fulfil\Check\All(['name' => 'Woohoo', 'checks' => [new \Fulfil\Check\String_(['lengthMin' => 3])]])]]), 'b' => new \Fulfil\Check\String_(['required' => true, 'lengthMin' => 3, 'lengthMax' => 5]), 'c' => new \Fulfil\Check\String_(['required' => true, 'lengthMin' => 3])]]); $in = ['a' => ['a' => 'ab'], 'b' => 'de', 'c' => 'ab']; $check->apply($in, $ctx); $ms = \Fulfil\MessageSet\SimpleTemplate::create('user', 'en', 'The value was invalid'); $ms->addTemplates(['reason' => ['check.required' => 'A value was required', 'string.lengthBetween' => 'Must be between {{min}} and {{max}} character(s), but only {{len}} were entered']]); dump($ms->formatContext($ctx)); dump($ms->formatContextPaths($ctx, ['a.a', 'b'])); $ms = new \Fulfil\MessageSet\Developer(); dump($ms->formatContext($ctx)); dump($ms->formatContextPaths($ctx, ['a.a', 'b']));
*/ use Fulfil\Check; use Fulfil\Rule; $words = preg_split('/\\r?\\n/', file_get_contents('/etc/dictionaries-common/words')); $words = array_slice($words, 10000, 1000); goto defs; script: $registry = new \Fulfil\Registry(); $schema = new \Fulfil\Schema(['props' => ['a' => new \Fulfil\Check\String_(['message' => ['text' => 'yep'], 'initial' => 'ddd', 'required' => true, 'pattern' => 'abc', 'lengthMin' => 2]), 'b' => [new \Fulfil\Check\Decimal(['required' => true, 'divisibleBy' => 1.1, 'allowString' => true])], 'c' => [new \Fulfil\Filter\String_(['trim' => true]), new \Fulfil\Check\String_(['required' => true]), new \Fulfil\Check\String_(['values' => ['aa', 'bb', 'cc', 'dd']]), new \Fulfil\Check\String_(['values' => ['bb', 'cc', 'dd'], 'message' => ['text' => 'foo']])], 'd' => new \Fulfil\Check\Int_(['required' => true, 'allowString' => true, 'max' => 30]), 'e' => new \Fulfil\Check\String_(['required' => true, 'lengthMin' => 5]), 'f' => [new \Fulfil\Check\Bool_(['required' => true, 'allowLoose' => true])], 'g' => new \Fulfil\Check\String_(['required' => true, 'values' => $words]), 'h' => new \Fulfil\Check\String_(['required' => true])]]); $out = ''; if (!isset($_POST['values'])) { $values = $schema->initial(); } else { $values = $_POST['values']; $ctx = new \Fulfil\Context(); $filtered = $schema->apply($values, $ctx); dump($ctx->flatten()); $out .= "<ul>"; foreach ($registry->messageSet->formatContext($ctx) as $msg) { $out .= "<li>{$msg}</li>"; } $out .= "</ul>"; } if (isset($filtered)) { $values = $filtered; } dump($values); $fw = new FormWriter(); $fw->schema = $schema; $fw->values = $values; $fw->path = ['values'];
return $class == 'Trou'; }], ['mapper' => new Fulfil\Mapper\Vars(), 'type' => 'regex', 'matcher' => '/urg/'], ['mapper' => $noteMapper, 'matcher' => 'Pants']], null); echo "\nDumping meta:\n"; dump($dispatchingMapper->getMeta(Pants::class)); echo "\nDumping instance properties:\n"; $p = new Pants(); $p->a = 1; $o = new Burger(); dump($dispatchingMapper->mapObjectToProperties($o)); echo "\nAssigning properties to isntance:\n"; $props = $dispatchingMapper->mapObjectToProperties($p); $props->a = 'aaa'; $props->yep = 'abcd'; $dispatchingMapper->populateObject($p, $props); dump($p); echo "\nLet's try a schema:\n"; $schema = new \Fulfil\Schema(['props' => ['a' => new \Fulfil\Check\String_(['emptyMode' => 'setNull']), 'b' => new \Fulfil\Check\String_(['emptyMode' => 'setNull']), 'yep' => [new \Fulfil\Filter\String_(['trim' => true]), new \Fulfil\Check\String_(['emptyMode' => 'setNull', 'required' => true])]]], ['mapper' => $dispatchingMapper]); $ctx = new \Fulfil\Context(); $p->setYep(' YEP '); echo "Before: "; dump($p); $p = $schema->apply($p, $ctx); echo "After: "; dump($p); dump($ctx->flatten()); echo "\nNow with an array:\n"; $ctx = new \Fulfil\Context(); $in = ['a' => '1', 'b' => '2', 'yep' => ' aaaa ']; $out = $schema->apply($in, $ctx); dump($ctx->flatten()); dump($out);