本文整理汇总了PHP中Symfony\Component\Validator\Constraint::getTargets方法的典型用法代码示例。如果您正苦于以下问题:PHP Constraint::getTargets方法的具体用法?PHP Constraint::getTargets怎么用?PHP Constraint::getTargets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\Constraint
的用法示例。
在下文中一共展示了Constraint::getTargets方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addConstraint
/**
* {@inheritDoc}
*/
public function addConstraint(Constraint $constraint)
{
if (!in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets())) {
throw new ConstraintDefinitionException(sprintf('The constraint %s cannot be put on classes', get_class($constraint)));
}
$constraint->addImplicitGroupName($this->getDefaultGroup());
parent::addConstraint($constraint);
}
示例2: addConstraint
/**
* {@inheritdoc}
*/
public function addConstraint(Constraint $constraint)
{
if (!in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets())) {
throw new ConstraintDefinitionException(sprintf('The constraint %s cannot be put on properties or getters', get_class($constraint)));
}
parent::addConstraint($constraint);
return $this;
}
示例3:
function it_doesnt_support_multi_targets_constraint($guesser, $factory, ClassMetadata $metadata, ProductValueInterface $value, AttributeInterface $attribute, Constraint $multiTargets, Constraint $validNumber)
{
$factory->createMetadata(Argument::any())->willReturn($metadata);
$value->getAttribute()->willReturn($attribute);
$attribute->getBackendType()->willReturn('varchar');
$guesser->guessConstraints($attribute)->willReturn([$multiTargets]);
$multiTargets->getTargets()->willReturn([Constraint::PROPERTY_CONSTRAINT, Constraint::CLASS_CONSTRAINT]);
$this->shouldThrow(new \LogicException('No support provided for constraint on many targets'))->duringGetMetadataFor($value);
}
示例4: addConstraint
/**
* @param ClassMetadata $metadata
* @param Constraint $constraint
* @param AttributeInterface $attribute
*/
protected function addConstraint(ClassMetadata $metadata, Constraint $constraint, AttributeInterface $attribute)
{
$target = $constraint->getTargets();
if (is_array($target)) {
throw new \LogicException('No support provided for constraint on many targets');
} elseif (Constraint::PROPERTY_CONSTRAINT === $target) {
$metadata->addPropertyConstraint($attribute->getBackendType(), $constraint);
} elseif (Constraint::CLASS_CONSTRAINT === $target) {
$metadata->addConstraint($constraint);
}
}
示例5: addConstraint
/**
* {@inheritDoc}
*/
public function addConstraint(Constraint $constraint)
{
if (!in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets())) {
throw new ConstraintDefinitionException(sprintf('The constraint %s cannot be put on properties or getters', get_class($constraint)));
}
if ($constraint instanceof Valid) {
$this->cascaded = true;
$this->collectionCascaded = $constraint->traverse;
} else {
parent::addConstraint($constraint);
}
return $this;
}
示例6: addConstraint
/**
* {@inheritdoc}
*/
public function addConstraint(Constraint $constraint)
{
if (!in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets())) {
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', get_class($constraint)));
}
if ($constraint instanceof Valid) {
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', get_class($constraint)));
}
if ($constraint instanceof Traverse) {
if ($constraint->traverse) {
// If traverse is true, traversal should be explicitly enabled
$this->traversalStrategy = TraversalStrategy::TRAVERSE;
} else {
// If traverse is false, traversal should be explicitly disabled
$this->traversalStrategy = TraversalStrategy::NONE;
}
// The constraint is not added
return $this;
}
$constraint->addImplicitGroupName($this->getDefaultGroup());
parent::addConstraint($constraint);
return $this;
}