Skip to content

Commit a3ba7fc

Browse files
[ExpressionLanguage] Add flags support in parse() and lint()
1 parent 8f8b9d2 commit a3ba7fc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

components/expression_language.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,30 @@ other hand, returns a boolean indicating if the expression is valid or not::
112112

113113
var_dump($expressionLanguage->lint('1 + 2')); // displays true
114114

115+
The call to these methods can be configured through flags. The available flags
116+
are available in the :class:`Symfony\\Component\\ExpressionLanguage\\Parser` class
117+
and are the following:
118+
119+
* ``IGNORE_UNKNOWN_VARIABLES``: don't throw an exception if a variable is not
120+
defined in the expression;
121+
* ``IGNORE_UNKNOWN_FUNCTIONS``: don't throw an exception if a function is not
122+
defined in the expression.
123+
124+
This is how you can use these flags::
125+
126+
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
127+
use Symfony\Component\ExpressionLanguage\Parser;
128+
129+
$expressionLanguage = new ExpressionLanguage();
130+
131+
// this return true because the unknown variables and functions are ignored
132+
var_dump($expressionLanguage->lint('unknown_var + unknown_function()', Parser::IGNORE_UNKNOWN_VARIABLES | Parser::IGNORE_UNKNOWN_FUNCTIONS));
133+
134+
.. versionadded:: 7.1
135+
136+
The support for flags in the ``parse()`` and ``lint()`` methods
137+
was introduced in Symfony 7.1.
138+
115139
Passing in Variables
116140
--------------------
117141

0 commit comments

Comments
 (0)