Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita554b34

Browse files
Allow to use translation_domain false for validators
1 parente411712 commita554b34

6 files changed

+26
-20
lines changed

‎src/Symfony/Component/Validator/Context/ExecutionContext.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ExecutionContext implements ExecutionContextInterface
4545
privatemixed$root;
4646

4747
privateTranslatorInterface$translator;
48-
private?string$translationDomain;
48+
privatestring|false|null$translationDomain;
4949

5050
/**
5151
* The violations generated in the current context.
@@ -111,7 +111,7 @@ class ExecutionContext implements ExecutionContextInterface
111111
/**
112112
* @internal Called by {@link ExecutionContextFactory}. Should not be used in user code.
113113
*/
114-
publicfunction__construct(ValidatorInterface$validator,mixed$root,TranslatorInterface$translator,string$translationDomain =null)
114+
publicfunction__construct(ValidatorInterface$validator,mixed$root,TranslatorInterface$translator,string|false|null$translationDomain =null)
115115
{
116116
$this->validator =$validator;
117117
$this->root =$root;
@@ -139,10 +139,12 @@ public function setConstraint(Constraint $constraint)
139139
$this->constraint =$constraint;
140140
}
141141

142-
publicfunctionaddViolation(string$message,array$parameters = [])
142+
publicfunctionaddViolation(string$message,array$parameters = [],string|false|null$translationDomain =null)
143143
{
144144
$this->violations->add(newConstraintViolation(
145-
$this->translator->trans($message,$parameters,$this->translationDomain),
145+
false ===$translationDomain
146+
?$message
147+
:$this->translator->trans($message,$parameters,$translationDomain ??$this->translationDomain),
146148
$message,
147149
$parameters,
148150
$this->root,
@@ -154,7 +156,7 @@ public function addViolation(string $message, array $parameters = [])
154156
));
155157
}
156158

157-
publicfunctionbuildViolation(string$message,array$parameters = []):ConstraintViolationBuilderInterface
159+
publicfunctionbuildViolation(string$message,array$parameters = [],string|false|null$translationDomain =null):ConstraintViolationBuilderInterface
158160
{
159161
returnnewConstraintViolationBuilder(
160162
$this->violations,
@@ -165,7 +167,7 @@ public function buildViolation(string $message, array $parameters = []): Constra
165167
$this->propertyPath,
166168
$this->getValue(),
167169
$this->translator,
168-
$this->translationDomain
170+
$translationDomain ??$this->translationDomain
169171
);
170172
}
171173

‎src/Symfony/Component/Validator/Context/ExecutionContextFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
class ExecutionContextFactoryimplements ExecutionContextFactoryInterface
2525
{
2626
privateTranslatorInterface$translator;
27-
private?string$translationDomain;
27+
privatestring|false|null$translationDomain;
2828

29-
publicfunction__construct(TranslatorInterface$translator,string$translationDomain =null)
29+
publicfunction__construct(TranslatorInterface$translator,string|false|null$translationDomain =null)
3030
{
3131
$this->translator =$translator;
3232
$this->translationDomain =$translationDomain;

‎src/Symfony/Component/Validator/Context/ExecutionContextInterface.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ interface ExecutionContextInterface
6464
/**
6565
* Adds a violation at the current node of the validation graph.
6666
*
67-
* @param string|\Stringable $message The error message as a string or a stringable object
68-
* @param array $params The parameters substituted in the error message
67+
* @param string|\Stringable $message The error message as a string or a stringable object
68+
* @param array $params The parameters substituted in the error message
69+
* @param string|false|null $translationDomain The translation domain of the error message
6970
*/
70-
publicfunctionaddViolation(string$message,array$params = []);
71+
publicfunctionaddViolation(string$message,array$params = []/* , string|false|null $translationDomain */);
7172

7273
/**
7374
* Returns a builder for adding a violation with extended information.
@@ -83,8 +84,9 @@ public function addViolation(string $message, array $params = []);
8384
*
8485
* @param string|\Stringable $message The error message as a string or a stringable object
8586
* @param array $parameters The parameters substituted in the error message
87+
* @param string|false|null $translationDomain The translation domain of the error message
8688
*/
87-
publicfunctionbuildViolation(string$message,array$parameters = []):ConstraintViolationBuilderInterface;
89+
publicfunctionbuildViolation(string$message,array$parameters = []/* , string|false|null $translationDomain */):ConstraintViolationBuilderInterface;
8890

8991
/**
9092
* Returns the validator.

‎src/Symfony/Component/Validator/ValidatorBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ValidatorBuilder
5454
privateConstraintValidatorFactoryInterface$validatorFactory;
5555
private ?CacheItemPoolInterface$mappingCache =null;
5656
private ?TranslatorInterface$translator =null;
57-
private?string$translationDomain =null;
57+
privatestring|false|null$translationDomain =null;
5858

5959
/**
6060
* Adds an object initializer to the validator.
@@ -300,7 +300,7 @@ public function setTranslator(TranslatorInterface $translator): static
300300
*
301301
* @return $this
302302
*/
303-
publicfunctionsetTranslationDomain(?string$translationDomain):static
303+
publicfunctionsetTranslationDomain(string|false|null$translationDomain):static
304304
{
305305
$this->translationDomain =$translationDomain;
306306

‎src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class ConstraintViolationBuilder implements ConstraintViolationBuilderInterface
3333
privatemixed$invalidValue;
3434
privatestring$propertyPath;
3535
privateTranslatorInterface$translator;
36-
private?string$translationDomain;
36+
privatestring|false|null$translationDomain;
3737
private ?int$plural =null;
3838
private ?Constraint$constraint;
3939
private ?string$code =null;
4040
privatemixed$cause =null;
4141

42-
publicfunction__construct(ConstraintViolationList$violations, ?Constraint$constraint,string|\Stringable$message,array$parameters,mixed$root, ?string$propertyPath,mixed$invalidValue,TranslatorInterface$translator,string$translationDomain =null)
42+
publicfunction__construct(ConstraintViolationList$violations, ?Constraint$constraint,string|\Stringable$message,array$parameters,mixed$root, ?string$propertyPath,mixed$invalidValue,TranslatorInterface$translator,string|false$translationDomain =null)
4343
{
4444
$this->violations =$violations;
4545
$this->message =$message;
@@ -73,7 +73,7 @@ public function setParameters(array $parameters): static
7373
return$this;
7474
}
7575

76-
publicfunctionsetTranslationDomain(string$translationDomain):static
76+
publicfunctionsetTranslationDomain(string|false$translationDomain):static
7777
{
7878
$this->translationDomain =$translationDomain;
7979

@@ -110,7 +110,9 @@ public function setCause(mixed $cause): static
110110

111111
publicfunctionaddViolation()
112112
{
113-
if (null ===$this->plural) {
113+
if (false ===$this->translationDomain) {
114+
$translatedMessage =$this->message;
115+
}elseif (null ===$this->plural) {
114116
$translatedMessage =$this->translator->trans(
115117
$this->message,
116118
$this->parameters,

‎src/Symfony/Component/Validator/Violation/ConstraintViolationBuilderInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ public function setParameters(array $parameters): static;
6060
* Sets the translation domain which should be used for translating the
6161
* violation message.
6262
*
63-
* @param string $translationDomain The translation domain
63+
* @param string|false $translationDomain The translation domain
6464
*
6565
* @return $this
6666
*
6767
* @see \Symfony\Contracts\Translation\TranslatorInterface
6868
*/
69-
publicfunctionsetTranslationDomain(string$translationDomain):static;
69+
publicfunctionsetTranslationDomain(string|false$translationDomain):static;
7070

7171
/**
7272
* Sets the invalid value that caused this violation.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp