Globals
in package
A class that serves as an abstraction/wrapper to work with superglobals.
Tags
Table of Contents
- GLOBALS = ['_GET' => '_GET', '_POST' => '_POST', '_FILES' => '_FILES', '_COOKIE' => '_COOKIE', '_SESSION' => '_SESSION', '_REQUEST' => '_REQUEST', '_SERVER' => '_SERVER', '_ENV' => '_ENV']
- $cookie : object
- $env : object
- $files : object
- $get : object
- $post : object
- $request : object
- $server : object
- $session : object
- $globals : array<string|int, mixed>
- This array holds an anonymous class that acts as a wrapper for each superglobal.
- $isInitialized : bool
- $_COOKIE : array<string|int, mixed>
- $_ENV : array<string|int, mixed>
- $_FILES : array<string|int, mixed>
- $_GET : array<string|int, mixed>
- $_POST : array<string|int, mixed>
- $_REQUEST : array<string|int, mixed>
- $_SERVER : array<string|int, mixed>
- $_SESSION : array<string|int, mixed>
- __call() : mixed
- Allows static methods handled by `self::__callStatic()` to be accessible via object operator `->`.
- __callStatic() : mixed
- Aliases getters and setter for class members.
- __construct() : mixed
- Class constructor.
- __get() : mixed
- Aliases getters and setter for class members.
- cut() : static
- Cuts a value from the specified superglobal. The value will be returned and the key will be unset from the superglobal.
- cutCookie() :
- cutEnv() :
- cutFiles() :
- cutGet() :
- cutPost() :
- cutRequest() :
- cutServer() :
- cutSession() :
- get() : mixed
- Gets a value from the specified superglobal.
- getAll() : array<string|int, mixed>
- Returns all superglobals.
- getCookie() :
- getEnv() :
- getFiles() :
- getGet() :
- getPost() :
- getRequest() :
- getServer() :
- getSession() :
- initialize() : void
- Initializes class internal state from superglobals.
- instance() : static
- Initializes class internal state from superglobals and returns an instance o it.
- set() : static
- Sets a value in the specified superglobal.
- setCookie() :
- setEnv() :
- setFiles() :
- setGet() :
- setPost() :
- setRequest() :
- setServer() :
- setSession() :
- getValidNameOrFail() : string
- Returns a valid superglobal name from the passed name.
Constants
GLOBALS
public
mixed
GLOBALS
= ['_GET' => '_GET', '_POST' => '_POST', '_FILES' => '_FILES', '_COOKIE' => '_COOKIE', '_SESSION' => '_SESSION', '_REQUEST' => '_REQUEST', '_SERVER' => '_SERVER', '_ENV' => '_ENV']
Properties
$cookie
public
object
$cookie
A class around the superglobal $_COOKIE
that has the methods has($key)
, get($key, $default)
, set($key, $value)
, and getAll()
.
$env
public
object
$env
A class around the superglobal $_ENV
that has the methods has($key)
, get($key, $default)
, set($key, $value)
, and getAll()
.
$files
public
object
$files
A class around the superglobal $_FILES
that has the methods has($key)
, get($key, $default)
, set($key, $value)
, and getAll()
.
$get
public
object
$get
A class around the superglobal $_GET
that has the methods has($key)
, get($key, $default)
, set($key, $value)
, and getAll()
.
$post
public
object
$post
A class around the superglobal $_POST
that has the methods has($key)
, get($key, $default)
, set($key, $value)
, and getAll()
.
$request
public
object
$request
A class around the superglobal $_REQUEST
that has the methods has($key)
, get($key, $default)
, set($key, $value)
, and getAll()
.
$server
public
object
$server
A class around the superglobal $_SERVER
that has the methods has($key)
, get($key, $default)
, set($key, $value)
, and getAll()
.
$session
public
object
$session
A class around the superglobal $_SESSION
that has the methods has($key)
, get($key, $default)
, set($key, $value)
, and getAll()
.
$globals
This array holds an anonymous class that acts as a wrapper for each superglobal.
protected
static array<string|int, mixed>
$globals
$isInitialized
protected
static bool
$isInitialized
= false
$_COOKIE
private
static array<string|int, mixed>
$_COOKIE
$_ENV
private
static array<string|int, mixed>
$_ENV
$_FILES
private
static array<string|int, mixed>
$_FILES
$_GET
private
static array<string|int, mixed>
$_GET
$_POST
private
static array<string|int, mixed>
$_POST
$_REQUEST
private
static array<string|int, mixed>
$_REQUEST
$_SERVER
private
static array<string|int, mixed>
$_SERVER
$_SESSION
private
static array<string|int, mixed>
$_SESSION
Methods
__call()
Allows static methods handled by `self::__callStatic()` to be accessible via object operator `->`.
public
__call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
- $arguments : array<string|int, mixed>
Return values
mixed —__callStatic()
Aliases getters and setter for class members.
public
static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
- $name : string
- $arguments : array<string|int, mixed>
Return values
mixed —__construct()
Class constructor.
public
final __construct() : mixed
Return values
mixed —__get()
Aliases getters and setter for class members.
public
__get(string $name) : mixed
Parameters
- $name : string
Return values
mixed —cut()
Cuts a value from the specified superglobal. The value will be returned and the key will be unset from the superglobal.
public
static cut(string $name, string $key) : static
Parameters
- $name : string
-
The superglobal name to get the value from. Can be written in any case with or without the leading underscore.
- $key : string
-
The array element to get from the superglobal. Dot-notation can be used with nested arrays.
Tags
Return values
static —cutCookie()
public
static cutCookie(string $key = null) :
Cuts a value from $_COOKIE. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—cutEnv()
public
static cutEnv(string $key = null) :
Cuts a value from $_ENV. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—cutFiles()
public
static cutFiles(string $key = null) :
Cuts a value from $_FILES. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—cutGet()
public
static cutGet(string $key = null) :
Cuts a value from $_GET. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—cutPost()
public
static cutPost(string $key = null) :
Cuts a value from $_POST. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—cutRequest()
public
static cutRequest(string $key = null) :
Cuts a value from $_REQUEST. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—cutServer()
public
static cutServer(string $key = null) :
Cuts a value from $_SERVER. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—cutSession()
public
static cutSession(string $key = null) :
Cuts a value from $_SESSION. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—get()
Gets a value from the specified superglobal.
public
static get(string $name[, string $key = null ]) : mixed
Parameters
- $name : string
-
The superglobal name to get the value from. Can be written in any case with or without the leading underscore.
- $key : string = null
-
The array element to get from the superglobal. Dot-notation can be used with nested arrays.
Tags
Return values
mixed —getAll()
Returns all superglobals.
public
static getAll() : array<string|int, mixed>
Return values
array<string|int, mixed> —getCookie()
public
static getCookie(string $key = null) :
Gets a value from $_COOKIE. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—getEnv()
public
static getEnv(string $key = null) :
Gets a value from $_ENV. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—getFiles()
public
static getFiles(string $key = null) :
Gets a value from $_FILES. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—getGet()
public
static getGet(string $key = null) :
Gets a value from $_GET. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—getPost()
public
static getPost(string $key = null) :
Gets a value from $_POST. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—getRequest()
public
static getRequest(string $key = null) :
Gets a value from $_REQUEST. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—getServer()
public
static getServer(string $key = null) :
Gets a value from $_SERVER. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—getSession()
public
static getSession(string $key = null) :
Gets a value from $_SESSION. Dot-notation can be used for nested values.
Parameters
- $key = null : string
Return values
—initialize()
Initializes class internal state from superglobals.
public
static initialize() : void
Return values
void —instance()
Initializes class internal state from superglobals and returns an instance o it.
public
static instance() : static
Return values
static —set()
Sets a value in the specified superglobal.
public
static set(string $name, string $key, mixed $value) : static
Parameters
- $name : string
-
The superglobal name to set the value in. Can be written in any case with or without the leading underscore.
- $key : string
-
The array element to set in the superglobal. Dot-notation can be used with nested arrays.
- $value : mixed
-
The value to set.
Tags
Return values
static —setCookie()
public
static setCookie(string $key, mixed $value) :
Sets a value in $_COOKIE. Dot-notation can be used for nested values.
Parameters
- $key : string
- $value : mixed
Return values
—setEnv()
public
static setEnv(string $key, mixed $value) :
Sets a value in $_ENV. Dot-notation can be used for nested values.
Parameters
- $key : string
- $value : mixed
Return values
—setFiles()
public
static setFiles(string $key, mixed $value) :
Sets a value in $_FILES. Dot-notation can be used for nested values.
Parameters
- $key : string
- $value : mixed
Return values
—setGet()
public
static setGet(string $key, mixed $value) :
Sets a value in $_GET. Dot-notation can be used for nested values.
Parameters
- $key : string
- $value : mixed
Return values
—setPost()
public
static setPost(string $key, mixed $value) :
Sets a value in $_POST. Dot-notation can be used for nested values.
Parameters
- $key : string
- $value : mixed
Return values
—setRequest()
public
static setRequest(string $key, mixed $value) :
Sets a value in $_REQUEST. Dot-notation can be used for nested values.
Parameters
- $key : string
- $value : mixed
Return values
—setServer()
public
static setServer(string $key, mixed $value) :
Sets a value in $_SERVER. Dot-notation can be used for nested values.
Parameters
- $key : string
- $value : mixed
Return values
—setSession()
public
static setSession(string $key, mixed $value) :
Sets a value in $_SESSION. Dot-notation can be used for nested values.
Parameters
- $key : string
- $value : mixed
Return values
—getValidNameOrFail()
Returns a valid superglobal name from the passed name.
private
static getValidNameOrFail(string $name) : string
Parameters
- $name : string