j4s / superglobals
Classes for work with superglobals $_GET, $_POST, $_SESSION, $_COOKIE
Installs: 72
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 19
pkg:composer/j4s/superglobals
Requires
- php: >=7.0.0
This package is auto-updated.
Last update: 2025-10-27 11:00:34 UTC
README
v1.0.0
SuperGlobals is a PHP library for safe and convenient handling of SuperGlobals such as $_GET, $_POST, $_SESSION, $_COOKIE.
- Safe because you can use special methods to validate or filter requested value "on the fly"
- Convenient because it makes application code short and meaningful, without useless repetitions, making it ''extra'' DRY
Using this library you can:
-
write
Get::get('key');instead ofisset($_GET['key']) ? $_GET['key'] : ''; -
put a default value as a second attribute like this:
Get::get('foo', 'bar');this returns 'bar' when $_GET['foo'] is not set. -
use methods like
Get::int('p');for getting an integer value, for page number. If you want to use default "1" in this keys, you should writeGet::int('p', 1); -
use the same interface for different SuperGlobals:
$_GET,$_POST,$_SESSION,$_COOKIE(useGet::get('foo');for $_GET['foo'], orCookie::get('foo');for $_COOKIE['foo'])
We have such a methods:
-
get(string $key, string $default = '') : string - Returns the value of the
presetkey, or thepresetdefault value. -
int(string $key, int $default = 0) : int - Returns the value of the
presetkey, if it is integer or thepresetdefault value. -
float(string $key, float $default = 0) : float - Returns the value of the
presetkey, if it is float or thepresetdefault value. -
array(string $key, array $default = array()) : array - Returns the value of the
presetkey, if it is an array or thepresetdefault value. -
ident(string $key, string $default = '') : string - Returns the value of the
presetkey, if it contains only this: a-zA-Z0-9_- symbols, or thepresetdefault value. -
isDefined(string $key) : bool - Returns
TRUEif the the thepresetkey is defined, orFALSEif it is not. -
isNull(string $key) : bool - Returns
TRUEif the value of the thepresetkey is not set, orFALSEotherwise. -
isNotSet(string $key) : bool - Returns
FALSEif the value of the thepresetkey is not set, orTRUEotherwise. -
is1(string $key) : bool - Returns
TRUEonly if value of the $key == 1; -
isEmpty(string $key, bool $ifNotSet = false) : bool - Returns
TRUEif value of the $key == ''
Complies with standards:
- RSR v0.90.1 (https://github.com/in4s/NewRepo/)
- Semantic Versioning 2.0.0 (https://semver.org/)