Symfony2 Assert\Expression 注释不支持常量
Symfony2 Assert\Expression annotation doesn't support Constants
通常我在所有基于注释的地方使用 Constants
,例如annotations, route and assert annotations
,但在 Assert\Expression 中它抛出 Variable "EntityInterface" is not valid around position 26.
这是一个错误还是一种特殊的罕见情况?
<?php
/**
* @var string
*
* @ORM\Column(name="id_number", type="string", length=11, nullable=true)
* @Assert\Expression(
* "this.getNationality() == EntityInterface::COUNTRY_DEFAULT_VALUE and value != null",
* message = "form.user.validation.id_number.blank",
* groups = {"personal_info"}
* )
* @Assert\Regex(
* pattern="/^([\d]{11})$/",
* match=true,
* message="form.user.validation.id_number.regex",
* groups = {"personal_info"}
* )
*/
private $idNumber;
尝试使用
/**
* @ORM\Column(name="id_number", type="string", length=11, nullable=true)
* @Assert\Expression(
* "this.getNationality() == constant('EntityInterface::COUNTRY_DEFAULT_VALUE') and value != null",
* message = "form.user.validation.id_number.blank",
* groups = {"personal_info"}
* )
*/
相反(省略了示例的部分内容以专注于在此处使用 constant()
)。
参考
通常我在所有基于注释的地方使用 Constants
,例如annotations, route and assert annotations
,但在 Assert\Expression 中它抛出 Variable "EntityInterface" is not valid around position 26.
这是一个错误还是一种特殊的罕见情况?
<?php
/**
* @var string
*
* @ORM\Column(name="id_number", type="string", length=11, nullable=true)
* @Assert\Expression(
* "this.getNationality() == EntityInterface::COUNTRY_DEFAULT_VALUE and value != null",
* message = "form.user.validation.id_number.blank",
* groups = {"personal_info"}
* )
* @Assert\Regex(
* pattern="/^([\d]{11})$/",
* match=true,
* message="form.user.validation.id_number.regex",
* groups = {"personal_info"}
* )
*/
private $idNumber;
尝试使用
/**
* @ORM\Column(name="id_number", type="string", length=11, nullable=true)
* @Assert\Expression(
* "this.getNationality() == constant('EntityInterface::COUNTRY_DEFAULT_VALUE') and value != null",
* message = "form.user.validation.id_number.blank",
* groups = {"personal_info"}
* )
*/
相反(省略了示例的部分内容以专注于在此处使用 constant()
)。
参考