本文整理汇总了PHP中Symfony\Component\Validator\ExecutionContext::validateValue方法的典型用法代码示例。如果您正苦于以下问题:PHP ExecutionContext::validateValue方法的具体用法?PHP ExecutionContext::validateValue怎么用?PHP ExecutionContext::validateValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\ExecutionContext
的用法示例。
在下文中一共展示了ExecutionContext::validateValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: walkConstraint
/**
* Validates a value against a constraint.
*
* @param Constraint $constraint
* @param $value
* @param $group
* @param $propertyPath
* @param null $currentClass
* @param null $currentProperty
*
* @deprecated Deprecated since version 2.2, to be removed in 2.3.
*/
public function walkConstraint(Constraint $constraint, $value, $group, $propertyPath, $currentClass = null, $currentProperty = null)
{
trigger_error('walkConstraint() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
$metadata = null;
// BC code to make getCurrentClass() and getCurrentProperty() work when
// called from within this method
if (null !== $currentClass) {
$metadata = $this->metadataFactory->getMetadataFor($currentClass);
if (null !== $currentProperty && $metadata instanceof PropertyMetadataContainerInterface) {
$metadata = current($metadata->getPropertyMetadata($currentProperty));
}
}
$context = new ExecutionContext($this->visitor, $this->translator, $this->translationDomain, $metadata, $value, $group, $propertyPath);
$context->validateValue($value, $constraint);
}
示例2: validate
/**
* validate
*
* @param type $data
* @param ExecutionContext $context
*/
public function validate($data, ExecutionContext $context)
{
if ($data['mode'] !== 'add_favorite') {
$context->validateValue($data['product_class_id'], array(new Assert\NotBlank()), '[product_class_id]');
if ($this->Product->getClassName1()) {
$context->validateValue($data['classcategory_id1'], array(new Assert\NotBlank(), new Assert\NotEqualTo(array('value' => '__unselected', 'message' => 'form.type.select.notselect'))), '[classcategory_id1]');
}
//商品規格2初期状態(未選択)の場合の返却値は「NULL」で「__unselected」ではない
if ($this->Product->getClassName2()) {
$context->validateValue($data['classcategory_id2'], array(new Assert\NotBlank(), new Assert\NotEqualTo(array('value' => '__unselected', 'message' => 'form.type.select.notselect'))), '[classcategory_id2]');
}
}
}
示例3: 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);
}
示例4: visit
/**
* {@inheritdoc}
*/
public function visit(MetadataInterface $metadata, $value, $group, $propertyPath)
{
$context = new ExecutionContext(
$this,
$metadata,
$value,
$group,
$propertyPath
);
$context->validateValue($value, $metadata->findConstraints($group));
}
示例5: 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();
}
示例6: 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());
}
示例7: validate
/**
* validate
*
* @param type $data
* @param ExecutionContext $context
*/
public function validate($data, ExecutionContext $context)
{
if ($data['mode'] === 'add_favorite') {
if (!$this->security->isGranted('ROLE_USER')) {
$context->addViolationAt('', 'ログインしてください.');
}
} else {
$context->validateValue($data['product_class_id'], array(new Assert\NotBlank()), '[product_class_id]');
if ($this->Product->getClassName1()) {
$context->validateValue($data['classcategory_id1'], array(new Assert\NotBlank(), new Assert\NotEqualTo(array('value' => '__unselected', 'message' => 'This value should be blank.'))), '[classcategory_id1]');
}
if ($this->Product->getClassName2()) {
$context->validateValue($data['classcategory_id2'], array(new Assert\NotBlank(), new Assert\NotEqualTo(array('value' => '__unselected', 'message' => 'This value should be blank.'))), '[classcategory_id2]');
}
}
}
示例8: walkConstraint
/**
* Validates a value against a constraint.
*
* @param Constraint $constraint
* @param $value
* @param $group
* @param $propertyPath
* @param null $currentClass
* @param null $currentProperty
*
* @deprecated Deprecated since version 2.2, to be removed in 2.3.
*/
public function walkConstraint(Constraint $constraint, $value, $group, $propertyPath, $currentClass = null, $currentProperty = null)
{
$metadata = null;
// BC code to make getCurrentClass() and getCurrentProperty() work when
// called from within this method
if (null !== $currentClass) {
$metadata = $this->metadataFactory->getMetadataFor($currentClass);
if (null !== $currentProperty && $metadata instanceof PropertyMetadataContainerInterface) {
$metadata = current($metadata->getPropertyMetadata($currentProperty));
}
}
$context = new ExecutionContext($this->visitor, $metadata, $value, $group, $propertyPath);
$context->validateValue($value, $constraint);
}