Skip to content

[ExpressionLanguage] Add flags support in parse() and lint() #19529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions components/expression_language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ other hand, returns a boolean indicating if the expression is valid or not::

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

The call to these methods can be configured through flags. The available flags
are available in the :class:`Symfony\\Component\\ExpressionLanguage\\Parser` class
and are the following:

* ``IGNORE_UNKNOWN_VARIABLES``: don't throw an exception if a variable is not
defined in the expression;
* ``IGNORE_UNKNOWN_FUNCTIONS``: don't throw an exception if a function is not
defined in the expression.

This is how you can use these flags::

use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\ExpressionLanguage\Parser;

$expressionLanguage = new ExpressionLanguage();

// this return true because the unknown variables and functions are ignored
var_dump($expressionLanguage->lint('unknown_var + unknown_function()', Parser::IGNORE_UNKNOWN_VARIABLES | Parser::IGNORE_UNKNOWN_FUNCTIONS));

.. versionadded:: 7.1

The support for flags in the ``parse()`` and ``lint()`` methods
was introduced in Symfony 7.1.

Passing in Variables
--------------------

Expand Down