* Support PHP8.1.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* 禅道API的entry类。
|
||||
* The entry class file of ZenTao API.
|
||||
@@ -83,11 +83,10 @@ class baseEntry
|
||||
* Get request data(POST or PUT)
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $defaultValue
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function request($key, $defaultValue = '')
|
||||
public function request(string $key, $defaultValue = '')
|
||||
{
|
||||
if(isset($this->requestBody->$key)) return $this->requestBody->$key;
|
||||
return $defaultValue;
|
||||
@@ -98,11 +97,10 @@ class baseEntry
|
||||
* Get request params.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $defaultValue
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function param($key, $defaultValue = '')
|
||||
public function param(string $key, $defaultValue = '')
|
||||
{
|
||||
if(isset($_GET[$key])) return $_GET[$key];
|
||||
return $defaultValue;
|
||||
@@ -113,11 +111,10 @@ class baseEntry
|
||||
* Set request param.
|
||||
*
|
||||
* @param string|array $key if is array, set params by its key-value pairs.
|
||||
* @param mixed $value
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function setParam($key, $value = null)
|
||||
public function setParam(string|array $key, $value = null)
|
||||
{
|
||||
if(is_array($key))
|
||||
{
|
||||
@@ -202,11 +199,10 @@ class baseEntry
|
||||
* Send response data
|
||||
*
|
||||
* @param int $code
|
||||
* @param mixed $data
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function send($code, $data = '')
|
||||
public function send(int $code, $data = '')
|
||||
{
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Credentials: true");
|
||||
@@ -227,7 +223,7 @@ class baseEntry
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function sendError($code, $msg)
|
||||
public function sendError(int $code, string $msg)
|
||||
{
|
||||
$response = new stdclass();
|
||||
$response->error = $msg;
|
||||
@@ -244,7 +240,7 @@ class baseEntry
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function sendSuccess($code, $msg)
|
||||
public function sendSuccess(int $code, string $msg)
|
||||
{
|
||||
$response = new stdclass();
|
||||
$response->message = $msg;
|
||||
@@ -259,7 +255,7 @@ class baseEntry
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function send400($message = 'error')
|
||||
public function send400(string $message = 'error')
|
||||
{
|
||||
return $this->sendError(400, $message);
|
||||
}
|
||||
@@ -284,7 +280,7 @@ class baseEntry
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function loadController($moduleName, $methodName)
|
||||
public function loadController(string $moduleName, string $methodName)
|
||||
{
|
||||
ob_start();
|
||||
|
||||
@@ -315,7 +311,7 @@ class baseEntry
|
||||
}
|
||||
|
||||
$file2Included = $isExt ? $app->extActionFile : $app->controlFile;
|
||||
chdir(dirname($file2Included));
|
||||
chdir(dirname((string) $file2Included));
|
||||
helper::import($file2Included);
|
||||
}
|
||||
|
||||
@@ -341,7 +337,7 @@ class baseEntry
|
||||
* @access public
|
||||
* @return object|bool 如果没有model文件,返回false,否则返回model对象。If no model file, return false, else return the model object.
|
||||
*/
|
||||
public function loadModel($moduleName = '', $appName = '')
|
||||
public function loadModel(string $moduleName = '', string $appName = '')
|
||||
{
|
||||
if(empty($moduleName)) $moduleName = $this->app->moduleName;
|
||||
if(empty($appName)) $appName = $this->app->appName;
|
||||
@@ -400,8 +396,8 @@ class baseEntry
|
||||
public function getData()
|
||||
{
|
||||
$output = helper::removeUTF8Bom(ob_get_clean());
|
||||
$output = json_decode($output);
|
||||
if(isset($output->data)) $output->data = json_decode($output->data);
|
||||
$output = json_decode((string) $output);
|
||||
if(isset($output->data)) $output->data = json_decode((string) $output->data);
|
||||
|
||||
return $output;
|
||||
}
|
||||
@@ -411,7 +407,6 @@ class baseEntry
|
||||
* Add data to $_POST.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
@@ -425,11 +420,10 @@ class baseEntry
|
||||
* Batch set data to $_POST.
|
||||
*
|
||||
* @param string $fields
|
||||
* @param mixed $object
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function batchSetPost($fields, $object = '')
|
||||
public function batchSetPost(string $fields, $object = '')
|
||||
{
|
||||
$fields = explode(',', $fields);
|
||||
foreach($fields as $field)
|
||||
@@ -457,11 +451,10 @@ class baseEntry
|
||||
* Make sure the fields is not empty.
|
||||
*
|
||||
* @param string $fields
|
||||
* @param mixed $object
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function requireFields($fields)
|
||||
public function requireFields(string $fields)
|
||||
{
|
||||
$fields = explode(',', $fields);
|
||||
foreach($fields as $field)
|
||||
@@ -469,7 +462,7 @@ class baseEntry
|
||||
if(!isset($_POST[$field]))
|
||||
{
|
||||
$module = $this->app->moduleName;
|
||||
$name = isset($this->app->lang->$module->$field) ? $this->app->lang->$module->$field : $field;
|
||||
$name = $this->app->lang->$module->$field ?? $field;
|
||||
throw EndResponseException::create($this->sendError(400, sprintf($this->app->lang->error->notempty, $name)));
|
||||
}
|
||||
}
|
||||
@@ -484,7 +477,7 @@ class baseEntry
|
||||
* @access public
|
||||
* @return object|array
|
||||
*/
|
||||
public function format($data, $fields)
|
||||
public function format(object|array $data, string $fields)
|
||||
{
|
||||
if(is_array($data))
|
||||
{
|
||||
@@ -504,7 +497,7 @@ class baseEntry
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
private function formatFields(&$object, $fields)
|
||||
private function formatFields(object &$object, string $fields)
|
||||
{
|
||||
$fields = explode(',', $fields);
|
||||
|
||||
@@ -523,7 +516,7 @@ class baseEntry
|
||||
$isArray = true;
|
||||
$type = substr($type, $pos + 1);
|
||||
}
|
||||
else if(strpos($type, 'array') !== false)
|
||||
else if(str_contains($type, 'array'))
|
||||
{
|
||||
$isArray = true;
|
||||
$type = 'object';
|
||||
@@ -532,7 +525,7 @@ class baseEntry
|
||||
/* Format value. */
|
||||
if(!$isArray)
|
||||
{
|
||||
$object->$key = $this->cast(trim($object->$key, ','), $type);
|
||||
$object->$key = $this->cast(trim((string) $object->$key, ','), $type);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -559,11 +552,11 @@ class baseEntry
|
||||
* Filter fields.
|
||||
*
|
||||
* @param object $object
|
||||
* @param array $filters
|
||||
* @param string $allowable
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function filterFields($object, $allowable = '')
|
||||
public function filterFields(object $object, string $allowable = '')
|
||||
{
|
||||
if(empty($allowable)) return $object;
|
||||
if(is_string($allowable)) $allowable = explode(',', $allowable);
|
||||
@@ -571,7 +564,7 @@ class baseEntry
|
||||
$filtered = new stdclass();
|
||||
foreach($allowable as $field)
|
||||
{
|
||||
$field = trim($field);
|
||||
$field = trim((string) $field);
|
||||
if(empty($field)) continue;
|
||||
if(!isset($object->$field)) continue;
|
||||
$filtered->$field = $object->$field;
|
||||
@@ -583,12 +576,12 @@ class baseEntry
|
||||
/**
|
||||
* Format user.
|
||||
*
|
||||
* @param string $account
|
||||
* @param array $users
|
||||
* @param string $account
|
||||
* @param array|object $users
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function formatUser($account, $users)
|
||||
public function formatUser(string $account, array|object $users)
|
||||
{
|
||||
$user = array();
|
||||
$user['account'] = $account;
|
||||
@@ -606,7 +599,7 @@ class baseEntry
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
private function cast($value, $type)
|
||||
private function cast($value, string $type)
|
||||
{
|
||||
switch($type)
|
||||
{
|
||||
@@ -615,7 +608,7 @@ class baseEntry
|
||||
if($timeFormat == 'utc')
|
||||
{
|
||||
if(!$value or $value == '0000-00-00 00:00:00') return null;
|
||||
return gmdate("Y-m-d\TH:i:s\Z", strtotime($value));
|
||||
return gmdate("Y-m-d\TH:i:s\Z", strtotime((string) $value));
|
||||
}
|
||||
return $value;
|
||||
case 'date':
|
||||
@@ -626,7 +619,7 @@ class baseEntry
|
||||
case 'int':
|
||||
return (int) $value;
|
||||
case 'idList':
|
||||
$values = explode(',', $value);
|
||||
$values = explode(',', (string) $value);
|
||||
if(empty($values)) return array();
|
||||
|
||||
$idList = array();
|
||||
@@ -636,7 +629,7 @@ class baseEntry
|
||||
}
|
||||
return $idList;
|
||||
case 'stringList':
|
||||
$values = explode(',', $value);
|
||||
$values = explode(',', (string) $value);
|
||||
if(empty($values)) return array();
|
||||
|
||||
$stringList = array();
|
||||
@@ -654,7 +647,7 @@ class baseEntry
|
||||
if(empty($this->users)) $this->users = $this->dao->select('id,account,avatar,realname')->from(TABLE_USER)->fetchAll('account');
|
||||
return zget($this->users, $value, null);
|
||||
case 'userList':
|
||||
$values = explode(',', $value);
|
||||
$values = explode(',', (string) $value);
|
||||
if(empty($values)) return array();
|
||||
|
||||
$userList = array();
|
||||
@@ -679,7 +672,7 @@ class baseEntry
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetch($entry, $method, $params = array())
|
||||
public function fetch(string $entry, string $method, array $params = array())
|
||||
{
|
||||
include($this->app->appRoot . "api/{$this->app->version}/entries/" . strtolower($entry) . ".php");
|
||||
|
||||
@@ -711,7 +704,7 @@ class baseEntry
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function resetOpenApp($tab)
|
||||
public function resetOpenApp(string $tab)
|
||||
{
|
||||
$_COOKIE['tab'] = $tab;
|
||||
$this->app->tab = $tab;
|
||||
|
||||
Reference in New Issue
Block a user