11<?php
2- /**
3- * Code for displaying server selection
4- */
52
63declare (strict_types=1 );
74
@@ -24,35 +21,32 @@ class Select
2421 /**
2522 * Renders the server selection in list or selectbox form, or option tags only
2623 *
27- * @param bool $not_only_options whether to include form tags or not
28- * @param bool $omit_fieldset whether to omit fieldset tag or not
24+ * @param bool $notOnlyOptions whether to include form tags or not
25+ * @param bool $omitFieldset whether to omit fieldset tag or not
2926 */
30- public static function render (bool $ not_only_options , bool $ omit_fieldset ): string
27+ public static function render (bool $ notOnlyOptions , bool $ omitFieldset ): string
3128 {
3229 // Show as list?
33- if ($ not_only_options ) {
30+ if ($ notOnlyOptions ) {
3431 $ list = $ GLOBALS ['cfg ' ]['DisplayServersList ' ];
35- $ not_only_options = ! $ list ;
32+ $ notOnlyOptions = ! $ list ;
3633 } else {
3734 $ list = false ;
3835 }
3936
40- $ form_action = '' ;
41- if ($ not_only_options ) {
42- $ form_action = Util ::getScriptNameForOption ($ GLOBALS ['cfg ' ]['DefaultTabServer ' ], 'server ' );
37+ $ formAction = '' ;
38+ if ($ notOnlyOptions ) {
39+ $ formAction = Util ::getScriptNameForOption ($ GLOBALS ['cfg ' ]['DefaultTabServer ' ], 'server ' );
4340 }
4441
45- $ servers = [];
42+ /** @var array{list: list<array<string, mixed>>, select: list<array<string, mixed>>} $servers */
43+ $ servers = ['list ' => [], 'select ' => []];
4644 foreach ($ GLOBALS ['cfg ' ]['Servers ' ] as $ key => $ server ) {
4745 if (empty ($ server ['host ' ])) {
4846 continue ;
4947 }
5048
51- if (! empty ($ GLOBALS ['server ' ]) && (int ) $ GLOBALS ['server ' ] === (int ) $ key ) {
52- $ selected = 1 ;
53- } else {
54- $ selected = 0 ;
55- }
49+ $ selected = ! empty ($ GLOBALS ['server ' ]) && (int ) $ GLOBALS ['server ' ] === (int ) $ key ;
5650
5751 if (! empty ($ server ['verbose ' ])) {
5852 $ label = $ server ['verbose ' ];
@@ -78,41 +72,27 @@ public static function render(bool $not_only_options, bool $omit_fieldset): stri
7872
7973 if ($ list ) {
8074 if ($ selected ) {
81- $ servers ['list ' ][] = [
82- 'selected ' => true ,
83- 'label ' => $ label ,
84- ];
75+ $ servers ['list ' ][] = ['selected ' => true , 'href ' => '' , 'label ' => $ label ];
8576 } else {
8677 $ scriptName = Util ::getScriptNameForOption ($ GLOBALS ['cfg ' ]['DefaultTabServer ' ], 'server ' );
8778 $ href = $ scriptName . Url ::getCommon (
8879 ['server ' => $ key ],
8980 ! str_contains ($ scriptName , '? ' ) ? '? ' : '& ' ,
9081 );
91- $ servers ['list ' ][] = [
92- 'href ' => $ href ,
93- 'label ' => $ label ,
94- ];
82+ $ servers ['list ' ][] = ['selected ' => false , 'href ' => $ href , 'label ' => $ label ];
9583 }
9684 } else {
97- $ servers ['select ' ][] = [
98- 'value ' => $ key ,
99- 'selected ' => $ selected ,
100- 'label ' => $ label ,
101- ];
85+ $ servers ['select ' ][] = ['value ' => $ key , 'selected ' => $ selected , 'label ' => $ label ];
10286 }
10387 }
10488
105- $ renderDetails = [
106- 'not_only_options ' => $ not_only_options ,
107- 'omit_fieldset ' => $ omit_fieldset ,
108- 'servers ' => $ servers ,
109- ];
110- if ($ not_only_options ) {
111- $ renderDetails ['form_action ' ] = $ form_action ;
112- }
113-
11489 $ template = new Template ();
11590
116- return $ template ->render ('server/select/index ' , $ renderDetails );
91+ return $ template ->render ('server/select/index ' , [
92+ 'not_only_options ' => $ notOnlyOptions ,
93+ 'omit_fieldset ' => $ omitFieldset ,
94+ 'servers ' => $ servers ,
95+ 'form_action ' => $ formAction ,
96+ ]);
11797 }
11898}
0 commit comments