ConstraintViolationList
其行为类似于
ConstraintViolationInterface
实施。从每个
约束ViolationInterface
对象,可以调用
getPropertyPath
方法,该方法为您提供根数据的无效元素的属性路径(根数据可以使用
getRoot
任何方法
约束ViolationInterface
实施。
use Symfony\Component\PropertyAccess\PropertyAccess;
// ...
foreach ($errors as $error) {
$invalidElementAccessor = PropertyAccess::createPropertyAccessor();
$invalidElement = $invalidElementAccessor->getValue($error->getRoot(), $error->getPropertyPath());
// Do something with element
}