7
7
use App \Controller \AbstractController ;
8
8
use App \DTO \EntryDto ;
9
9
use App \Entity \Magazine ;
10
+ use App \Exception \ImageDownloadTooLargeException ;
10
11
use App \Exception \PostingRestrictedException ;
11
12
use App \Exception \TagBannedException ;
12
13
use App \PageView \EntryPageView ;
16
17
use App \Service \EntryCommentManager ;
17
18
use App \Service \EntryManager ;
18
19
use App \Service \IpResolver ;
20
+ use App \Service \SettingsManager ;
19
21
use Psr \Log \LoggerInterface ;
20
22
use Symfony \Component \HttpFoundation \Request ;
21
23
use Symfony \Component \HttpFoundation \Response ;
22
24
use Symfony \Component \HttpKernel \Exception \AccessDeniedHttpException ;
23
25
use Symfony \Component \Security \Http \Attribute \IsGranted ;
24
26
use Symfony \Component \Validator \Validator \ValidatorInterface ;
27
+ use Symfony \Contracts \Translation \TranslatorInterface ;
25
28
26
29
class EntryCreateController extends AbstractController
27
30
{
28
31
use EntryTemplateTrait;
29
32
use EntryFormTrait;
30
33
31
34
public function __construct (
35
+ private readonly TranslatorInterface $ translator ,
36
+ private readonly SettingsManager $ settingsManager ,
32
37
private readonly LoggerInterface $ logger ,
33
38
private readonly TagLinkRepository $ tagLinkRepository ,
34
39
private readonly TagRepository $ tagRepository ,
@@ -45,6 +50,7 @@ public function __invoke(?Magazine $magazine, ?string $type, Request $request):
45
50
$ dto = new EntryDto ();
46
51
$ dto ->magazine = $ magazine ;
47
52
$ user = $ this ->getUserOrThrow ();
53
+ $ maxBytes = $ this ->settingsManager ->getMaxImageByteString ();
48
54
49
55
$ form = $ this ->createFormByType ((new EntryPageView (1 ))->resolveType ($ type ), $ dto );
50
56
try {
@@ -85,6 +91,7 @@ public function __invoke(?Magazine $magazine, ?string $type, Request $request):
85
91
'magazine ' => $ magazine ,
86
92
'user ' => $ user ,
87
93
'form ' => $ form ->createView (),
94
+ 'maxSize ' => $ maxBytes ,
88
95
],
89
96
new Response (null , $ form ->isSubmitted () && !$ form ->isValid () ? 422 : 200 )
90
97
);
@@ -99,6 +106,7 @@ public function __invoke(?Magazine $magazine, ?string $type, Request $request):
99
106
'magazine ' => $ magazine ,
100
107
'user ' => $ user ,
101
108
'form ' => $ form ->createView (),
109
+ 'maxSize ' => $ maxBytes ,
102
110
],
103
111
new Response (null , 422 )
104
112
);
@@ -112,6 +120,21 @@ public function __invoke(?Magazine $magazine, ?string $type, Request $request):
112
120
'magazine ' => $ magazine ,
113
121
'user ' => $ user ,
114
122
'form ' => $ form ->createView (),
123
+ 'maxSize ' => $ maxBytes ,
124
+ ],
125
+ new Response (null , 422 )
126
+ );
127
+ } catch (ImageDownloadTooLargeException $ e ) {
128
+ $ this ->addFlash ('error ' , $ this ->translator ->trans ('flash_image_download_too_large_error ' , ['%bytes% ' => $ maxBytes ]));
129
+ $ this ->logger ->error ($ e );
130
+
131
+ return $ this ->render (
132
+ $ this ->getTemplateName ((new EntryPageView (1 ))->resolveType ($ type )),
133
+ [
134
+ 'magazine ' => $ magazine ,
135
+ 'user ' => $ user ,
136
+ 'form ' => $ form ->createView (),
137
+ 'maxSize ' => $ maxBytes ,
115
138
],
116
139
new Response (null , 422 )
117
140
);
@@ -126,6 +149,7 @@ public function __invoke(?Magazine $magazine, ?string $type, Request $request):
126
149
'magazine ' => $ magazine ,
127
150
'user ' => $ user ,
128
151
'form ' => $ form ->createView (),
152
+ 'maxSize ' => $ maxBytes ,
129
153
],
130
154
new Response (null , 422 )
131
155
);
0 commit comments