2929use function __ ;
3030use function htmlspecialchars ;
3131use function in_array ;
32+ use function is_string ;
3233use function max ;
3334use function mb_strtoupper ;
3435use function sprintf ;
@@ -362,25 +363,13 @@ public function __invoke(ServerRequest $request): Response
362363 }
363364 }
364365
365- /** @var mixed $routineType */
366- $ routineType = $ request ->getQueryParam ('item_type ' );
367- if (
368- ! empty ($ _GET ['export_item ' ])
369- && ! empty ($ _GET ['item_name ' ])
370- && in_array ($ routineType , ['FUNCTION ' , 'PROCEDURE ' ], true )
371- ) {
372- if ($ routineType === 'FUNCTION ' ) {
373- $ routineDefinition = Routines ::getFunctionDefinition (
374- $ this ->dbi ,
375- Current::$ database ,
376- $ _GET ['item_name ' ],
377- );
366+ $ routineType = $ this ->getRoutineType ($ request ->getQueryParam ('item_type ' ));
367+ $ routineName = $ this ->getRoutineName ($ request ->getQueryParam ('item_name ' ));
368+ if ($ request ->hasQueryParam ('export_item ' ) && $ routineName !== '' && $ routineType !== null ) {
369+ if ($ routineType === RoutineType::Function) {
370+ $ routineDefinition = Routines ::getFunctionDefinition ($ this ->dbi , Current::$ database , $ routineName );
378371 } else {
379- $ routineDefinition = Routines ::getProcedureDefinition (
380- $ this ->dbi ,
381- Current::$ database ,
382- $ _GET ['item_name ' ],
383- );
372+ $ routineDefinition = Routines ::getProcedureDefinition ($ this ->dbi , Current::$ database , $ routineName );
384373 }
385374
386375 $ exportData = false ;
@@ -389,10 +378,10 @@ public function __invoke(ServerRequest $request): Response
389378 $ exportData = "DELIMITER $$ \n" . $ routineDefinition . "$$ \nDELIMITER ; \n" ;
390379 }
391380
392- $ itemName = Util ::backquote ($ _GET [ ' item_name ' ] );
381+ $ routineName = Util ::backquote ($ routineName );
393382 if ($ exportData !== false ) {
394383 $ exportData = trim ($ exportData );
395- $ title = sprintf (__ ('Export of routine %s ' ), $ itemName );
384+ $ title = sprintf (__ ('Export of routine %s ' ), $ routineName );
396385
397386 if ($ request ->isAjax ()) {
398387 $ this ->response ->addJSON ('message ' , $ exportData );
@@ -414,7 +403,7 @@ public function __invoke(ServerRequest $request): Response
414403 'Error in processing request: No routine with name %1$s found in database %2$s. '
415404 . ' You might be lacking the necessary privileges to view/export this routine. ' ,
416405 ),
417- htmlspecialchars ($ itemName ),
406+ htmlspecialchars ($ routineName ),
418407 htmlspecialchars (Util ::backquote (Current::$ database )),
419408 );
420409 $ message = Message ::error ($ message );
@@ -490,4 +479,14 @@ public function __invoke(ServerRequest $request): Response
490479
491480 return $ this ->response ->response ();
492481 }
482+
483+ private function getRoutineType (mixed $ param ): RoutineType |null
484+ {
485+ return is_string ($ param ) ? RoutineType ::tryFrom ($ param ) : null ;
486+ }
487+
488+ private function getRoutineName (mixed $ param ): string
489+ {
490+ return is_string ($ param ) ? $ param : '' ;
491+ }
493492}
0 commit comments