81 lines
2.3 KiB
PHP
81 lines
2.3 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
Module : /Web/Param.php
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : November 14th, 2013.
|
|
Last Modified : October 16th, 2026.
|
|
|
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
|
|
|
*******************************************************************/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Webapp\Web;
|
|
|
|
use \flight\Engine;
|
|
|
|
/**
|
|
* Class Param
|
|
*
|
|
* Manajemen Variable Request dari GET / POST.
|
|
*
|
|
* @license MIT, https://www.3fonia.com
|
|
* @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]>
|
|
*
|
|
* @package Webapp\Web
|
|
*/
|
|
|
|
final class Param {
|
|
private static $__ahasil = [];
|
|
|
|
public function __construct() {
|
|
if (count(self::$__ahasil)==0) self::__data();
|
|
}
|
|
|
|
private static function __data(): void {
|
|
global $app;
|
|
if (empty($app)) $app = \Flight::app();
|
|
$_asumber = $app->request()->query->getData() + $app->request()->data->getData();
|
|
foreach ($_asumber as $__key => $__val) {
|
|
if (in_array($__val, ['true','false'])) { $__val = ($__val === 'true'); }
|
|
else if (is_string($__val)) $__val = urldecode(self::safeSQL($__val));
|
|
self::$__ahasil[$__key] = $__val;
|
|
}
|
|
}
|
|
|
|
public static function safeSQL(string $str = ""): string {
|
|
$_se = ["\\","\0","\n","\r","\x1a","'",'"'];
|
|
$_re = ["\\\\","\\0","\\n","\\r","\Z","\'",'\"'];
|
|
return str_replace($_se, $_re, $str);
|
|
}
|
|
|
|
public static function Get(string $key = "", mixed $def = null): mixed {
|
|
if (empty(self::$__ahasil)) self::__data();
|
|
if (isset(self::$__ahasil[$key])) return self::$__ahasil[$key];
|
|
return $def;
|
|
}
|
|
|
|
public static function Int(string $key = "", int $def = 0): int {
|
|
if (empty(self::$__ahasil)) self::__data();
|
|
if (isset(self::$__ahasil[$key])) return (int) self::$__ahasil[$key];
|
|
return $def;
|
|
}
|
|
|
|
public static function Float(string $key = "", float $def = 0): float {
|
|
if (empty(self::$__ahasil)) self::__data();
|
|
if (isset(self::$__ahasil[$key])) return (float) self::$__ahasil[$key];
|
|
return $def;
|
|
}
|
|
|
|
public static function Get_All(): array {
|
|
if (count(self::$__ahasil)==0) self::__data();
|
|
return self::$__ahasil;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|