- md5
- 02e85668b95ec0155239b47bd376a189
- sha1
- bc281ad7d3667921665a27c5e9cbb49294dabd12
- sha256
- ad95805cf8931b106f5202008923a8c3e11387375bbe63b65a9838c63d3ab9ee
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator\Violation;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Util\PropertyPath;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Default implementation of {@link ConstraintViolationBuilderInterface}.
*
* @author Bernhard Schussek <[email protected]>
*
* @internal since version 2.5. Code against ConstraintViolationBuilderInterface instead.
*/
class ConstraintViolationBuilder implements ConstraintViolationBuilderInterface
{
private ConstraintViolationList $violations;
private string|\Stringable $message;
private array $parameters;
private mixed $root;
private mixed $invalidValue;
private string $propertyPath;
private TranslatorInterface $translator;
private string|false|null $translationDomain;
private ?int $plural = null;
private ?Constraint $constraint;
private ?string $code = null;
private mixed $cause = null;
public function __construct(ConstraintViolationList $violations, ?Constraint $constraint, string|\Stringable $message, array $parameters, mixed $root, ?string $propertyPath, mixed $invalidValue, TranslatorInterface $translator, string|false|null $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;
}
public function atPath(string $path): static
{
$this->propertyPath = PropertyPath::append($this->propertyPath, $path);
return $this;
}
public function setParameter(string $key, string $value): static
{
$this->parameters[$key] = $value;
return $this;
}
public function setParameters(array $parameters): static
{
$this->parameters = $parameters;
return $this;
}
public function setTranslationDomain(string $translationDomain): static
{
$this->translationDomain = $translationDomain;
return $this;
}
/**
* @return $this
*/
public function disableTranslation(): static
{
$this->translationDomain = false;
return $this;
}
public function setInvalidValue(mixed $invalidValue): static
{
$this->invalidValue = $invalidValue;
return $this;
}
public function setPlural(int $number): static
{
$this->plural = $number;
return $this;
}
public function setCode(?string $code): static
{
$this->code = $code;
return $this;
}
public function setCause(mixed $cause): static
{
$this->cause = $cause;
return $this;
}
public function addViolation(): void
{
$parameters = null === $this->plural ? $this->parameters : (['%count%' => $this->plural] + $this->parameters);
if (false === $this->translationDomain) {
$translatedMessage = strtr($this->message, $parameters);
} else {
$translatedMessage = $this->translator->trans(
$this->message,
$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
));
}
}
The same content is in 136 releases, Joomla 5.1.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.