@@ -24,6 +24,7 @@ class UploadValidatorExtension extends AbstractTypeExtension
24
24
{
25
25
private $ translator ;
26
26
private $ translationDomain ;
27
+ private $ errorMessage = 'post_max_size_message ' ;
27
28
28
29
/**
29
30
* @param TranslatorInterface $translator The translator for translating error messages
@@ -40,11 +41,11 @@ public function __construct(TranslatorInterface $translator, $translationDomain
40
41
*/
41
42
public function configureOptions (OptionsResolver $ resolver )
42
43
{
43
- $ translator = $ this ->translator ;
44
- $ translationDomain = $ this ->translationDomain ;
44
+ $ self = $ this ;
45
+ $ resolver ->setNormalizer ('post_max_size_message ' , function (Options $ options , $ errorMessage ) use ($ self ) {
46
+ $ self ->setErrorMessage ($ errorMessage );
45
47
46
- $ resolver ->setNormalizer ('post_max_size_message ' , function (Options $ options , $ errorMessage ) use ($ translator , $ translationDomain ) {
47
- return $ translator ->trans ($ errorMessage , array (), $ translationDomain );
48
+ return $ self ;
48
49
});
49
50
}
50
51
@@ -55,4 +56,19 @@ public function getExtendedType()
55
56
{
56
57
return 'form ' ;
57
58
}
59
+
60
+ public function __toString ()
61
+ {
62
+ return $ this ->translator ->trans ($ this ->errorMessage , array (), $ this ->translationDomain );
63
+ }
64
+
65
+ /**
66
+ * This method is public because it needs to be callable from a closure in PHP 5.3.
67
+ *
68
+ * @internal
69
+ */
70
+ public function setErrorMessage ($ errorMessage )
71
+ {
72
+ $ this ->errorMessage = $ errorMessage ;
73
+ }
58
74
}
0 commit comments