Skip to content

Commit 79128c3

Browse files
author
Robin Chalas
committed
Merge branch '4.3' into 4.4
* 4.3: [Security\Core] Make SodiumPasswordEncoder validate BCrypt-ed passwords [Validator] Fix TimezoneValidator default option [Messenger] Inject RoutableMessageBus instead of bus locator [DomCrawler] Fix type error with null Form::$currentUri [Contracts] Fixed typos do not enable validator auto mapping by default [HttpClient] remove unused argument
2 parents 8d9d6bc + cef643a commit 79128c3

File tree

6 files changed

+29
-28
lines changed

6 files changed

+29
-28
lines changed

Constraints/Timezone.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Timezone extends Constraint
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function __construct(array $options = null)
46+
public function __construct($options = null)
4747
{
4848
parent::__construct($options);
4949

@@ -58,4 +58,12 @@ public function __construct(array $options = null)
5858
throw new ConstraintDefinitionException('The option "intlCompatible" can only be used when the PHP intl extension is available.');
5959
}
6060
}
61+
62+
/**
63+
* {@inheritdoc}
64+
*/
65+
public function getDefaultOption()
66+
{
67+
return 'zone';
68+
}
6169
}

Constraints/TimezoneValidator.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,6 @@ public function validate($value, Constraint $constraint)
7575
->addViolation();
7676
}
7777

78-
/**
79-
* {@inheritdoc}
80-
*/
81-
public function getDefaultOption()
82-
{
83-
return 'zone';
84-
}
85-
86-
/**
87-
* {@inheritdoc}
88-
*/
89-
protected function formatValue($value, $format = 0)
90-
{
91-
$value = parent::formatValue($value, $format);
92-
93-
if (!$value || \DateTimeZone::PER_COUNTRY === $value) {
94-
return $value;
95-
}
96-
97-
return array_search($value, (new \ReflectionClass(\DateTimeZone::class))->getConstants(), true) ?: $value;
98-
}
99-
10078
private static function getPhpTimezones(int $zone, string $countryCode = null): array
10179
{
10280
if (null !== $countryCode) {

DependencyInjection/AddAutoMappingConfigurationPass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ public function process(ContainerBuilder $container)
7070
/**
7171
* Builds a regexp to check if a class is auto-mapped.
7272
*/
73-
private function getRegexp(array $patterns): string
73+
private function getRegexp(array $patterns): ?string
7474
{
75+
if (!$patterns) {
76+
return null;
77+
}
78+
7579
$regexps = [];
7680
foreach ($patterns as $pattern) {
7781
// Escape namespace

Tests/Constraints/TimezoneTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testValidTimezoneConstraints()
2323
{
2424
new Timezone();
2525
new Timezone(['zone' => \DateTimeZone::ALL]);
26-
new Timezone(['zone' => \DateTimeZone::ALL_WITH_BC]);
26+
new Timezone(\DateTimeZone::ALL_WITH_BC);
2727
new Timezone([
2828
'zone' => \DateTimeZone::PER_COUNTRY,
2929
'countryCode' => 'AR',

Tests/Constraints/TimezoneValidatorTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,7 @@ public function testGroupedTimezonesWithInvalidCountry()
267267
*/
268268
public function testDeprecatedTimezonesAreValidWithBC(string $timezone)
269269
{
270-
$constraint = new Timezone([
271-
'zone' => \DateTimeZone::ALL_WITH_BC,
272-
]);
270+
$constraint = new Timezone(\DateTimeZone::ALL_WITH_BC);
273271

274272
$this->validator->validate($timezone, $constraint);
275273

Tests/DependencyInjection/AddAutoMappingConfigurationPassTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,17 @@ public function mappingProvider(): array
7070
['Symfony\Component\Validator\Tests\Fixtures\\**', ['trailing_double_star'], '{^App\\\\|^Symfony\\\\Component\\\\Validator\\\\Tests\\\\Fixtures\\\\.*?$}'],
7171
];
7272
}
73+
74+
public function testDoNotMapAllClassesWhenConfigIsEmpty()
75+
{
76+
$container = new ContainerBuilder();
77+
$container->setParameter('validator.auto_mapping', []);
78+
79+
$container->register('validator.builder', ValidatorBuilder::class);
80+
$container->register('loader')->addTag('validator.auto_mapper');
81+
82+
(new AddAutoMappingConfigurationPass())->process($container);
83+
84+
$this->assertNull($container->getDefinition('loader')->getArgument('$classValidatorRegexp'));
85+
}
7386
}

0 commit comments

Comments
 (0)