primo commit
This commit is contained in:
147
libraries/vendor/symfony/validator/Violation/ConstraintViolationBuilder.php
vendored
Normal file
147
libraries/vendor/symfony/validator/Violation/ConstraintViolationBuilder.php
vendored
Normal file
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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 <bschussek@gmail.com>
|
||||
*
|
||||
* @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
|
||||
));
|
||||
}
|
||||
}
|
||||
116
libraries/vendor/symfony/validator/Violation/ConstraintViolationBuilderInterface.php
vendored
Normal file
116
libraries/vendor/symfony/validator/Violation/ConstraintViolationBuilderInterface.php
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Violation;
|
||||
|
||||
/**
|
||||
* Builds {@link \Symfony\Component\Validator\ConstraintViolationInterface}
|
||||
* objects.
|
||||
*
|
||||
* Use the various methods on this interface to configure the built violation.
|
||||
* Finally, call {@link addViolation()} to add the violation to the current
|
||||
* execution context.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @method $this disableTranslation()
|
||||
*/
|
||||
interface ConstraintViolationBuilderInterface
|
||||
{
|
||||
/**
|
||||
* Stores the property path at which the violation should be generated.
|
||||
*
|
||||
* The passed path will be appended to the current property path of the
|
||||
* execution context.
|
||||
*
|
||||
* @param string $path The property path
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function atPath(string $path): static;
|
||||
|
||||
/**
|
||||
* Sets a parameter to be inserted into the violation message.
|
||||
*
|
||||
* @param string $key The name of the parameter
|
||||
* @param string $value The value to be inserted in the parameter's place
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParameter(string $key, string $value): static;
|
||||
|
||||
/**
|
||||
* Sets all parameters to be inserted into the violation message.
|
||||
*
|
||||
* @param array $parameters An array with the parameter names as keys and
|
||||
* the values to be inserted in their place as
|
||||
* values
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParameters(array $parameters): static;
|
||||
|
||||
/**
|
||||
* Sets the translation domain which should be used for translating the
|
||||
* violation message.
|
||||
*
|
||||
* @param string $translationDomain The translation domain
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see \Symfony\Contracts\Translation\TranslatorInterface
|
||||
*/
|
||||
public function setTranslationDomain(string $translationDomain): static;
|
||||
|
||||
/**
|
||||
* Sets the invalid value that caused this violation.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setInvalidValue(mixed $invalidValue): static;
|
||||
|
||||
/**
|
||||
* Sets the number which determines how the plural form of the violation
|
||||
* message is chosen when it is translated.
|
||||
*
|
||||
* @param int $number The number for determining the plural form
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see \Symfony\Contracts\Translation\TranslatorInterface::trans()
|
||||
*/
|
||||
public function setPlural(int $number): static;
|
||||
|
||||
/**
|
||||
* Sets the violation code.
|
||||
*
|
||||
* @param string|null $code The violation code
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCode(?string $code): static;
|
||||
|
||||
/**
|
||||
* Sets the cause of the violation.
|
||||
*
|
||||
* @param mixed $cause The cause of the violation
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCause(mixed $cause): static;
|
||||
|
||||
/**
|
||||
* Adds the violation to the current execution context.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addViolation();
|
||||
}
|
||||
Reference in New Issue
Block a user