Skip to content

Commit 5e45191

Browse files
Merge branch '6.4' into 7.0
* 6.4: (32 commits) [Validator] Fix registering "is_valid()" for `#[Expression]` [Scheduler] Trigger unique messages at runtime [Scheduler] Fix CHANGELOG [Clock] Add `DatePoint`: an immutable DateTime implementation with stricter error handling and return types [Scheduler] Allow modifying the schedule at runtime and recalculate heap [Cache] Fix Redis6Proxy [Finder] Disable failing test about open_basedir Fix merge Fix merge Minor CS fixes Deprecate `Kernel::stripComments()` Remove setAccessible reflection call in tests [Notifier] Telegram Bridge add escaping for \ [Component][AssertMapper] add type hint of an argument in asset mapper command [Translation] [Phrase] Refacto ReadConfig and WriteConfig into arrays [Routing] Fix routing collection defaults when adding a new route to a collection [Messenger] Fix cloned TraceableStack not unstacking the stack independently [Translation] Add `--as-tree` option to `translation:pull` command [Mime] Allow to add some headers as a strings [Translation] Give current locale to locale switcher runWithLocale callback ...
2 parents 7eebfcc + 5a5222d commit 5e45191

File tree

8 files changed

+50
-36
lines changed

8 files changed

+50
-36
lines changed

Command/DebugCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ private function getPropertyData(ClassMetadataInterface $classMetadata, string $
165165
foreach ($propertyMetadata as $metadata) {
166166
$autoMapingStrategy = 'Not supported';
167167
if ($metadata instanceof GenericMetadata) {
168-
switch ($metadata->getAutoMappingStrategy()) {
169-
case AutoMappingStrategy::ENABLED: $autoMapingStrategy = 'Enabled'; break;
170-
case AutoMappingStrategy::DISABLED: $autoMapingStrategy = 'Disabled'; break;
171-
case AutoMappingStrategy::NONE: $autoMapingStrategy = 'None'; break;
172-
}
168+
$autoMapingStrategy = match ($metadata->getAutoMappingStrategy()) {
169+
AutoMappingStrategy::ENABLED => 'Enabled',
170+
AutoMappingStrategy::DISABLED => 'Disabled',
171+
AutoMappingStrategy::NONE => 'None',
172+
};
173173
}
174174
$traversalStrategy = 'None';
175175
if (TraversalStrategy::TRAVERSE === $metadata->getTraversalStrategy()) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Constraints;
13+
14+
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
15+
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
16+
17+
class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
18+
{
19+
public function getFunctions(): array
20+
{
21+
return [
22+
new ExpressionFunction('is_valid', function (...$arguments) {
23+
return sprintf(
24+
'0 === $context->getValidator()->inContext($context)->validate(%s)->getViolations()->count()',
25+
implode(', ', $arguments)
26+
);
27+
}, function (array $variables, ...$arguments): bool {
28+
return 0 === $variables['context']->getValidator()->inContext($variables['context'])->validate(...$arguments)->getViolations()->count();
29+
}),
30+
];
31+
}
32+
}

Constraints/ExpressionValidator.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14-
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
15-
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
1614
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1715
use Symfony\Component\Validator\Constraint;
1816
use Symfony\Component\Validator\ConstraintValidator;
@@ -22,15 +20,14 @@
2220
* @author Fabien Potencier <[email protected]>
2321
* @author Bernhard Schussek <[email protected]>
2422
*/
25-
class ExpressionValidator extends ConstraintValidator implements ExpressionFunctionProviderInterface
23+
class ExpressionValidator extends ConstraintValidator
2624
{
2725
private ExpressionLanguage $expressionLanguage;
2826

2927
public function __construct(ExpressionLanguage $expressionLanguage = null)
3028
{
3129
if ($expressionLanguage) {
32-
$this->expressionLanguage = clone $expressionLanguage;
33-
$this->expressionLanguage->registerProvider($this);
30+
$this->expressionLanguage = $expressionLanguage;
3431
}
3532
}
3633

@@ -53,25 +50,11 @@ public function validate(mixed $value, Constraint $constraint): void
5350
}
5451
}
5552

56-
public function getFunctions(): array
57-
{
58-
return [
59-
new ExpressionFunction('is_valid', function (...$arguments) {
60-
return sprintf(
61-
'0 === $context->getValidator()->inContext($context)->validate(%s)->getViolations()->count()',
62-
implode(', ', $arguments)
63-
);
64-
}, function (array $variables, ...$arguments): bool {
65-
return 0 === $variables['context']->getValidator()->inContext($variables['context'])->validate(...$arguments)->getViolations()->count();
66-
}),
67-
];
68-
}
69-
7053
private function getExpressionLanguage(): ExpressionLanguage
7154
{
7255
if (!isset($this->expressionLanguage)) {
7356
$this->expressionLanguage = new ExpressionLanguage();
74-
$this->expressionLanguage->registerProvider($this);
57+
$this->expressionLanguage->registerProvider(new ExpressionLanguageProvider());
7558
}
7659

7760
return $this->expressionLanguage;

Tests/Constraints/ExpressionValidatorTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1515
use Symfony\Component\Validator\Constraints\Expression;
16+
use Symfony\Component\Validator\Constraints\ExpressionLanguageProvider;
1617
use Symfony\Component\Validator\Constraints\ExpressionValidator;
1718
use Symfony\Component\Validator\Constraints\NotNull;
1819
use Symfony\Component\Validator\Constraints\Range;
@@ -359,10 +360,8 @@ public function testIsValidExpressionInvalid()
359360
*/
360361
public function testCompileIsValid(string $expression, array $names, string $expected)
361362
{
362-
$provider = new ExpressionValidator();
363-
364363
$expressionLanguage = new ExpressionLanguage();
365-
$expressionLanguage->registerProvider($provider);
364+
$expressionLanguage->registerProvider(new ExpressionLanguageProvider());
366365

367366
$result = $expressionLanguage->compile($expression, $names);
368367

Tests/Mapping/Loader/YamlFileLoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
use Symfony\Component\Validator\Constraints\Range;
2222
use Symfony\Component\Validator\Mapping\ClassMetadata;
2323
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
24-
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity;
25-
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\GroupSequenceProviderEntity;
2624
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
2725
use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
2826
use Symfony\Component\Validator\Tests\Fixtures\ConstraintWithRequiredArgument;
2927
use Symfony\Component\Validator\Tests\Fixtures\Entity_81;
28+
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity;
29+
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\GroupSequenceProviderEntity;
3030

3131
class YamlFileLoaderTest extends TestCase
3232
{

Tests/Mapping/MemberMetadataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
use Symfony\Component\Validator\Constraints\Valid;
1919
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
2020
use Symfony\Component\Validator\Mapping\MemberMetadata;
21-
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity;
2221
use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint;
2322
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
2423
use Symfony\Component\Validator\Tests\Fixtures\ConstraintB;
24+
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity;
2525
use Symfony\Component\Validator\Tests\Fixtures\PropertyConstraint;
2626

2727
class MemberMetadataTest extends TestCase

Tests/Mapping/PropertyMetadataTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Validator\Exception\ValidatorException;
1616
use Symfony\Component\Validator\Mapping\PropertyMetadata;
17-
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity;
18-
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\EntityParent;
1917
use Symfony\Component\Validator\Tests\Fixtures\Entity_74;
2018
use Symfony\Component\Validator\Tests\Fixtures\Entity_74_Proxy;
19+
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity;
20+
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\EntityParent;
2121

2222
class PropertyMetadataTest extends TestCase
2323
{

Tests/Validator/RecursiveValidatorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
use Symfony\Component\Validator\ObjectInitializerInterface;
4545
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildA;
4646
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildB;
47-
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity;
48-
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\EntityParent;
49-
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\GroupSequenceProviderEntity;
5047
use Symfony\Component\Validator\Tests\Fixtures\CascadedChild;
5148
use Symfony\Component\Validator\Tests\Fixtures\CascadingEntity;
5249
use Symfony\Component\Validator\Tests\Fixtures\EntityWithGroupedConstraintOnMethods;
5350
use Symfony\Component\Validator\Tests\Fixtures\FailingConstraint;
5451
use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory;
52+
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\Entity;
53+
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\EntityParent;
54+
use Symfony\Component\Validator\Tests\Fixtures\NestedAttribute\GroupSequenceProviderEntity;
5555
use Symfony\Component\Validator\Tests\Fixtures\Reference;
5656
use Symfony\Component\Validator\Validator\ContextualValidatorInterface;
5757
use Symfony\Component\Validator\Validator\LazyProperty;

0 commit comments

Comments
 (0)