Ejemplo n.º 1
0
 function ensureValid(\Fulfil\MessageSet $messageSet = null)
 {
     if (!$messageSet) {
         $messageSet = new \Fulfil\MessageSet\Developer();
     }
     $flat = $this->flatten();
     if (!$flat->valid) {
         $msg = implode("\n - ", $messageSet->formatAll($flat->messages)) . "\n";
         throw new \Fulfil\ValidationException("Failed validation:\n - " . $msg);
     }
 }
Ejemplo n.º 2
0
function main()
{
    global $argv;
    $registry = \Fulfil\Registry::standard();
    $pdo = new \PDO(getenv('JUNK_DB_DSN'), getenv('JUNK_DB_USER'), getenv('JUNK_DB_PASS'), [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
    $reader = new \Fulfil\Ext\MySqlReader($registry, $pdo);
    $schema = $reader->tableSchema($argv[1], $argv[2]);
    var_dump($schema);
    $ctx = new \Fulfil\Context();
    $in = ['foo' => 'a', 'bar' => '2', 'baz' => ['zz', 'yy']];
    var_dump($schema->apply($in, $ctx));
    $msg = new \Fulfil\MessageSet\Developer();
    foreach ($msg->formatContext($ctx) as $text) {
        echo "{$text}\n";
    }
}
Ejemplo n.º 3
0
<?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']));