/** * @param ProductValueInterface $value * * @return ClassMetadata */ protected function createMetadata(ProductValueInterface $value) { $class = ClassUtils::getClass($value); $metadata = $this->factory->createMetadata($class); $attribute = $value->getAttribute(); foreach ($this->guesser->guessConstraints($attribute) as $constraint) { $this->addConstraint($metadata, $constraint, $attribute); } return $metadata; }
function it_can_guess_constraints(AttributeInterface $attribute, ConstraintGuesserInterface $guesserFoo, ConstraintGuesserInterface $guesserBar, ConstraintGuesserInterface $guesserBaz) { $guesserFoo->guessConstraints($attribute)->willReturn(['foo']); $guesserBar->guessConstraints($attribute)->willReturn(['bar']); $guesserBaz->guessConstraints($attribute)->willReturn(['baz']); $guesserFoo->supportAttribute($attribute)->willReturn(true); $guesserBar->supportAttribute($attribute)->willReturn(false); $guesserBaz->supportAttribute($attribute)->willReturn(true); $this->addConstraintGuesser($guesserFoo); $this->addConstraintGuesser($guesserBar); $this->addConstraintGuesser($guesserBaz); $this->guessConstraints($attribute)->shouldReturn(['foo', 'baz']); }
/** * Returns an array of constraints for a given attribute * * @param AttributeInterface $attribute * * @return string */ protected function getAttributeConstraints(AttributeInterface $attribute) { $code = $attribute->getCode(); if (!isset($this->constraints[$code])) { if ($this->constraintGuesser->supportAttribute($attribute)) { $this->constraints[$code] = $this->constraintGuesser->guessConstraints($attribute); } else { $this->constraints[$code] = []; } } return $this->constraints[$code]; }