Validator ######### .. highlight:: php ``Arokettu\ArithmeticParser\Validator`` can be used to catch situations that are valid for the parser but will definitely fail in calculator, namely: * Undefined variable. A list of available variables is unknown during parsing time * Undefined function. A list of functions may be not final during parsing time, this allows users to have dynamic functions if needed * Not enough arguments passed to a function. Same reasons, function list may be dynamic ``Validator\Warning`` ===================== ``Arokettu\ArithmeticParser\Validator\Warning`` An object describing a validator warning. There are 3 warnings currently: * ``MissingVariablesWarning`` * ``MissingFunctionsWarning`` * ``MissingFunctionArgumentsWarning`` :: getMessage(); // convert to an exception throw $warning->toException(); } Methods ======= Validator exposes several methods that do a single thing but tailored to different possible use semantics ``Validator::validate()`` ------------------------- Returns an array of ``Arokettu\ArithmeticParser\Validator\Warning``:: parse('a + 1'); $warnings = Validator::validate($parsed, $config, ['a']); $isValid = $warnings === []; foreach ($warnings as $warning) { // ... } ``Validator::isValid()`` ------------------------ Returns a boolean, can optionally populate a list of warnings:: parse('a + 1'); $isValid = Validator::isValid($parsed, $config, ['a'], $warnings); foreach ($warnings as $warning) { // ... } ``Validator::assertValid()`` ---------------------------- Throws an exception when the input is not valid:: parse('a + 1'); try { Validator::assertValid($parsed, $config, ['a']); $isValid = true; } catch (ValidationException $e) { $isValid = false; }