update
This commit is contained in:
+65
-65
@@ -8,29 +8,29 @@ use RuntimeException;
|
|||||||
class Request
|
class Request
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array|null
|
||||||
*/
|
*/
|
||||||
public static $file;
|
public $file = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array|null
|
||||||
*/
|
*/
|
||||||
public static $header;
|
public $header = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array|null
|
||||||
*/
|
*/
|
||||||
public static $server;
|
public $server = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array|null
|
||||||
*/
|
*/
|
||||||
public static $payload;
|
public $payload = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init()
|
public function init()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
{
|
{
|
||||||
@@ -45,8 +45,8 @@ class Request
|
|||||||
$_REQUEST = array_merge($_REQUEST, $add_get);
|
$_REQUEST = array_merge($_REQUEST, $add_get);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
//self::init_payload();
|
//$this->init_payload();
|
||||||
//self::init_file();
|
//$this->init_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
// common
|
// common
|
||||||
@@ -54,14 +54,14 @@ class Request
|
|||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function is_cli()
|
public function is_cli()
|
||||||
{
|
{
|
||||||
return \php_sapi_name() === 'cli';
|
return \php_sapi_name() === 'cli';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function is_cli_server()
|
public function is_cli_server()
|
||||||
{
|
{
|
||||||
return \php_sapi_name() === 'cli-server';
|
return \php_sapi_name() === 'cli-server';
|
||||||
}
|
}
|
||||||
@@ -69,40 +69,40 @@ class Request
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function script_name()
|
public function script_name()
|
||||||
{
|
{
|
||||||
return self::server('script_name');
|
return $this->server('script_name');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function method()
|
public function method()
|
||||||
{
|
{
|
||||||
return strtolower((string) self::server('REQUEST_METHOD', 'get'));
|
return strtolower((string) $this->server('REQUEST_METHOD', 'get'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function is_method($value)
|
public function is_method($value)
|
||||||
{
|
{
|
||||||
return strtolower($value) === self::method();
|
return strtolower($value) === $this->method();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function is_ajax() {
|
public function is_ajax() {
|
||||||
return self::has_header('X_REQUESTED_WITH') &&
|
return $this->has_header('X_REQUESTED_WITH') &&
|
||||||
strtolower((string) self::header('X_REQUESTED_WITH')) === 'xmlhttprequest';
|
strtolower((string) $this->header('X_REQUESTED_WITH')) === 'xmlhttprequest';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function ip()
|
public function ip()
|
||||||
{
|
{
|
||||||
$keys = [
|
$keys = [
|
||||||
'HTTP_CLIENT_IP',
|
'HTTP_CLIENT_IP',
|
||||||
@@ -124,43 +124,43 @@ class Request
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function user_agent()
|
public function user_agent()
|
||||||
{
|
{
|
||||||
return (string) self::header('user_agent');
|
return (string) $this->header('user_agent');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function referer()
|
public function referer()
|
||||||
{
|
{
|
||||||
return (string) self::header('referer');
|
return (string) $this->header('referer');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function host()
|
public function host()
|
||||||
{
|
{
|
||||||
return (string) self::header('host');
|
return (string) $this->header('host');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function base_url()
|
public function base_url()
|
||||||
{
|
{
|
||||||
return self::server('request_scheme', 'http')
|
return $this->server('request_scheme', 'http')
|
||||||
. '://'
|
. '://'
|
||||||
. self::server('server_name', 'localhost');
|
. $this->server('server_name', 'localhost');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $mode
|
* @param string $mode
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function uri($mode = 'full')
|
public function uri($mode = 'full')
|
||||||
{
|
{
|
||||||
$uri = self::server('request_uri');
|
$uri = $this->server('request_uri');
|
||||||
|
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
case 'request':
|
case 'request':
|
||||||
@@ -168,16 +168,16 @@ class Request
|
|||||||
case 'no_query':
|
case 'no_query':
|
||||||
return strtok($uri, '?');
|
return strtok($uri, '?');
|
||||||
default:
|
default:
|
||||||
return self::base_url() . $uri;
|
return $this->base_url() . $uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function query_string()
|
public function query_string()
|
||||||
{
|
{
|
||||||
return (string) self::server('query_string');
|
return (string) $this->server('query_string');
|
||||||
}
|
}
|
||||||
|
|
||||||
// HEADER
|
// HEADER
|
||||||
@@ -186,7 +186,7 @@ class Request
|
|||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function header($key = '', $default = null)
|
public function header($key = '', $default = null)
|
||||||
{
|
{
|
||||||
if ($key === '') {
|
if ($key === '') {
|
||||||
$headers = [];
|
$headers = [];
|
||||||
@@ -205,7 +205,7 @@ class Request
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has_header($key)
|
public function has_header($key)
|
||||||
{
|
{
|
||||||
return isset($_SERVER['HTTP_' . strtoupper($key)]);
|
return isset($_SERVER['HTTP_' . strtoupper($key)]);
|
||||||
}
|
}
|
||||||
@@ -217,7 +217,7 @@ class Request
|
|||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function get($key = '', $default = null)
|
public function get($key = '', $default = null)
|
||||||
{
|
{
|
||||||
if ($key === '') {
|
if ($key === '') {
|
||||||
return $_GET;
|
return $_GET;
|
||||||
@@ -229,7 +229,7 @@ class Request
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has_get($key)
|
public function has_get($key)
|
||||||
{
|
{
|
||||||
return isset($_GET[$key]);
|
return isset($_GET[$key]);
|
||||||
}
|
}
|
||||||
@@ -238,7 +238,7 @@ class Request
|
|||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function set_get($key, $value)
|
public function set_get($key, $value)
|
||||||
{
|
{
|
||||||
$_GET[$key] = $value;
|
$_GET[$key] = $value;
|
||||||
}
|
}
|
||||||
@@ -250,7 +250,7 @@ class Request
|
|||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function post($key, $default = null)
|
public function post($key, $default = null)
|
||||||
{
|
{
|
||||||
if ($key === '') {
|
if ($key === '') {
|
||||||
return $_POST;
|
return $_POST;
|
||||||
@@ -262,7 +262,7 @@ class Request
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has_post($key)
|
public function has_post($key)
|
||||||
{
|
{
|
||||||
return isset($_POST[$key]);
|
return isset($_POST[$key]);
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ class Request
|
|||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function set_post($key, $value)
|
public function set_post($key, $value)
|
||||||
{
|
{
|
||||||
$_POST[$key] = $value;
|
$_POST[$key] = $value;
|
||||||
}
|
}
|
||||||
@@ -283,7 +283,7 @@ class Request
|
|||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function cookie($key, $default = null)
|
public function cookie($key, $default = null)
|
||||||
{
|
{
|
||||||
if ($key === '') {
|
if ($key === '') {
|
||||||
return $_COOKIE;
|
return $_COOKIE;
|
||||||
@@ -295,7 +295,7 @@ class Request
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has_cookie($key)
|
public function has_cookie($key)
|
||||||
{
|
{
|
||||||
return isset($_COOKIE[$key]);
|
return isset($_COOKIE[$key]);
|
||||||
}
|
}
|
||||||
@@ -304,7 +304,7 @@ class Request
|
|||||||
* @param string $value
|
* @param string $value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function set_cookie($key, $value)
|
public function set_cookie($key, $value)
|
||||||
{
|
{
|
||||||
$_COOKIE[$key] = $value;
|
$_COOKIE[$key] = $value;
|
||||||
}
|
}
|
||||||
@@ -316,7 +316,7 @@ class Request
|
|||||||
* @param int $ttl
|
* @param int $ttl
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function session_start($prefix = 'sess_', $ttl = 86400)
|
public function session_start($prefix = 'sess_', $ttl = 86400)
|
||||||
{
|
{
|
||||||
//session_set_save_handler(new \Nightmare\Session\Storage\Apcu($prefix, $ttl));
|
//session_set_save_handler(new \Nightmare\Session\Storage\Apcu($prefix, $ttl));
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ class Request
|
|||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function session($key, $default = null)
|
public function session($key, $default = null)
|
||||||
{
|
{
|
||||||
if ($key === '') {
|
if ($key === '') {
|
||||||
return $_SESSION;
|
return $_SESSION;
|
||||||
@@ -345,7 +345,7 @@ class Request
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has_session($key)
|
public function has_session($key)
|
||||||
{
|
{
|
||||||
return isset($_SESSION[$key]);
|
return isset($_SESSION[$key]);
|
||||||
}
|
}
|
||||||
@@ -354,7 +354,7 @@ class Request
|
|||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function set_session($key, $value)
|
public function set_session($key, $value)
|
||||||
{
|
{
|
||||||
$_SESSION[$key] = $value;
|
$_SESSION[$key] = $value;
|
||||||
}
|
}
|
||||||
@@ -362,7 +362,7 @@ class Request
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function unset_session($key)
|
public function unset_session($key)
|
||||||
{
|
{
|
||||||
unset($_SESSION[$key]);
|
unset($_SESSION[$key]);
|
||||||
}
|
}
|
||||||
@@ -375,7 +375,7 @@ class Request
|
|||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function server($key, $default = null)
|
public function server($key, $default = null)
|
||||||
{
|
{
|
||||||
if ($key === '') {
|
if ($key === '') {
|
||||||
return $_SERVER;
|
return $_SERVER;
|
||||||
@@ -387,7 +387,7 @@ class Request
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has_server($key)
|
public function has_server($key)
|
||||||
{
|
{
|
||||||
return isset($_SERVER[$key]) ? true : isset($_SERVER[strtoupper($key)]);
|
return isset($_SERVER[$key]) ? true : isset($_SERVER[strtoupper($key)]);
|
||||||
}
|
}
|
||||||
@@ -397,7 +397,7 @@ class Request
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
public static function file($key)
|
public function file($key)
|
||||||
{
|
{
|
||||||
if ($key === '') {
|
if ($key === '') {
|
||||||
return $_FILES;
|
return $_FILES;
|
||||||
@@ -432,7 +432,7 @@ class Request
|
|||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function request($key, $default = null)
|
public function request($key, $default = null)
|
||||||
{
|
{
|
||||||
if ($key === '') {
|
if ($key === '') {
|
||||||
return $_REQUEST;
|
return $_REQUEST;
|
||||||
@@ -444,7 +444,7 @@ class Request
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has_request($key)
|
public function has_request($key)
|
||||||
{
|
{
|
||||||
return isset($_REQUEST[$key]);
|
return isset($_REQUEST[$key]);
|
||||||
}
|
}
|
||||||
@@ -454,29 +454,29 @@ class Request
|
|||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init_payload()
|
public function init_payload()
|
||||||
{
|
{
|
||||||
self::$payload = Json::decode(file_get_contents('php://input') ?: '[]', true);
|
$this->payload = Json::decode(file_get_contents('php://input') ?: '[]', true);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has_payload($key)
|
public function has_payload($key)
|
||||||
{
|
{
|
||||||
return isset(self::$payload[$key]);
|
return isset($this->payload[$key]);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function payload($key = '', $default = null)
|
public function payload($key = '', $default = null)
|
||||||
{
|
{
|
||||||
if ($key === '') {
|
if ($key === '') {
|
||||||
return self::$payload;
|
return $this->payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$payload[$key] ?? $default;
|
return $this->payload[$key] ?? $default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user