Ejemplo n.º 1
0
 public function testSeqErr()
 {
     $vfs = [function ($in) {
         throw new ValidationException('a');
     }, function ($in) {
         throw new ValidationException('b');
     }];
     $_ = seq($vfs);
     try {
         $_('dummy');
     } catch (ValidationException $e) {
         $this->assertEquals('a, b', $e->getMessage());
     }
     $_ = seq_($vfs);
     try {
         $_('dummy');
     } catch (ValidationException $e) {
         $this->assertEquals('a', $e->getMessage());
     }
 }
Ejemplo n.º 2
0
/**
 * Combine a map of validation functions into a map validator
 * 
 * Fields with no rules count as validation errors.
 * Throw exception immediately at the first problem.
 */
function map_S($callables)
{
    return seq_([function ($data) use($callables) {
        $diff = array_diff(array_keys($data), array_keys($callables));
        if (count($diff) > 0) {
            throw new IncompleteValidationException("the following fields lack validation rules: " . implode(',', $diff));
        }
        return $data;
    }, map_($callables)]);
}