1313
1414namespace phpbb \skeleton \controller ;
1515
16+ use Exception ;
1617use phpbb \config \config ;
1718use phpbb \controller \helper ;
1819use phpbb \exception \http_exception ;
2324use phpbb \template \template ;
2425use phpbb \user ;
2526use Symfony \Component \HttpFoundation \Response ;
27+ use Symfony \Component \HttpFoundation \StreamedResponse ;
2628
2729class main
2830{
2931 /** @var array */
30- protected $ data ;
32+ protected array $ data ;
3133
3234 /* @var config */
33- protected $ config ;
35+ protected config $ config ;
3436
3537 /* @var helper */
36- protected $ helper ;
38+ protected helper $ helper ;
3739
3840 /** @var language */
39- protected $ language ;
41+ protected language $ language ;
4042
4143 /* @var request */
42- protected $ request ;
44+ protected request $ request ;
4345
4446 /* @var packager */
45- protected $ packager ;
47+ protected packager $ packager ;
4648
4749 /* @var validator */
48- protected $ validator ;
50+ protected validator $ validator ;
4951
5052 /* @var template */
51- protected $ template ;
53+ protected template $ template ;
5254
5355 /* @var user */
54- protected $ user ;
56+ protected user $ user ;
5557
5658 /**
5759 * Constructor
@@ -83,11 +85,11 @@ public function __construct(config $config, helper $helper, language $language,
8385 * Controller for route /skeleton
8486 *
8587 * @throws http_exception
86- * @throws \ Exception
88+ * @throws Exception
8789 *
88- * @return Response A Symfony Response object
90+ * @return Response|StreamedResponse A Symfony Response object
8991 */
90- public function handle ()
92+ public function handle (): Response | StreamedResponse
9193 {
9294 if ($ this ->user ->data ['is_bot ' ])
9395 {
@@ -104,16 +106,16 @@ public function handle()
104106 $ this ->packager ->create_extension ($ this ->data );
105107 $ filename = $ this ->packager ->create_zip ($ this ->data );
106108
107- $ response = new Response ($ filename );
109+ $ response = new StreamedResponse (function () use ($ filename ) {
110+ readfile ($ filename );
111+ });
108112 $ response ->headers ->set ('Content-type ' , 'application/octet-stream ' );
109113 $ response ->headers ->set ('Content-Disposition ' , 'attachment; filename=" ' . basename ($ filename ) . '"; ' );
110114 $ response ->headers ->set ('Content-length ' , filesize ($ filename ));
111- $ response ->sendHeaders ();
112- $ response ->setContent (readfile ($ filename ));
113115
114116 return $ response ;
115117 }
116- catch (\ Exception $ e )
118+ catch (Exception $ e )
117119 {
118120 $ this ->template ->assign_var ('ERROR ' , $ e ->getMessage ());
119121 }
@@ -145,7 +147,7 @@ public function handle()
145147 'NAME ' => $ value ,
146148 'DESC ' => $ this ->language ->lang ('SKELETON_QUESTION_ ' . strtoupper ($ value ) . '_UI ' ),
147149 'DESC_EXPLAIN ' => $ this ->language ->is_set ('SKELETON_QUESTION_ ' . strtoupper ($ value ) . '_EXPLAIN ' ) ? $ this ->language ->lang ('SKELETON_QUESTION_ ' . strtoupper ($ value ) . '_EXPLAIN ' ) : '' ,
148- 'VALUE ' => isset ( $ author_values [$ value ][$ i ]) ? $ author_values [ $ value ][ $ i ] : '' ,
150+ 'VALUE ' => $ author_values [$ value ][$ i ] ?? '' ,
149151 ]);
150152 }
151153 }
@@ -189,7 +191,7 @@ public function handle()
189191 /**
190192 * Get composer data
191193 */
192- protected function get_composer_data ()
194+ protected function get_composer_data (): void
193195 {
194196 $ dialog_questions = $ this ->packager ->get_composer_dialog_values ();
195197 foreach ($ dialog_questions ['extension ' ] as $ value => $ default )
@@ -215,7 +217,7 @@ protected function get_composer_data()
215217 /**
216218 * Get components data
217219 */
218- protected function get_component_data ()
220+ protected function get_component_data (): void
219221 {
220222 $ components = $ this ->packager ->get_component_dialog_values ();
221223 foreach ($ components as $ component => $ details )
@@ -236,13 +238,13 @@ protected function get_component_data()
236238 /**
237239 * Get user input values
238240 *
239- * @param string $value
241+ * @param string $value
240242 * @param mixed $default
241- * @param null| int $array_key for multi user support
243+ * @param int|null $array_key for multi user support
242244 *
243- * @return mixed|string
245+ * @return mixed
244246 */
245- protected function get_user_input ($ value , $ default , $ array_key = null )
247+ protected function get_user_input (string $ value , mixed $ default , int $ array_key = null ): mixed
246248 {
247249 $ return_value = $ this ->get_request_variable ($ value , $ default , $ array_key );
248250
@@ -257,20 +259,20 @@ protected function get_user_input($value, $default, $array_key = null)
257259 /**
258260 * Get request variables
259261 *
260- * @param string $value
261- * @param mixed $default
262- * @param null| int $array_key for multi user support
262+ * @param string $value
263+ * @param mixed $default
264+ * @param int|null $array_key for multi user support
263265 *
264- * @return mixed|string
266+ * @return mixed
265267 */
266- protected function get_request_variable ($ value , $ default , $ array_key = null )
268+ protected function get_request_variable (string $ value , mixed $ default , int $ array_key = null ): mixed
267269 {
268270 if (is_bool ($ default ))
269271 {
270272 if ($ array_key !== null )
271273 {
272274 $ return_value = $ this ->request ->variable ($ value , [$ default ]);
273- return isset ( $ return_value [$ array_key ]) ? $ return_value [ $ array_key ] : $ default ;
275+ return $ return_value [$ array_key ] ?? $ default ;
274276 }
275277
276278 return $ this ->request ->variable ($ value , $ default );
0 commit comments