class Engine (View source)

internal  
 

Validation expression language engine.

Engine/Parser implementation for the Mighty Validation Expression Language (mVEL) v1 (v1.*.*).

Methods

static string
cleanExpression(string $expression)

Cleans (minifies) the validation expression by removing comments and unnecessary whitespace from it.

static string
createRuleArguments(array $arguments)

Returns valid rule arguments by stringifing the passed array.

static string
createRuleName(string $name)

Returns a valid rule name as per convention.

static string
createRuleStatement(string $name, string $arguments = '')

Returns a valid rule statement from the passed name and arguments.

static bool
evaluateBitwiseExpression(string $expression)

Evaluates a bitwise expression string and returns its boolean result.

static array
evaluateExpression(string $expression, array $results)

Evaluates the passed validation expression string using the provided statements results.

static array
getBitwiseTranslationsMap()

No description

static array
parseExpression(string $expression)

Parses the validation expression by extracting the validations into an array of checks.

static array
parseRule(string $statement, array $casts)

Parses the rule statement by extracting rule name and rule arguments.

Details

static string cleanExpression(string $expression)

Since: 1.1.0

Cleans (minifies) the validation expression by removing comments and unnecessary whitespace from it.

Parameters

string $expression

Validation expression string.

Return Value

string

The cleaned validation expression.

static string createRuleArguments(array $arguments)

Returns valid rule arguments by stringifing the passed array.

Parameters

array $arguments

Rule arguments.

Return Value

string

The stringified rule arguments.

static string createRuleName(string $name)

Returns a valid rule name as per convention.

Parameters

string $name

Rule name, preferably in camelCase.

Return Value

string

The rule name like (namespace.ruleName).

static string createRuleStatement(string $name, string $arguments = '')

Returns a valid rule statement from the passed name and arguments.

Parameters

string $name

Rule name. The name may need to be passed to self::createRuleName() first.

string $arguments

[optional] Rule arguments. The arguments may need to be passed to self::createRuleArguments() first.

Return Value

string

The rule statement.

static bool evaluateBitwiseExpression(string $expression)

Evaluates a bitwise expression string and returns its boolean result.

NOTE: The expression may only contain the following characters: 0, 1, ~, &, |, ^, (, ). Which are the subset of Bitwise that is the same as Boolean Algebra (returns a boolean value). The expression may also have whitespace characters (spaces, tabs, new lines), these will simply be discarded.

Parameters

string $expression

The bitwise expression to evaluate.

Return Value

bool

The result of the evaluation.

Exceptions

InvalidBitwiseExpressionException
InvalidBitwiseExpressionException

static array evaluateExpression(string $expression, array $results)

Since: 1.1.0

Evaluates the passed validation expression string using the provided statements results.

Parameters

string $expression

The validation expression to evaluate.

array $results

Statements results. An associative array where key is the statement and value is the result.

Return Value

array

An associative array containing the resulted bitwise expression and its result.

Exceptions

InvalidBitwiseExpressionException
InvalidBitwiseExpressionException

static private array getBitwiseTranslationsMap()

No description

Return Value

array

static array parseExpression(string $expression)

Parses the validation expression by extracting the validations into an array of checks.

Parameters

string $expression

Validation expression string.

Return Value

array

An array of arrays where each of the nested arrays contains rule name and rule statement.

static array parseRule(string $statement, array $casts)

Parses the rule statement by extracting rule name and rule arguments.

Parameters

string $statement

Rule statement string.

array $casts

Rule arguments data-types casts.

Return Value

array

A symbol as an associative array containing name and arguments (arguments will be in casted to their expected data-types).