default services conflit ?

This commit is contained in:
armansansd
2022-04-27 11:30:43 +02:00
parent 28190a5749
commit 8bb1064a3b
8132 changed files with 900138 additions and 426 deletions

View File

@@ -0,0 +1,202 @@
<?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\Translation\TranslatorInterface as LegacyTranslatorInterface;
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 $violations;
private $message;
private $parameters;
private $root;
private $invalidValue;
private $propertyPath;
private $translator;
private $translationDomain;
private $plural;
private $constraint;
private $code;
/**
* @var mixed
*/
private $cause;
/**
* @param string|object $message The error message as a string or a stringable object
* @param TranslatorInterface $translator
*/
public function __construct(ConstraintViolationList $violations, Constraint $constraint, $message, array $parameters, $root, string $propertyPath, $invalidValue, $translator, string $translationDomain = null)
{
if (null === $message) {
@trigger_error(sprintf('Passing a null message when instantiating a "%s" is deprecated since Symfony 4.4.', __CLASS__), \E_USER_DEPRECATED);
$message = '';
}
if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) {
throw new \TypeError(sprintf('Argument 8 passed to "%s()" must be an instance of "%s", "%s" given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
}
$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)
{
if (null !== $code && !\is_string($code)) {
@trigger_error(sprintf('Not using a string as the error code in %s() is deprecated since Symfony 4.4. A type-hint will be added in 5.0.', __METHOD__), \E_USER_DEPRECATED);
}
$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
);
} elseif ($this->translator instanceof TranslatorInterface) {
$translatedMessage = $this->translator->trans(
$this->message,
['%count%' => $this->plural] + $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
));
}
}

View File

@@ -0,0 +1,114 @@
<?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>
*/
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($path);
/**
* 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($key, $value);
/**
* 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);
/**
* 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($translationDomain);
/**
* Sets the invalid value that caused this violation.
*
* @param mixed $invalidValue The invalid value
*
* @return $this
*/
public function setInvalidValue($invalidValue);
/**
* 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::transChoice()
*/
public function setPlural($number);
/**
* Sets the violation code.
*
* @param string|null $code The violation code
*
* @return $this
*/
public function setCode($code);
/**
* Sets the cause of the violation.
*
* @param mixed $cause The cause of the violation
*
* @return $this
*/
public function setCause($cause);
/**
* Adds the violation to the current execution context.
*/
public function addViolation();
}