You are here

class ConstraintViolationBuilder in Plug 7

Default implementation of {@link ConstraintViolationBuilderInterface}.

@since 2.5 @author Bernhard Schussek <bschussek@gmail.com>

@internal You should not instantiate or use this class. Code against {@link ConstraintViolationBuilderInterface} instead.

Hierarchy

Expanded class hierarchy of ConstraintViolationBuilder

1 file declares its use of ConstraintViolationBuilder
ExecutionContext.php in lib/Symfony/validator/Symfony/Component/Validator/Context/ExecutionContext.php

File

lib/Symfony/validator/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php, line 29

Namespace

Symfony\Component\Validator\Violation
View source
class ConstraintViolationBuilder implements ConstraintViolationBuilderInterface {

  /**
   * @var ConstraintViolationList
   */
  private $violations;

  /**
   * @var string
   */
  private $message;

  /**
   * @var array
   */
  private $parameters;

  /**
   * @var mixed
   */
  private $root;

  /**
   * @var mixed
   */
  private $invalidValue;

  /**
   * @var string
   */
  private $propertyPath;

  /**
   * @var TranslatorInterface
   */
  private $translator;

  /**
   * @var string|null
   */
  private $translationDomain;

  /**
   * @var int|null
   */
  private $plural;

  /**
   * @var Constraint
   */
  private $constraint;

  /**
   * @var mixed
   */
  private $code;

  /**
   * @var mixed
   */
  private $cause;
  public function __construct(ConstraintViolationList $violations, Constraint $constraint, $message, array $parameters, $root, $propertyPath, $invalidValue, TranslatorInterface $translator, $translationDomain = null) {
    $this->violations = $violations;
    $this->message = $message;
    $this->parameters = $parameters;
    $this->root = $root;
    $this->propertyPath = $propertyPath;
    $this->invalidValue = $invalidValue;
    $this->translator = $translator;
    $this->translationDomain = $translationDomain;
    $this->constraint = $constraint;
  }

  /**
   * {@inheritdoc}
   */
  public function atPath($path) {
    $this->propertyPath = PropertyPath::append($this->propertyPath, $path);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setParameter($key, $value) {
    $this->parameters[$key] = $value;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setParameters(array $parameters) {
    $this->parameters = $parameters;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setTranslationDomain($translationDomain) {
    $this->translationDomain = $translationDomain;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setInvalidValue($invalidValue) {
    $this->invalidValue = $invalidValue;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setPlural($number) {
    $this->plural = $number;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setCode($code) {
    $this->code = $code;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function setCause($cause) {
    $this->cause = $cause;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function addViolation() {
    if (null === $this->plural) {
      $translatedMessage = $this->translator
        ->trans($this->message, $this->parameters, $this->translationDomain);
    }
    else {
      try {
        $translatedMessage = $this->translator
          ->transChoice($this->message, $this->plural, $this->parameters, $this->translationDomain);
      } catch (\InvalidArgumentException $e) {
        $translatedMessage = $this->translator
          ->trans($this->message, $this->parameters, $this->translationDomain);
      }
    }
    $this->violations
      ->add(new ConstraintViolation($translatedMessage, $this->message, $this->parameters, $this->root, $this->propertyPath, $this->invalidValue, $this->plural, $this->code, $this->constraint, $this->cause));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConstraintViolationBuilder::$cause private property
ConstraintViolationBuilder::$code private property
ConstraintViolationBuilder::$constraint private property
ConstraintViolationBuilder::$invalidValue private property
ConstraintViolationBuilder::$message private property
ConstraintViolationBuilder::$parameters private property
ConstraintViolationBuilder::$plural private property
ConstraintViolationBuilder::$propertyPath private property
ConstraintViolationBuilder::$root private property
ConstraintViolationBuilder::$translationDomain private property
ConstraintViolationBuilder::$translator private property
ConstraintViolationBuilder::$violations private property
ConstraintViolationBuilder::addViolation public function Adds the violation to the current execution context. Overrides ConstraintViolationBuilderInterface::addViolation
ConstraintViolationBuilder::atPath public function Stores the property path at which the violation should be generated. Overrides ConstraintViolationBuilderInterface::atPath
ConstraintViolationBuilder::setCause public function Sets the cause of the violation. Overrides ConstraintViolationBuilderInterface::setCause
ConstraintViolationBuilder::setCode public function Sets the violation code. Overrides ConstraintViolationBuilderInterface::setCode
ConstraintViolationBuilder::setInvalidValue public function Sets the invalid value that caused this violation. Overrides ConstraintViolationBuilderInterface::setInvalidValue
ConstraintViolationBuilder::setParameter public function Sets a parameter to be inserted into the violation message. Overrides ConstraintViolationBuilderInterface::setParameter
ConstraintViolationBuilder::setParameters public function Sets all parameters to be inserted into the violation message. Overrides ConstraintViolationBuilderInterface::setParameters
ConstraintViolationBuilder::setPlural public function Sets the number which determines how the plural form of the violation message is chosen when it is translated. Overrides ConstraintViolationBuilderInterface::setPlural
ConstraintViolationBuilder::setTranslationDomain public function Sets the translation domain which should be used for translating the violation message. Overrides ConstraintViolationBuilderInterface::setTranslationDomain
ConstraintViolationBuilder::__construct public function