@@ -24,6 +24,7 @@ class UploadValidatorExtension extends AbstractTypeExtension
2424{
2525 private $ translator ;
2626 private $ translationDomain ;
27+ private $ errorMessage = 'post_max_size_message ' ;
2728
2829 /**
2930 * @param TranslatorInterface $translator The translator for translating error messages
@@ -40,11 +41,11 @@ public function __construct(TranslatorInterface $translator, $translationDomain
4041 */
4142 public function configureOptions (OptionsResolver $ resolver )
4243 {
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 );
4547
46- $ resolver ->setNormalizer ('post_max_size_message ' , function (Options $ options , $ errorMessage ) use ($ translator , $ translationDomain ) {
47- return $ translator ->trans ($ errorMessage , array (), $ translationDomain );
48+ return $ self ;
4849 });
4950 }
5051
@@ -55,4 +56,19 @@ public function getExtendedType()
5556 {
5657 return 'form ' ;
5758 }
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+ }
5874}
0 commit comments