8000 [FrameworkBundle][Validator] Add `framework.validation.disable_transl… · symfony/symfony@15c853a · GitHub
[go: up one dir, main page]

Skip to content

Commit 15c853a

Browse files
[FrameworkBundle][Validator] Add framework.validation.disable_translation config
1 parent 65fa483 commit 15c853a

File tree

8 files changed

+36
-5
lines changed

8 files changed

+36
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Add `framework.validation.disable_translation` option
8+
49
6.3
510
---
611

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

+3
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,9 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
10211021
->end()
10221022
->end()
10231023
->end()
1024+
->booleanNode('disable_translation')
1025+
->defaultFalse()
1026+
->end()
10241027
->arrayNode('auto_mapping')
10251028
->info('A collection of namespaces for which auto-mapping will be enabled by default, or null to opt-in with the EnableAutoMapping constraint.')
10261029
->example([

src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.php

+7
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,11 @@
119119
])
120120
->tag('validator.auto_mapper')
121121
;
122+
123+
if (param('validator.disable_translation') === true) {
124+
$container->services()
125+
->get('validator.builder')
126+
->call('disableTranslation')
127+
;
128+
}
122129
};

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ protected static function getBundleDefaultConfig()
547547
'enable_annotations' => !class_exists(FullStack::class),
548548
'static_method' => ['loadValidatorMetadata'],
549549
'translation_domain' => 'validators',
550+
'disable_translation' => false,
550551
'mapping' => [
551552
'paths' => [],
552553
],

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ExecutionContext implements ExecutionContextInterface
4545
private mixed $root;
4646

4747
private TranslatorInterface $translator;
48-
private ?string $translationDomain;
48+
private string|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-
public function __construct(ValidatorInterface $validator, mixed $root, TranslatorInterface $translator, string $translationDomain = null)
114+
public function __construct(ValidatorInterface $validator, mixed $root, TranslatorInterface $translator, string|false $translationDomain = null)
115115
{
116116
$this->validator = $validator;
117117
$this->root = $root;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
class ExecutionContextFactory implements ExecutionContextFactoryInterface
2525
{
2626
private TranslatorInterface $translator;
27-
private ?string $translationDomain;
27+
private string|false|null $translationDomain;
2828

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

src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public function testSetTranslationDomain()
140140
$this->assertSame($this->builder, $this->builder->setTranslationDomain('TRANS_DOMAIN'));
141141
}
142142

143+
public function testDisableTranslation()
144+
{
145+
$this->assertSame($this->builder, $this->builder->disableTranslation());
146+
}
147+
143148
public function testGetValidator()
144149
{
145150
$this->assertInstanceOf(RecursiveValidator::class, $this->builder->getValidator());

src/Symfony/Component/Validator/ValidatorBuilder.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ValidatorBuilder
5454
private ConstraintValidatorFactoryInterface $validatorFactory;
5555
private ?CacheItemPoolInterface $mappingCache = null;
5656
private ?TranslatorInterface $translator = null;
57-
private ?string $translationDomain = null;
57+
private string|false|null $translationDomain = null;
5858

5959
/**
6060
* Adds an object initializer to the validator.
@@ -307,6 +307,16 @@ public function setTranslationDomain(?string $translationDomain): static
307307
return $this;
308308
}
309309

310+
/**
311+
* @return $this
312+
*/
313+
public function disableTranslation(): static
314+
{
315+
$this->translationDomain = false;
316+
317+
return $this;
318+
}
319+
310320
/**
311321
* @return $this
312322
*/

0 commit comments

Comments
 (0)
0