refactor solution to PHP through AI
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ElixForms\Common;
|
||||
|
||||
/**
|
||||
* Utility statica per leggere parametri dalla URL corrente ($_GET).
|
||||
* Equivalente PHP di QueryParamHelper.tsx nel progetto React.
|
||||
*/
|
||||
class QueryParamHelper
|
||||
{
|
||||
/**
|
||||
* Ottiene un array di valori numerici dalla query string (per checkbox).
|
||||
* Il parametro è una stringa di valori separati da virgola (es. "1,3,5").
|
||||
*
|
||||
* @param string $paramName Nome del parametro nella query string
|
||||
* @return int[] Array di interi
|
||||
*/
|
||||
public static function getCheckedFromQuery(string $paramName): array
|
||||
{
|
||||
$raw = $_GET[$paramName] ?? '';
|
||||
|
||||
if ($raw === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$parts = explode(',', (string)$raw);
|
||||
$result = [];
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$trimmed = trim($part);
|
||||
if ($trimmed !== '' && is_numeric($trimmed)) {
|
||||
$result[] = (int)$trimmed;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ottiene un singolo valore numerico dalla query string (per radio/dropdown).
|
||||
*
|
||||
* @param string $paramName Nome del parametro nella query string
|
||||
* @return int|null Valore numerico o null se non presente
|
||||
*/
|
||||
public static function getOptionFromQuery(string $paramName): ?int
|
||||
{
|
||||
if (!isset($_GET[$paramName])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = $_GET[$paramName];
|
||||
|
||||
if (!is_numeric($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int)$value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ottiene un valore booleano dalla query string.
|
||||
*
|
||||
* @param string $paramName Nome del parametro nella query string
|
||||
* @return bool|null true/false o null se non presente
|
||||
*/
|
||||
public static function getBooleanFromQuery(string $paramName): ?bool
|
||||
{
|
||||
if (!isset($_GET[$paramName])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return strtolower((string)$_GET[$paramName]) === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Ottiene un valore testuale decodificato dalla query string.
|
||||
*
|
||||
* @param string $paramName Nome del parametro nella query string
|
||||
* @return string|null Valore decodificato o null se non presente
|
||||
*/
|
||||
public static function getDecodedTextFromQuery(string $paramName): ?string
|
||||
{
|
||||
if (!isset($_GET[$paramName])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return urldecode((string)$_GET[$paramName]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user