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

Skip to content

Commit 9461461

Browse files
[FrameworkBundle][Validator] Add framework.validation.disable_translation config
1 parent 9b0ca99 commit 9461461

File tree

8 files changed

+27
-3
lines changed

8 files changed

+27
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CHANGELOG
2121
* Add support f 8000 or configuring multiple serializer instances via the configuration
2222
* Add support for `SYMFONY_TRUSTED_PROXIES`, `SYMFONY_TRUSTED_HEADERS`, `SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER` and `SYMFONY_TRUSTED_HOSTS` env vars
2323
* Add `--no-fill` option to `translation:extract` command
24+
* Add `framework.validation.disable_translation` option
2425

2526
7.1
2627
---

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

+3
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,9 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
10401040
->end()
10411041
->end()
10421042
->end()
1043+
->booleanNode('disable_translation')
1044+
->defaultFalse()
1045+
->end()
10431046
->arrayNode('auto_mapping')
10441047
->info('A collection of namespaces for which auto-mapping will be enabled by default, or null to opt-in with the EnableAutoMapping constraint.')
10451048
->example([

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

+4
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,10 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
16591659
$validatorBuilder->addMethodCall('setMappingCache', [new Reference('validator.mapping.cache.adapter')]);
16601660
}
16611661

1662+
if ($config['disable_translation'] ?? false) {
1663+
$validatorBuilder->addMethodCall('disableTranslation');
1664+
}
1665+
16621666
$container->setParameter('validator.auto_mapping', $config['auto_mapping']);
16631667
if (!$propertyInfoEnabled || !class_exists(PropertyInfoLoader::class)) {
16641668
$container->removeDefinition('validator.property_info_loader');

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

+1
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ protected static function getBundleDefaultConfig()
768768
'enable_attributes' => !class_exists(FullStack::class),
769769
'static_method' => ['loadValidatorMetadata'],
770770
'translation_domain' => 'validators',
771+
'disable_translation' => false,
771772
'mapping' => [
772773
'paths' => [],
773774
],

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function __construct(
107107
private ValidatorInterface $validator,
108108
private mixed $root,
109109
private TranslatorInterface $translator,
110-
private ?string $translationDomain = null,
110+
private string|false|null $translationDomain = null,
111111
) {
112112
$this->violations = new ConstraintViolationList();
113113
$this->cachedObjectsRefs = new \SplObjectStorage();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ExecutionContextFactory implements ExecutionContextFactoryInterface
2525
{
2626
public function __construct(
2727
private TranslatorInterface $translator,
28-
private ?string $translationDomain = null,
28+
private string|false|null $translationDomain = null,
2929
) {
3030
}
3131

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

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public function testSetTranslationDomain()
9999
$this->assertSame($this->builder, $this->builder->setTranslationDomain('TRANS_DOMAIN'));
100100
}
101101

102+
public function testDisableTranslation()
103+
{
104+
$this->assertSame($this->builder, $this->builder->disableTranslation());
105+
}
106+
102107
public function testGetValidator()
103108
{
104109
$this->assertInstanceOf(RecursiveValidator::class, $this->builder->getValidator());

src/Symfony/Component/Validator/ValidatorBuilder.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ValidatorBuilder
5050
private ?ContainerInterface $groupProviderLocator = null;
5151
private ?CacheItemPoolInterface $mappingCache = null;
5252
private ?TranslatorInterface $translator = null;
53-
private ?string $translationDomain = null;
53+
private string|false|null $translationDomain = null;
5454

5555
/**
5656
* Adds an object initializer to the validator.
@@ -292,6 +292,16 @@ public function setTranslationDomain(?string $translationDomain): static
292292
return $this;
293293
}
294294

295+
/**
296+
* @return $this
297+
*/
298+
public function disableTranslation(): static
299+
{
300+
$this->translationDomain = false;
301+
302+
return $this;
303+
}
304+
295305
/**
296306
* @return $this
297307
*/

0 commit comments

Comments
 (0)
0