ExpressionSyntax
此约束检查该值是否为有效的 ExpressionLanguage 表达式。
应用于 | 属性或方法 |
类 | ExpressionSyntax |
验证器 | ExpressionSyntaxValidator |
基本用法
以下约束确保
- the
promotion
属性存储的值是有效的 ExpressionLanguage 表达式; - the
shippingOptions
属性也确保表达式仅使用某些变量。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// src/Entity/Order.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Order
{
#[Assert\ExpressionSyntax]
protected string $promotion;
#[Assert\ExpressionSyntax(
allowedVariables: ['user', 'shipping_centers'],
)]
protected string $shippingOptions;
}
选项
allowedVariables
类型: array
或 null
默认值: null
如果定义了此选项,则表达式只能使用名称包含在此选项中的变量。取消设置此选项或将其值设置为 null
以允许任何变量。
本作品,包括代码示例,根据 Creative Commons BY-SA 3.0 许可获得许可。