Provide a configurable set of matching rules, used by tasks and transformers to test an input (e.g. to filter it).
- Namespace:
CleverAge\ProcessBundle\Transformer\ConditionTrait - Options algorithm:
- each condition option is a list of
property path => expected value(or justproperty pathforemptyandnot_empty, the value being ignored) - the property path is read on the input with the Symfony
PropertyAccessor: use
[key]for arrays,propertyora.bfor objects. An unreadable path givesnull, without error. The empty path''targets the whole input - all conditions must match (logical AND, there is no OR): the checks are run in the order
match,empty,match_regexp,not_match,not_empty,not_match_regexp, and stop at the first failure - with no condition at all, the input always matches
- each condition option is a list of
| Code | Type | Required | Default | Description |
|---|---|---|---|---|
match |
array |
[] |
path => value: the value at path must be strictly equal (===) to value |
|
not_match |
array |
[] |
path => value: the value at path must not be strictly equal (!==) to value |
|
empty |
array |
[] |
path => ~: the value at path must be empty (PHP empty(): null, '', '0', 0, false, [], or missing) |
|
not_empty |
array |
[] |
path => ~: the value at path must not be empty |
|
match_regexp |
array |
[] |
path => pattern: the value at path, cast to string, must match the regular expression |
|
not_match_regexp |
array |
[] |
path => pattern: the value at path, cast to string, must not match the regular expression |
An invalid regular expression makes both match_regexp and not_match_regexp fail.
- Call
ConditionTrait::configureConditionOptionsto add the condition options at the root of yourOptionsResolver, orConditionTrait::configureWrappedConditionOptionsto add them under a single option (e.g.condition) - Set the
$accessorproperty with aPropertyAccessorInterface(e.g. in the constructor) - Call
ConditionTrait::checkConditionwith the input and the resolved conditions; it returnstrueif all conditions match
The input can be of any type: on a scalar input (e.g. the items of a list of strings in
ArrayFilterTransformer), use the empty path '' to test the whole value;
any other path gives null, like a missing key.
- Strict equality: the
[status]key must beactive(string) and[stock]must not be0(integer)
match:
'[status]': active
not_match:
'[stock]': 0- Emptiness:
[email]must be filled and[deleted_at]must be empty or missing
not_empty:
'[email]': ~
empty:
'[deleted_at]': ~- Regular expressions, on an object input
match_regexp:
sku: '/^[A-Z]{3}-\d+$/'
not_match_regexp:
customer.email: '/@example\.com$/'- Wrapped in a
conditionoption (e.g. ArrayFilterTransformer)
# Transformer options level
array_filter:
condition:
match:
'[type]': product- FilterTask: condition options at the root of the task options
- ColumnAggregatorTask:
conditionoption, checked against{input_column_value: <column value>, input: <input>}(so use paths like[input_column_value]or[input][key]) - ArrayFilterTransformer:
conditionoption, checked against each item - UnsetTransformer:
conditionoption, checked against the input array