You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Sylius Grid Bundle utilizes the Symfony `ExpressionLanguage` component to provide a flexible and powerful way to evaluate expressions.
5
+
6
+
Evaluating Expressions
7
+
----------------------
8
+
9
+
Expressions can be evaluated using the `sylius_grid.expression_language.expression_evaluator` service, which is an instance of `ExpressionEvaluator`.
10
+
11
+
The `ExpressionEvaluator` uses both an instance of `ExpressionLanguage` and a `VariablesCollectionInterface` (`sylius_grid.expression_language.variables_collection_aggregate`). This ensures that the evaluator has access to a collection of variables that developers can add.
12
+
13
+
To evaluate an expression:
14
+
- The `evaluateExpression` method is called with the expression string and an optional array of variables.
15
+
- The evaluator merges the provided variables with the collection of variables provided by the `VariablesCollectionAggregate` mentioned earlier.
16
+
- The expression is then evaluated with all the variables.
17
+
18
+
**Note that:**
19
+
- The `ExpressionLanguage` can be extended using expression providers.
20
+
-`sylius_grid.expression_language.variables_collection_aggregate` can be extended using custom variables collections.
21
+
22
+
Extending the Expression Language
23
+
---------------------------------
24
+
25
+
### Adding Expression Providers
26
+
27
+
The Symfony `ExpressionLanguage` component can be extended with functions using expression providers. To create a custom expression provider:
28
+
29
+
1. Your class should implement `Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface`.
30
+
2. Tag your service with `sylius.grid.provider`. You can automate this by using the `Sylius\Component\Grid\Attribute\AsExpressionProvider` attribute.
31
+
32
+
### Adding Custom Variables
33
+
34
+
Adding custom variables is done by creating a new variables collection:
35
+
36
+
1. Create a class that implements `Sylius\Component\Grid\ExpressionLanguage\VariablesCollectionInterface`.
37
+
2. Tag your service with `sylius.grid.variables`. You can automate this by using the `Sylius\Component\Grid\Attribute\AsExpressionVariables` attribute.
0 commit comments