Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #24007 [ExpressionLanguage] SyntaxError : make a proposal when …
…no function or variable found (fmata) This PR was merged into the 3.4 branch. Discussion ---------- [ExpressionLanguage] SyntaxError : make a proposal when no function or variable found | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | needed ? Now when an Expression fails to be parsed, a SyntaxError is raised with an explicit message but it's impossible to extract the function, variable or the pair token type/token value to parse. When a functional user encounters a SyntaxError, by default there is no mechanism to understand why what he typed is incorrect. This PR exposes when it's possible the subject of the violation and in case of function or variable undefined in the Expression, a proposal is made. ```php <?php require 'vendor/autoload.php'; use Symfony\Component\ExpressionLanguage\Lexer; use Symfony\Component\ExpressionLanguage\Parser; use Symfony\Component\ExpressionLanguage\SyntaxError; $lexer = new Lexer(); $parser = new Parser(array()); try { $parser->parse($lexer->tokenize('user.city.departement in [departement, departement2]'), array('user', 'departement1', 'departement2')); } catch (SyntaxError $e) { echo $e->getMessage(); } ``` Outputs : > Variable "departement" is not valid around position 27 for expression `user.city.departement in [departement, departement2]`. > > Did you mean "departement1"? Commits ------- f19cf8a [ExpressionLanguage] make a proposal in SyntaxError message
- Loading branch information