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
preset
key, or thepreset
default value. -
int(string $key, int $default = 0) : int - Returns the value of the
preset
key, if it is integer or thepreset
default value. -
float(string $key, float $default = 0) : float - Returns the value of the
preset
key, if it is float or thepreset
default value. -
array(string $key, array $default = array()) : array - Returns the value of the
preset
key, if it is an array or thepreset
default value. -
ident(string $key, string $default = '') : string - Returns the value of the
preset
key, if it contains only this: a-zA-Z0-9_- symbols, or thepreset
default value. -
isDefined(string $key) : bool - Returns
TRUE
if the the thepreset
key is defined, orFALSE
if it is not. -
isNull(string $key) : bool - Returns
TRUE
if the value of the thepreset
key is not set, orFALSE
otherwise. -
isNotSet(string $key) : bool - Returns
FALSE
if the value of the thepreset
key is not set, orTRUE
otherwise. -
is1(string $key) : bool - Returns
TRUE
only if value of the $key == 1; -
isEmpty(string $key, bool $ifNotSet = false) : bool - Returns
TRUE
if value of the $key == ''
- RSR v0.90.1 (https://github.com/in4s/NewRepo/)
- Semantic Versioning 2.0.0 (https://semver.org/)