File tree Expand file tree Collapse file tree 7 files changed +30
-94
lines changed
src/Symfony/Component/Translation Expand file tree Collapse file tree 7 files changed +30
-94
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ CHANGELOG
4
4
6.2
5
5
---
6
6
7
- * Deprecate ` PhpExtractor ` in favor of ` PhpAstExtractor `
8
- * Add ` PhpAstExtractor ` (which require [ nikic/php-parser] ( https://github.com/nikic/php-parser ) to be installed)
7
+ * Deprecate ` PhpExtractor ` in favor of ` PhpAstExtractor `
8
+ * Add ` PhpAstExtractor ` (requires [ nikic/php-parser] ( https://github.com/nikic/php-parser ) to be installed)
9
9
10
10
6.1
11
11
---
Original file line number Diff line number Diff line change @@ -70,5 +70,16 @@ public function process(ContainerBuilder $container)
70
70
$ definition ->replaceArgument (7 , $ paths );
71
71
}
72
72
}
73
+
74
+ if ($ container ->hasDefinition ('validator ' ) && $ container ->hasDefinition ('translation.extractor.visitor.constraint ' )) {
75
+ $ definition = $ container ->findDefinition ('translation.extractor.visitor.constraint ' );
76
+ $ constraintClassNames = [];
77
+
78
+ foreach (array_keys ($ container ->findTaggedServiceIds ('validator.constraint_validator ' , true )) as $ serviceId ) {
79
+ $ constraintClassNames [] = str_replace ('Validator ' , '' , $ serviceId );
80
+ }
81
+
82
+ $ definition ->setArgument (0 , $ constraintClassNames );
83
+ }
73
84
}
74
85
}
Original file line number Diff line number Diff line change 20
20
* PhpExtractor extracts translation messages from a PHP template.
21
21
*
22
22
* @author Michel Salib <[email protected] >
23
+ * @deprecated since Symfony 6.2, use the PhpAstExtractor instead
23
24
*/
24
25
class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
25
26
{
Original file line number Diff line number Diff line change 17
17
/**
18
18
* @author Mathieu Santostefano <[email protected] >
19
19
*/
20
- abstract class AbstractVisitor implements Visitor
20
+ abstract class AbstractVisitor
21
21
{
22
22
protected MessageCatalogue $ catalogue ;
23
23
protected \SplFileInfo $ file ;
Original file line number Diff line number Diff line change 21
21
*/
22
22
final class ConstraintVisitor extends AbstractVisitor implements NodeVisitor
23
23
{
24
- public const CONSTRAINT_CLASS_NAMES = [
25
- 'AbstractComparison ' ,
26
- 'All ' ,
27
- 'Bic ' ,
28
- 'Blank ' ,
29
- 'Callback ' ,
30
- 'CardScheme ' ,
31
- 'Choice ' ,
32
- 'Collection ' ,
33
- 'Composite ' ,
34
- 'Count ' ,
35
- 'Country ' ,
36
- 'Currency ' ,
37
- 'Date ' ,
38
- 'DateTime ' ,
39
- 'DisableAutoMapping ' ,
40
- 'DivisibleBy ' ,
41
- 'Email ' ,
42
- 'EnableAutoMapping ' ,
43
- 'EqualTo ' ,
44
- 'Existence ' ,
45
- 'Expression ' ,
46
- 'File ' ,
47
- 'GreaterThan ' ,
48
- 'GreaterThanOrEqual ' ,
49
- 'GroupSequence ' ,
50
- 'GroupSequenceProvider ' ,
51
- 'Iban ' ,
52
- 'IdenticalTo ' ,
53
- 'Image ' ,
54
- 'Ip ' ,
55
- 'Isbn ' ,
56
- 'IsFalse ' ,
57
- 'IsNull ' ,
58
- 'Issn ' ,
59
- 'IsTrue ' ,
60
- 'Json ' ,
61
- 'Language ' ,
62
- 'Length ' ,
63
- 'LessThan ' ,
64
- 'LessThanOrEqual ' ,
65
- 'Locale ' ,
66
- 'Luhn ' ,
67
- 'Negative ' ,
68
- 'NegativeOrZero ' ,
69
- 'NotBlank ' ,
70
- 'NotCompromisedPassword ' ,
71
- 'NotEqualTo ' ,
72
- 'NotIdenticalTo ' ,
73
- 'NotNull ' ,
74
- 'NumberConstraintTrait ' ,
75
- 'Optional ' ,
76
- 'Positive ' ,
77
- 'PositiveOrZero ' ,
78
- 'Range ' ,
79
- 'Regex ' ,
80
- 'Required ' ,
81
- 'Time ' ,
82
- 'Timezone ' ,
83
- 'Traverse ' ,
84
- 'Type ' ,
85
- 'Unique ' ,
86
- 'Url ' ,
87
- 'Uuid ' ,
88
- 'Valid ' ,
89
- ];
24
+ public function __construct (
25
+ private readonly array $ constraintClassNames = []
26
+ ) {
27
+ }
90
28
91
29
public function beforeTraverse (array $ nodes ): ?Node
92
30
{
@@ -108,7 +46,7 @@ public function enterNode(Node $node): ?Node
108
46
$ isConstraintClass = false ;
109
47
110
48
foreach ($ parts as $ part ) {
111
- if (\in_array ($ part , self :: CONSTRAINT_CLASS_NAMES , true )) {
49
+ if (\in_array ($ part , $ this -> constraintClassNames , true )) {
112
50
$ isConstraintClass = true ;
113
51
114
52
break ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -28,7 +28,11 @@ public function testExtraction(iterable|string $resource)
28
28
$ extractor = new PhpAstExtractor ([
29
29
new TransMethodVisitor (),
30
30
new TranslatableMessageVisitor (),
31
- new ConstraintVisitor (),
31
+ new ConstraintVisitor ([
32
+ 'NotBlank ' ,
33
+ 'Isbn ' ,
34
+ 'Length ' ,
35
+ ]),
32
36
]);
33
37
$ extractor ->setPrefix ('prefix ' );
34
38
$ catalogue = new MessageCatalogue ('en ' );
@@ -150,7 +154,11 @@ public function testExtractionFromIndentedHeredocNowdoc()
150
154
$ extractor = new PhpAstExtractor ([
151
155
new TransMethodVisitor (),
152
156
new TranslatableMessageVisitor (),
153
- new ConstraintVisitor (),
157
+ new ConstraintVisitor ([
158
+ 'NotBlank ' ,
159
+ 'Isbn ' ,
160
+ 'Length ' ,
161
+ ]),
154
162
]);
155
163
$ extractor ->setPrefix ('prefix ' );
156
164
$ extractor ->extract (__DIR__ .'/../fixtures/extractor-7.3/translation.html.php ' , $ catalogue );
You can’t perform that action at this time.
0 commit comments