Example #1
0
/**
 * @param string $method
 * @return \Closure
 */
function hasMethod($method)
{
    if (!is_string($method)) {
        return never();
    }
    return combine(pool(isObject(), combine(isString(), 'class_exists')), function ($object) use($method) {
        return method_exists($object, $method);
    });
}
Example #2
0
function baseType($value)
{
    if (isString($value)) {
        return 'string';
    }
    if (isInteger($value)) {
        return 'integer';
    }
    return 'object';
}
Example #3
0
    }
    return true;
};
// Validates data
$validates = function ($json) {
    if ($json === NULL) {
        returns(error('Body request not found'));
        return false;
    }
    if (!isString($json->{'name'})) {
        returns(error('Name field is empty'));
        return false;
    }
    if (!isEmail($json->{'email'})) {
        returns(error('E-mail field is empty'));
        return false;
    }
    if (!isString($json->{'password'})) {
        returns(error('Password field is empty'));
        return false;
    }
    return true;
};
// Now, read it as a human and execute our orders :)
$theData = $jsonFrom($input());
if ($validates($theData)) {
    $token = $saves($theData);
    if ($sendmail($token, $theData->{'email'})) {
        returns(success());
    }
}
Example #4
0
function isEmail($email)
{
    return isString($email) && filter_var($email, FILTER_VALIDATE_EMAIL);
}
Example #5
0
function fIsString()
{
    return function ($d) {
        return isString($d);
    };
}
Example #6
0
function saveBusListAsJson($array)
{
    $buses = [];
    foreach ($array as $key => $value) {
        array_push($buses, ["Route" => $key, "Count" => count($array[$key]), "DisplayText" => (isString($key) ? "train" : "bus") . (count($array[$key]) > 1 ? isString($key) ? "s" : "es" : ""), "Bus" => isString($key) ? "false" : "true", "Selected" => "false"]);
    }
    file_put_contents(Constants::DATA_DIR . "buslist.json", json_encode(recursiveMapToString($buses)));
}
Example #7
0
/**
 * @return \Closure
 */
function isNotString()
{
    return negate(isString());
}