Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d4ccef2

Browse files
[FrameworkBundle][Validator] Add framework.validation.disable_translation config
1 parent 2cb470e commit d4ccef2

File tree

8 files changed

+27
-3
lines changed

8 files changed

+27
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Derivate `kernel.secret` from the decryption secret when its env var is not defined
99
* Make the `config/` directory optional in `MicroKernelTrait`, add support for service arguments in the
1010
invokable Kernel class, and register `FrameworkBundle` by default when the `bundles.php` file is missing
11+
* Add `framework.validation.disable_translation` option
1112

1213
7.1
1314
---

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,9 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
10311031
->end()
10321032
->end()
10331033
->end()
1034+
->booleanNode('disable_translation')
1035+
->defaultFalse()
1036+
->end()
10341037
->arrayNode('auto_mapping')
10351038
->info('A collection of namespaces for which auto-mapping will be enabled by default, or null to opt-in with the EnableAutoMapping constraint.')
10361039
->example([

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,10 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
16541654
$validatorBuilder->addMethodCall('setMappingCache', [new Reference('validator.mapping.cache.adapter')]);
16551655
}
16561656

1657+
if (\array_key_exists('disable_translation', $config) && $config['disable_translation']) {
1658+
$validatorBuilder->addMethodCall('disableTranslation');
1659+
}
1660+
16571661
$container->setParameter('validator.auto_mapping', $config['auto_mapping']);
16581662
if (!$propertyInfoEnabled || !class_exists(PropertyInfoLoader::class)) {
16591663
$container->removeDefinition('validator.property_info_loader');

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ protected static function getBundleDefaultConfig()
674674
'enable_attributes' => !class_exists(FullStack::class),
675675
'static_method' => ['loadValidatorMetadata'],
676676
'translation_domain' => 'validators',
677+
'disable_translation' => false,
677678
'mapping' => [
678679
'paths' => [],
679680
],

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 11 additions & 1 deletion
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)