Ejemplo n.º 1
0
/**
 * Returns the value as a float
 * @param mixed $val
 * @return float
 * @throws CastException if the value cannot be safely cast to a float
 */
function to_float($val)
{
    if (!safe_float($val)) {
        throw new CastException("Value could not be converted to float");
    } else {
        return (double) $val;
    }
}
Ejemplo n.º 2
0
/**
 * Judgehosts
 */
function judgehosts($args)
{
    global $DB;
    $query = 'TABLE SELECT hostname, active, polltime FROM judgehost';
    $byHostname = array_key_exists('hostname', $args);
    $query .= $byHostname ? ' WHERE hostname = %s' : '%_';
    $hostname = $byHostname ? $args['hostname'] : null;
    $jdatas = $DB->q($query, $hostname);
    return array_map(function ($jdata) {
        return array('hostname' => $jdata['hostname'], 'active' => safe_bool($jdata['active']), 'polltime' => safe_float($jdata['polltime']));
    }, $jdatas);
}