Mike42\Escpos\Printer::validateStringRegex PHP Method

validateStringRegex() protected static method

Throw an exception if the argument doesn't match the given regex.
protected static validateStringRegex ( string $test, string $source, string $regex, string $argument = "Argument" )
$test string the input to test
$source string the name of the function calling this
$regex string valid values for this attribute, as a regex
$argument string the name of the parameter being validated
    protected static function validateStringRegex($test, $source, $regex, $argument = "Argument")
    {
        if (preg_match($regex, $test) === 0) {
            throw new InvalidArgumentException("{$argument} given to {$source} is invalid. It should match regex '{$regex}', but '{$test}' was given.");
        }
    }