Skip to content

Commit 5f9efce

Browse files
committed
minor #19529 [ExpressionLanguage] Add flags support in parse() and lint() (alexandre-daubois)
This PR was merged into the 7.1 branch. Discussion ---------- [ExpressionLanguage] Add flags support in `parse()` and `lint()` Fix #19521 Requires #19528 Commits ------- a3ba7fc [ExpressionLanguage] Add flags support in `parse()` and `lint()`
2 parents 42f27f0 + a3ba7fc commit 5f9efce

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
@@ -110,6 +110,30 @@ other hand, returns a boolean indicating if the expression is valid or not::
110110

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

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

0 commit comments

Comments
 (0)