本文整理匯總了PHP中Symfony\Component\Validator\ExecutionContext::getViolations方法的典型用法代碼示例。如果您正苦於以下問題:PHP ExecutionContext::getViolations方法的具體用法?PHP ExecutionContext::getViolations怎麽用?PHP ExecutionContext::getViolations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Validator\ExecutionContext
的用法示例。
在下文中一共展示了ExecutionContext::getViolations方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testAddViolationAtUsesPassedNullValue
public function testAddViolationAtUsesPassedNullValue()
{
$this->translator->expects($this->once())->method('trans')->with('Error', array('foo' => 'bar'))->will($this->returnValue('Translated error'));
$this->translator->expects($this->once())->method('transChoice')->with('Choice error', 2, array('foo' => 'bar'))->will($this->returnValue('Translated choice error'));
// passed null value should override preconfigured value "invalid"
$this->context->addViolationAt('bam.baz', 'Error', array('foo' => 'bar'), null);
$this->context->addViolationAt('bam.baz', 'Choice error', array('foo' => 'bar'), null, 2);
$this->assertEquals(new ConstraintViolationList(array(new ConstraintViolation('Translated error', 'Error', array('foo' => 'bar'), 'Root', 'foo.bar.bam.baz', null), new ConstraintViolation('Translated choice error', 'Choice error', array('foo' => 'bar'), 'Root', 'foo.bar.bam.baz', null, 2))), $this->context->getViolations());
}
示例2: testGetPropertyPathWithNestedCollectionsAndAllMixed
public function testGetPropertyPathWithNestedCollectionsAndAllMixed()
{
$constraints = new Collection(array('shelves' => new All(array('constraints' => array(new Collection(array('name' => new ConstraintA(), 'books' => new All(array('constraints' => array(new ConstraintA())))))))), 'name' => new ConstraintA()));
$data = array('shelves' => array(array('name' => 'Research', 'books' => array('foo', 'bar')), array('name' => 'VALID', 'books' => array('foozy', 'VALID', 'bazzy'))), 'name' => 'Library');
$expectedViolationPaths = array('[shelves][0][name]', '[shelves][0][books][0]', '[shelves][0][books][1]', '[shelves][1][books][0]', '[shelves][1][books][2]', '[name]');
$visitor = new ValidationVisitor('Root', $this->metadataFactory, new ConstraintValidatorFactory(), $this->translator);
$context = new ExecutionContext($visitor, $this->translator, self::TRANS_DOMAIN);
$context->validateValue($data, $constraints);
foreach ($context->getViolations() as $violation) {
$violationPaths[] = $violation->getPropertyPath();
}
$this->assertEquals($expectedViolationPaths, $violationPaths);
}
示例3: validateValue
/**
* {@inheritDoc}
*/
public function validateValue($value, $constraints, $groups = null)
{
$context = new ExecutionContext($this->createVisitor($value), $this->translator, $this->translationDomain);
$constraints = is_array($constraints) ? $constraints : array($constraints);
foreach ($constraints as $constraint) {
if ($constraint instanceof Valid) {
// Why can't the Valid constraint be executed directly?
//
// It cannot be executed like regular other constraints, because regular
// constraints are only executed *if they belong to the validated group*.
// The Valid constraint, on the other hand, is always executed and propagates
// the group to the cascaded object. The propagated group depends on
//
// * Whether a group sequence is currently being executed. Then the default
// group is propagated.
//
// * Otherwise the validated group is propagated.
throw new ValidatorException(sprintf('The constraint %s cannot be validated. Use the method validate() instead.', get_class($constraint)));
}
$context->validateValue($value, $constraint, $groups);
}
return $context->getViolations();
}
示例4: testGetPropertyPathWithNestedCollectionsMixed
public function testGetPropertyPathWithNestedCollectionsMixed()
{
$constraints = new Collection(array('foo' => new Collection(array('foo' => new ConstraintA(), 'bar' => new ConstraintA())), 'name' => new ConstraintA()));
$visitor = new ValidationVisitor('Root', $this->metadataFactory, new ConstraintValidatorFactory(), $this->translator);
$context = new ExecutionContext($visitor, $this->translator, self::TRANS_DOMAIN);
$context->validateValue(array('foo' => array('foo' => 'VALID')), $constraints);
$violations = $context->getViolations();
$this->assertEquals('[name]', $violations[1]->getPropertyPath());
}