class ExprBuilder

This class builds an if expression.

Properties

$ifPart
$thenPart

Methods

__construct(NodeDefinition $node)

Constructor.

always(Closure $then = null)

Marks the expression as being always used.

ifTrue(Closure $closure = null)

Sets a closure to use as tests.

ifString()

Tests if the value is a string.

ifNull()

Tests if the value is null.

ifArray()

Tests if the value is an array.

ifInArray(array $array)

Tests if the value is in an array.

ifNotInArray(array $array)

Tests if the value is not in an array.

then(Closure $closure)

Sets the closure to run if the test pass.

thenEmptyArray()

Sets a closure returning an empty array.

thenInvalid(string $message)

Sets a closure marking the value as invalid at validation time.

thenUnset()

Sets a closure unsetting this key of the array at validation time.

end()

Returns the related node.

static array
buildExpressions(array $expressions)

Builds the expressions.

Details

at line line 33
__construct(NodeDefinition $node)

Constructor.

Parameters

NodeDefinition $node The related node

at line line 45
ExprBuilder always(Closure $then = null)

Marks the expression as being always used.

Parameters

Closure $then

Return Value

ExprBuilder

at line line 65
ExprBuilder ifTrue(Closure $closure = null)

Sets a closure to use as tests.

The default one tests if the value is true.

Parameters

Closure $closure

Return Value

ExprBuilder

at line line 81
ExprBuilder ifString()

Tests if the value is a string.

Return Value

ExprBuilder

at line line 93
ExprBuilder ifNull()

Tests if the value is null.

Return Value

ExprBuilder

at line line 105
ExprBuilder ifArray()

Tests if the value is an array.

Return Value

ExprBuilder

at line line 119
ExprBuilder ifInArray(array $array)

Tests if the value is in an array.

Parameters

array $array

Return Value

ExprBuilder

at line line 133
ExprBuilder ifNotInArray(array $array)

Tests if the value is not in an array.

Parameters

array $array

Return Value

ExprBuilder

at line line 147
ExprBuilder then(Closure $closure)

Sets the closure to run if the test pass.

Parameters

Closure $closure

Return Value

ExprBuilder

at line line 159
ExprBuilder thenEmptyArray()

Sets a closure returning an empty array.

Return Value

ExprBuilder

at line line 177
ExprBuilder thenInvalid(string $message)

Sets a closure marking the value as invalid at validation time.

if you want to add the value of the node in your message just use a %s placeholder.

Parameters

string $message

Return Value

ExprBuilder

Exceptions

InvalidArgumentException

at line line 191
ExprBuilder thenUnset()

Sets a closure unsetting this key of the array at validation time.

Return Value

ExprBuilder

Exceptions

UnsetKeyException

at line line 205
NodeDefinition end()

Returns the related node.

Return Value

NodeDefinition

Exceptions

RuntimeException

at line line 224
static array buildExpressions(array $expressions)

Builds the expressions.

Parameters

array $expressions An array of ExprBuilder instances to build

Return Value

array