Mecha CMS

Detector.

Is::()

Specify a method logic.

2.0.02.2.0staticGenome
Is::_(string $key, callable $fn);

Example:

Is::_('hexColor', function($x) {
    if (!is_string($x)) {
        return false; // Must be a string
    }
    $i = strlen($x);
    if ($i !== 4 && $i !== 7) {
        return false; // Must consist of 4 or 7 character(s)
    }
    if ($x[0] !== '#') {
        return false; // Must begin with `#`
    }
    // Must only consist of `0123456789abcdef` character(s) after `#`
    return ctype_xdigit(substr($x, 1));
});

Another example with regular expression. Shorter, but worse in performance:

Is::_('hexColor', function($in) {
    return is_string($in) && preg_match('/^#(?:[a-f\d]{3}|[a-f\d]{6})$/i', $in);
});