mirror of https://gitee.com/karson/fastadmin.git
mod: add type comments
parent
b0d295bd67
commit
63cdd2ad25
|
|
@ -11,11 +11,11 @@ class Http
|
||||||
/**
|
/**
|
||||||
* 发送一个POST请求
|
* 发送一个POST请求
|
||||||
* @param string $url 请求URL
|
* @param string $url 请求URL
|
||||||
* @param array $params 请求参数
|
* @param array $params 请求参数
|
||||||
* @param array $options 扩展参数
|
* @param array $options 扩展参数
|
||||||
* @return mixed|string
|
* @return mixed|string
|
||||||
*/
|
*/
|
||||||
public static function post($url, $params = [], $options = [])
|
public static function post(string $url, array $params = [], array $options = [])
|
||||||
{
|
{
|
||||||
$req = self::sendRequest($url, $params, 'POST', $options);
|
$req = self::sendRequest($url, $params, 'POST', $options);
|
||||||
return $req['ret'] ? $req['msg'] : '';
|
return $req['ret'] ? $req['msg'] : '';
|
||||||
|
|
@ -24,11 +24,11 @@ class Http
|
||||||
/**
|
/**
|
||||||
* 发送一个GET请求
|
* 发送一个GET请求
|
||||||
* @param string $url 请求URL
|
* @param string $url 请求URL
|
||||||
* @param array $params 请求参数
|
* @param array $params 请求参数
|
||||||
* @param array $options 扩展参数
|
* @param array $options 扩展参数
|
||||||
* @return mixed|string
|
* @return mixed|string
|
||||||
*/
|
*/
|
||||||
public static function get($url, $params = [], $options = [])
|
public static function get(string $url, array $params = [], array $options = [])
|
||||||
{
|
{
|
||||||
$req = self::sendRequest($url, $params, 'GET', $options);
|
$req = self::sendRequest($url, $params, 'GET', $options);
|
||||||
return $req['ret'] ? $req['msg'] : '';
|
return $req['ret'] ? $req['msg'] : '';
|
||||||
|
|
@ -42,7 +42,7 @@ class Http
|
||||||
* @param mixed $options CURL的参数
|
* @param mixed $options CURL的参数
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function sendRequest($url, $params = [], $method = 'POST', $options = [])
|
public static function sendRequest(string $url, $params = [], string $method = 'POST', $options = []): array
|
||||||
{
|
{
|
||||||
$method = strtoupper($method);
|
$method = strtoupper($method);
|
||||||
$protocol = substr($url, 0, 5);
|
$protocol = substr($url, 0, 5);
|
||||||
|
|
@ -108,7 +108,7 @@ class Http
|
||||||
* @param string $method 请求的方法
|
* @param string $method 请求的方法
|
||||||
* @return boolean TRUE
|
* @return boolean TRUE
|
||||||
*/
|
*/
|
||||||
public static function sendAsyncRequest($url, $params = [], $method = 'POST')
|
public static function sendAsyncRequest(string $url, $params = [], string $method = 'POST'): bool
|
||||||
{
|
{
|
||||||
$method = strtoupper($method);
|
$method = strtoupper($method);
|
||||||
$method = $method == 'POST' ? 'POST' : 'GET';
|
$method = $method == 'POST' ? 'POST' : 'GET';
|
||||||
|
|
@ -157,10 +157,10 @@ class Http
|
||||||
/**
|
/**
|
||||||
* 发送文件到客户端
|
* 发送文件到客户端
|
||||||
* @param string $file
|
* @param string $file
|
||||||
* @param bool $delaftersend
|
* @param bool $deleteAfterSend
|
||||||
* @param bool $exitaftersend
|
* @param bool $exitAfterSend
|
||||||
*/
|
*/
|
||||||
public static function sendToBrowser($file, $delaftersend = true, $exitaftersend = true)
|
public static function sendToBrowser(string $file, bool $deleteAfterSend = true, bool $exitAfterSend = true)
|
||||||
{
|
{
|
||||||
if (file_exists($file) && is_readable($file)) {
|
if (file_exists($file) && is_readable($file)) {
|
||||||
header('Content-Description: File Transfer');
|
header('Content-Description: File Transfer');
|
||||||
|
|
@ -174,10 +174,10 @@ class Http
|
||||||
ob_clean();
|
ob_clean();
|
||||||
flush();
|
flush();
|
||||||
readfile($file);
|
readfile($file);
|
||||||
if ($delaftersend) {
|
if ($deleteAfterSend) {
|
||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
if ($exitaftersend) {
|
if ($exitAfterSend) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class Random
|
||||||
* @param int $len 长度
|
* @param int $len 长度
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function alnum($len = 6)
|
public static function alnum(int $len = 6): string
|
||||||
{
|
{
|
||||||
return self::build('alnum', $len);
|
return self::build('alnum', $len);
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +25,7 @@ class Random
|
||||||
* @param int $len 长度
|
* @param int $len 长度
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function alpha($len = 6)
|
public static function alpha(int $len = 6): string
|
||||||
{
|
{
|
||||||
return self::build('alpha', $len);
|
return self::build('alpha', $len);
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +36,7 @@ class Random
|
||||||
* @param int $len 长度
|
* @param int $len 长度
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function numeric($len = 4)
|
public static function numeric(int $len = 4): string
|
||||||
{
|
{
|
||||||
return self::build('numeric', $len);
|
return self::build('numeric', $len);
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +47,7 @@ class Random
|
||||||
* @param int $len 长度
|
* @param int $len 长度
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function nozero($len = 4)
|
public static function nozero(int $len = 4): string
|
||||||
{
|
{
|
||||||
return self::build('nozero', $len);
|
return self::build('nozero', $len);
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,7 @@ class Random
|
||||||
* @param int $len 长度
|
* @param int $len 长度
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function build($type = 'alnum', $len = 8)
|
public static function build(string $type = 'alnum', int $len = 8): string
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'alpha':
|
case 'alpha':
|
||||||
|
|
@ -93,7 +93,7 @@ class Random
|
||||||
* 获取全球唯一标识
|
* 获取全球唯一标识
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function uuid()
|
public static function uuid(): string
|
||||||
{
|
{
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue