Strong type array parameter helper (#6661)

Also useful for extensions (including one I am writing)
This commit is contained in:
Alexandre Alapetite
2024-07-29 14:48:17 +02:00
committed by GitHub
parent 47a3e15edc
commit 5c8369ce38
2 changed files with 10 additions and 1 deletions

View File

@@ -114,7 +114,7 @@ class FreshRSS_entry_Controller extends FreshRSS_ActionController {
}
} else {
/** @var array<numeric-string> $idArray */
$idArray = Minz_Request::paramArray('id');
$idArray = Minz_Request::paramArrayString('id');
$idString = Minz_Request::paramString('id');
if (count($idArray) > 0) {
$ids = $idArray;

View File

@@ -69,6 +69,15 @@ class Minz_Request {
return $specialchars ? Minz_Helper::htmlspecialchars_utf8(self::$params[$key]) : self::$params[$key];
}
/** @return array<string> */
public static function paramArrayString(string $key, bool $specialchars = false): array {
if (empty(self::$params[$key]) || !is_array(self::$params[$key])) {
return [];
}
$result = array_filter(self::$params[$key], 'is_string');
return $specialchars ? Minz_Helper::htmlspecialchars_utf8($result) : $result;
}
public static function paramTernary(string $key): ?bool {
if (isset(self::$params[$key])) {
$p = self::$params[$key];