Download the PHP package uuf6429/expression-language-arrowfunc without Composer
On this page you can find all versions of the php package uuf6429/expression-language-arrowfunc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download uuf6429/expression-language-arrowfunc
More information about uuf6429/expression-language-arrowfunc
Files in uuf6429/expression-language-arrowfunc
Package expression-language-arrowfunc
Short Description Arrow function support in Symfony Expression Language
License MIT
Homepage https://github.com/uuf6429/expression-language-arrowfunc
Informations about the package expression-language-arrowfunc
➡️ Symfony Expression Language Arrow Function
for Symfony Expression Language (5-8)
This library extends Symfony Expression Language component to support Arrow Function (also known as Lambda Functions) syntax.
🔌 Installation
Install via Composer:
💡 Before You Start
1. How does it work?
Essentially, the library pre-processes expressions to replace callbacks with placeholders (variables), then generates new variables (with the callback as value), which are finally later on used for executing the expression. Conceptually:2. What does the syntax look like?
By default, the arrow function syntax looks like so:3. How safe is it?
Symfony Expression Language can be unsafe by design – if the result of expressions is used as a callable without being checked, global callables, functions and static methods could be called arbitrarily from (potentially malicious) expressions. This library acknowledges the risk and tries to mitigate it. **Problem Examples** 1. Exposing functionality that accepts a callable to Expression Language: 2. A naive implementation of arrow functions: **Solutions** There are two viable solutions: 1. Set the type declaration of methods or functions that will receive callbacks to `Closure` (*not `Callable`!*) - it works, but it is prone to mistakes and frankly, quite risky. 2. The engine wraps callbacks within an object that cannot be invoked by default – this is the safest option (and the default). Usages need to be aware of this wrapping, drastically decreasing the risk of mistakes.🚀 Usage
Usage
Two different APIs are provided to suit your integration needs:
1. Ready-Made Drop-in Replacement
If you just need a standard, drop-in replacement for Symfony's standard `ExpressionLanguage` class, use [`uuf6429\ExpressionLanguage\ExpressionLanguageWithArrowFunctions`]:2. Extensible Trait
If you want to integrate this functionality with your own custom `ExpressionLanguage` implementation or combine it with other classes, use the trait [`uuf6429\ExpressionLanguage\ArrowFunctionTrait`]:[!IMPORTANT]
For safety reasons, any returned callbacks are wrapped in a
SafeCallableobject. Your methods and functions need to expect and handle that object. This is to avoid expressions being able to "break out" and execute anything.
Here's a more complete example: