Add function for ensuring all input in an array is strings

This commit is contained in:
Joshua Ramon Enslin 2024-07-09 16:43:21 +02:00
parent cd46a3ec73
commit fb008e1b59
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -131,6 +131,27 @@ final class MD_STD_IN {
}
/**
* Validates an input array for all entries being strings. Unsets empty values.
* This is especially useful for parsed JSON.
*
* @param array<mixed> $inputs Input array.
*
* @return array<string>
*/
public static function sanitize_text_array(array $inputs):array {
$output = [];
foreach ($inputs as $key => $input) {
if (empty($input)) continue;
$output[$key] = self::sanitize_text($input);
}
return $output;
}
/**
* Retrieves HTTP input texts from GET or POST variables, whatever is provided.
* If neither is given, returns a provided default.