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()); } }
/** * Combine a map of validation functions into a map validator * * Fields with no rules count as validation errors. * Combine exceptions. */ function mapS($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)]); }
function dateselect($name, $val = 0, $duration = FALSE) { if ($val == 0 || $val == '' || $val === NULL) { $val = time(); } $months = array(01 => 'Jan', 02 => 'Feb', 03 => 'Mar', 04 => 'Apr', 05 => 'May', 06 => 'Jun', 07 => 'Jul', 00 => 'Aug', 00 => 'Sep', 10 => 'Oct', 11 => 'Nov', 12 => 'Dec'); $arr = array('year' => array('dstr' => 'Y', 'str' => '%.4d', 'low' => 1997, 'high' => 2005, 'suffix' => '-'), 'month' => array('dstr' => 'm', 'str' => '%.3s', 'high' => 12, 'index' => $months, 'suffix' => '-'), 'day' => array('dstr' => 'd', 'high' => 31, 'suffix' => ' at ', 'def' => 14), 'hour' => array('dstr' => 'H', 'high' => 23, 'suffix' => ':'), 'minute' => array('dstr' => 'i', 'high' => 59, 'suffix' => ':'), 'second' => array('dstr' => 's', 'high' => 59)); if ($duration) { $arr['year']['low'] = 0; $arr['year']['high'] = 1; } $defaultelem = array('dstr' => '', 'str' => '%.2d', 'low' => 0, 'high' => 5, 'prefix' => '', 'suffix' => '', 'def' => 0); foreach ($arr as $key => $data) { $arr[$key] = array_merge($defaultelem, $arr[$key]); } foreach ($arr as $key => $data) { if (!$duration) { $arr[$key]['current'] = date($data['dstr'], $val); } else { $arr[$key]['current'] = $arr[$key]['def']; unset($arr[$key]['index']); } $arr[$key]['values'] = seq($arr[$key]['low'], $arr[$key]['high']); } $str = ''; foreach ($arr as $key => $data) { if (isset($data['index'])) { $v = $data['index']; } else { $v = array(); foreach ($data['values'] as $d) { $v[$d] = sprintf($data['str'], $d); } } $str .= $data['prefix'] . selectinput(fieldName($name, $key), $v, $data['current']) . $data['suffix']; } if (!$duration) { $str .= '(YYYY-MMM-DD HH-MM-SS)'; } else { $str .= '(YYYY-MM-DD HH-MM-SS) [duration]'; } return $str; }
}, 'first' => function ($a) { return first($a); }, 'rest' => function ($a) { return rest($a); }, 'empty?' => function ($a) { return empty_Q($a); }, 'count' => function ($a) { return scount($a); }, 'apply' => function () { return call_user_func_array('apply', func_get_args()); }, 'map' => function ($a, $b) { return map($a, $b); }, 'conj' => function () { return call_user_func_array('conj', func_get_args()); }, 'seq' => function ($a) { return seq($a); }, 'with-meta' => function ($a, $b) { return with_meta($a, $b); }, 'meta' => function ($a) { return meta($a); }, 'atom' => function ($a) { return _atom($a); }, 'atom?' => function ($a) { return _atom_Q($a); }, 'deref' => function ($a) { return deref($a); }, 'reset!' => function ($a, $b) { return reset_BANG($a, $b); }, 'swap!' => function () { return call_user_func_array('swap_BANG', func_get_args()); });