diff --git a/framework/api/entry.class.php b/framework/api/entry.class.php index 0b3f15714b..5c0a8122c3 100644 --- a/framework/api/entry.class.php +++ b/framework/api/entry.class.php @@ -1,4 +1,4 @@ -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; diff --git a/framework/api/helper.class.php b/framework/api/helper.class.php index f24358735e..919ea889e5 100644 --- a/framework/api/helper.class.php +++ b/framework/api/helper.class.php @@ -1,4 +1,4 @@ -requestType != 'GET') @@ -21,10 +21,10 @@ class helper extends baseHelper $pathInfo = $app->getPathInfo(); if(!empty($pathInfo)) { - $dotPos = strrpos($pathInfo, '.'); + $dotPos = strrpos((string) $pathInfo, '.'); if($dotPos) { - $viewType = substr($pathInfo, $dotPos + 1); + $viewType = substr((string) $pathInfo, $dotPos + 1); } else { @@ -46,8 +46,8 @@ class helper extends baseHelper } if($source and isset($viewType)) return $viewType; - if(isset($viewType) and strpos($config->views, ',' . $viewType . ',') === false) $viewType = $config->default->view; - return isset($viewType) ? $viewType : $config->default->view; + if(isset($viewType) and !str_contains((string) $config->views, ',' . $viewType . ',')) $viewType = $config->default->view; + return $viewType ?? $config->default->view; } /** @@ -58,19 +58,19 @@ class helper extends baseHelper * @access public * @return bool */ - public static function hasFeature($feature) + public static function hasFeature(string $feature) { global $config; - if(strpos($feature, '_') !== false) + if(str_contains($feature, '_')) { $code = explode('_', $feature); $code = $code[0] . ucfirst($code[1]); - return strpos(",$config->disabledFeatures,", ",{$code},") === false; + return !str_contains(",$config->disabledFeatures,", ",{$code},"); } else { - if($feature == 'product' or $feature == 'scrum' or $feature == 'waterfall') return strpos(",$config->disabledFeatures,", ",{$feature},") === false; + if($feature == 'product' or $feature == 'scrum' or $feature == 'waterfall') return !str_contains(",$config->disabledFeatures,", ",{$feature},"); $hasFeature = false; foreach($config->featureGroup as $group => $modules) @@ -90,7 +90,7 @@ class helper extends baseHelper } } } - return $hasFeature && strpos(",$config->disabledFeatures,", ",{$feature},") === false; + return $hasFeature && !str_contains(",$config->disabledFeatures,", ",{$feature},"); } } @@ -103,13 +103,13 @@ class helper extends baseHelper * @access public * @return string */ - public static function jsonEncode4Parse($data, $options = 0) + public static function jsonEncode4Parse(array $data, int $options = 0) { $json = json_encode($data); if($options) $json = str_replace(array("'", '"'), array('\u0027', '\u0022'), $json); - $escapers = array("\\", "/", "\"", "'", "\n", "\r", "\t", "\x08", "\x0c", "\\\\u"); - $replacements = array("\\\\", "\\/", "\\\"", "\'", "\\n", "\\r", "\\t", "\\f", "\\b", "\\u"); + $escapers = array("\\", "/", "\"", "'", "\n", "\r", "\t", "\x08", "\x0c", "\\\\u"); + $replacements = array("\\\\", "\\/", "\\\"", "\'", "\\n", "\\r", "\\t", "\\f", "\\b", "\\u"); return str_replace($escapers, $replacements, $json); } @@ -123,7 +123,7 @@ class helper extends baseHelper * @access public * @return string */ - public static function convertEncoding($string, $fromEncoding, $toEncoding = 'utf-8') + public static function convertEncoding(string $string, string $fromEncoding, string $toEncoding = 'utf-8') { $toEncoding = str_replace('utf8', 'utf-8', $toEncoding); if(function_exists('mb_convert_encoding')) @@ -133,7 +133,7 @@ class helper extends baseHelper if($position !== false) $toEncoding = substr($toEncoding, 0, $position); /* Check string encoding. */ - $encodings = array_merge(array('GB2312','GBK','BIG5'), mb_list_encodings()); + $encodings = array_merge(array('GB2312', 'GBK', 'BIG5'), mb_list_encodings()); $encoding = strtolower(mb_detect_encoding($string, $encodings)); if($encoding == $toEncoding) return $string; return mb_convert_encoding($string, $toEncoding, $encoding); @@ -155,10 +155,8 @@ class helper extends baseHelper * * @param string $begin * @param string $end - * - * @return bool|float */ - public static function workDays($begin, $end) + public static function workDays(string $begin, string $end): bool|float { $begin = strtotime($begin); $end = strtotime($end); @@ -180,7 +178,7 @@ class helper extends baseHelper * @access public * @return string */ - public static function unify($string, $to = ',') + public static function unify(string $string, string $to = ',') { $labels = array('_', '、', ' ', '-', '?', '@', '&', '%', '~', '`', '+', '*', '/', '\\', ',', '。'); $string = str_replace($labels, $to, $string); @@ -190,27 +188,29 @@ class helper extends baseHelper /** * Create url of issue. * - * @param string $module - * @param string $method - * @param string $vars + * @param string $module + * @param string $method + * @param string|array $vars + * @param string $viewType + * @param bool $onlyBody * @static * @access public * @return string */ - static public function createLink($moduleName, $methodName = 'index', $vars = '', $viewType = 'json', $onlyBody = false) + static public function createLink(string $moduleName, string $methodName = 'index', string|array $vars = '', string $viewType = 'json', bool $onlyBody = false) { global $config; $link = parent::createLink($moduleName, $methodName, $vars, $viewType); - $pos = strpos($link, '.php'); + $pos = strpos((string) $link, '.php'); /* The requestTypes are: GET, PATH_INFO2, PATH_INFO */ if($config->requestType == 'GET') { - $link = $config->webRoot . 'index' . substr($link, $pos); + $link = $config->webRoot . 'index' . substr((string) $link, $pos); } elseif($config->requestType == 'PATH_INFO2') { - $link = substr($link, $pos + 4); + $link = substr((string) $link, $pos + 4); } return common::getSysURL() . $link; } @@ -221,9 +221,9 @@ class helper extends baseHelper * Check exist onlybody param. * * @access public - * @return void + * @return bool */ -function isonlybody() +function isonlybody(): bool { return helper::inOnlyBodyMode(); } @@ -231,12 +231,12 @@ function isonlybody() /** * Format time. * - * @param int $time + * @param string $time * @param string $format * @access public - * @return void + * @return string */ -function formatTime($time, $format = '') +function formatTime(string $time, string $format = '') { $time = str_replace('0000-00-00', '', $time); $time = str_replace('00:00:00', '', $time); @@ -248,11 +248,11 @@ function formatTime($time, $format = '') /** * Fix for session error. * - * @param int $class + * @param string $class * @access protected * @return void */ -function autoloader($class) +function autoloader(string $class) { if(!class_exists($class)) { diff --git a/framework/api/router.class.php b/framework/api/router.class.php index ba88468a31..33b46310da 100644 --- a/framework/api/router.class.php +++ b/framework/api/router.class.php @@ -1,4 +1,4 @@ -httpMethod = strtolower($_SERVER['REQUEST_METHOD']); + $this->httpMethod = strtolower((string) $_SERVER['REQUEST_METHOD']); /* $documentRoot = zget($_SERVER, 'CONTEXT_DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']); @@ -91,7 +91,7 @@ class api extends router if(strpos($this->path, '?') > 0) $this->path = strstr($this->path, '?', true); */ - $this->path = trim(substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], 'api.php') + 7), '/'); + $this->path = trim(substr((string) $_SERVER['REQUEST_URI'], strpos((string) $_SERVER['REQUEST_URI'], 'api.php') + 7), '/'); if(strpos($this->path, '?') > 0) $this->path = strstr($this->path, '?', true); $subPos = $this->path ? strpos($this->path, '/') : false; @@ -107,26 +107,26 @@ class api extends router * Parse request path, find entry and action. * * @param array $routes - * @access private + * @access public * @return void */ - public function route($routes) + public function route(array $routes) { foreach($routes as $route => $target) { $patternAsRegex = preg_replace_callback( '#:([\w]+)\+?#', - array($this, 'matchesCallback'), + $this->matchesCallback(...), str_replace(')', ')?', $route) ); - if(substr($route, -1) === '/') $patternAsRegex .= '?'; + if(str_ends_with($route, '/')) $patternAsRegex .= '?'; /* Cache URL params' names and values if this route matches the current HTTP request. */ if(!preg_match('#^' . $patternAsRegex . '$#', $this->path, $paramValues)) continue; /* Set module and action */ $this->entry = $target; - $this->action = strtolower($_SERVER['REQUEST_METHOD']); + $this->action = strtolower((string) $_SERVER['REQUEST_METHOD']); /* Set params */ foreach($this->paramNames as $name) @@ -154,11 +154,11 @@ class api extends router * * Parse params of route to regular expression. * - * @param string $param + * @param string $m * @access protected * @return string */ - protected function matchesCallback($m) + protected function matchesCallback(string $m) { $this->paramNames[] = $m[1]; return '(?P<' . $m[1] . '>[^/]+)'; @@ -230,7 +230,7 @@ class api extends router * @access public * @return void */ - public function loadApiConfig($configPath) + public function loadApiConfig(string $configPath) { global $config; include($this->appRoot . "api/$this->version/config/$configPath.php"); @@ -260,17 +260,17 @@ class api extends router * @access public * @return string */ - public function formatData($output) + public function formatData(string $output) { /* If the version exists, return output directly. */ if($this->version) return $output; - $output = json_decode($output); + $output = json_decode((string) $output); $data = new stdClass(); - $data->status = isset($output->status) ? $output->status : $output->result; + $data->status = $output->status ?? $output->result; if(isset($output->message)) $data->message = $output->message; - if(isset($output->data)) $data->data = json_decode($output->data); + if(isset($output->data)) $data->data = json_decode((string) $output->data); if(isset($output->id)) $data->id = $output->id; $output = json_encode($data); diff --git a/framework/base/control.class.php b/framework/base/control.class.php index 25dc9fc83d..a387118d74 100644 --- a/framework/base/control.class.php +++ b/framework/base/control.class.php @@ -1,4 +1,4 @@ -lang = $lang; $this->dbh = $dbh; $this->viewType = $this->app->getViewType(); - $this->appName = $appName ? $appName : $this->app->getAppName(); + $this->appName = $appName ?: $this->app->getAppName(); /** * 设置当前模块,读取该模块的model类。 @@ -257,7 +257,7 @@ class baseControl * Load the zen file auto. */ $zenClass = $this->moduleName . 'Zen'; - $selfClass = get_class($this); + $selfClass = static::class; $parentClasses = class_parents($this); if($selfClass != $zenClass && !isset($parentClasses[$zenClass])) $this->loadZen($this->moduleName, $appName); } @@ -272,9 +272,9 @@ class baseControl * @access public * @return void */ - public function setModuleName($moduleName = '') + public function setModuleName(string $moduleName = '') { - $this->moduleName = $moduleName ? strtolower($moduleName) : $this->app->getModuleName(); + $this->moduleName = $moduleName ? strtolower((string) $moduleName) : $this->app->getModuleName(); } /** @@ -285,7 +285,7 @@ class baseControl * @access public * @return void */ - public function setMethodName($methodName = '') + public function setMethodName(string $methodName = '') { $this->methodName = $methodName ? strtolower($methodName) : $this->app->getMethodName(); } @@ -301,7 +301,7 @@ class baseControl * @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 = ''): object|bool { $model = $this->app->loadTarget($moduleName, $appName); @@ -333,7 +333,7 @@ class baseControl * @access public * @return object|bool 如果没有zen文件,返回false,否则返回zen对象。If no zen file, return false, else return the zen object. */ - public function loadZen($moduleName = '', $appName = '') + public function loadZen(string $moduleName = '', string $appName = ''): object|bool { $zen = $this->app->loadTarget($moduleName, $appName, 'zen'); if(!$zen) return false; @@ -396,7 +396,7 @@ class baseControl * @access public * @return string the view file */ - public function setViewFile($moduleName, $methodName) + public function setViewFile(string $moduleName, string $methodName) { $moduleName = strtolower(trim($moduleName)); $methodName = strtolower(trim($methodName)); @@ -434,13 +434,13 @@ class baseControl * @access public * @return string|bool If extension view file exists, return the path. Else return fasle. */ - public function getExtViewFile($viewFile) + public function getExtViewFile(string $viewFile): string|bool { /** * 首先找sitecode下的扩展文件,如果没有,再找ext下的扩展文件。 * Find extViewFile in ext/_$siteCode/view first, then try ext/view/. */ - $moduleName = basename(dirname(dirname(realpath($viewFile)))); + $moduleName = basename(dirname(realpath($viewFile), 2)); $extPath = $this->app->getModuleExtPath('', $moduleName, 'view'); $checkedOrder = array('site', 'saas', 'custom', 'vision', 'xuan', 'common'); @@ -470,7 +470,7 @@ class baseControl * @access public * @return string */ - public function getCSS($moduleName, $methodName) + public function getCSS(string $moduleName, string $methodName): string { $moduleName = strtolower(trim($moduleName)); $methodName = strtolower(trim($methodName)); @@ -479,7 +479,7 @@ class baseControl $cssExtPath = $this->app->getModuleExtPath($this->appName, $moduleName, 'css'); $clientLang = $this->app->getClientLang(); - $notCNLang = strpos('|zh-cn|zh-tw|', "|{$clientLang}|") === false; + $notCNLang = !str_contains('|zh-cn|zh-tw|', "|{$clientLang}|"); $css = ''; $devicePrefix = $this->devicePrefix; @@ -531,15 +531,15 @@ class baseControl * @access public * @return string */ - public function getExtCSS($files) + public function getExtCSS(array $files): string { $clientLang = $this->app->getClientLang(); - $notCNLang = strpos('|zh-cn|zh-tw|', "|{$clientLang}|") === false; + $notCNLang = !str_contains('|zh-cn|zh-tw|', "|{$clientLang}|"); $filePairs = array(); foreach($files as $cssFile) { - $fileName = basename($cssFile); + $fileName = basename((string) $cssFile); $filePairs[$fileName] = $cssFile; } @@ -551,11 +551,11 @@ class baseControl { /* Method extension css file. like module/story/ext/css/create/effort.css. */ $css .= file_get_contents($cssFile); - list($code) = explode('.', $fileName); + [$code] = explode('.', $fileName); } else { - list($code) = explode('.', $fileName); + [$code] = explode('.', $fileName); if(isset($usedCodes[$code])) continue; } @@ -584,7 +584,7 @@ class baseControl * @access public * @return string */ - public function getJS($moduleName, $methodName) + public function getJS(string $moduleName, string $methodName): string { $moduleName = strtolower(trim($moduleName)); $methodName = strtolower(trim($methodName)); @@ -627,7 +627,7 @@ class baseControl * @access public * @return void */ - public function assign($name, $value) + public function assign(string $name, $value) { $this->view->$name = $value; } @@ -653,7 +653,7 @@ class baseControl * @access public * @return string the parsed result. */ - public function parse($moduleName = '', $methodName = '') + public function parse(string $moduleName = '', string $methodName = ''): string { if(empty($moduleName)) $moduleName = $this->moduleName; if(empty($methodName)) $methodName = $this->methodName; @@ -673,8 +673,9 @@ class baseControl * @access public * @return void */ - public function parseJSON($moduleName, $methodName) + public function parseJSON(string $moduleName, string $methodName) { + $output = array(); unset($this->view->app); unset($this->view->config); unset($this->view->lang); @@ -701,7 +702,7 @@ class baseControl * @access public * @return void */ - public function parseDefault($moduleName, $methodName) + public function parseDefault(string $moduleName, string $methodName) { /** * 设置视图文件。(PHP7有一个bug,不能直接$viewFile = $this->setViewFile())。 @@ -753,13 +754,13 @@ class baseControl * Get the output of one module's one method as a string, thus in one module's method, can fetch other module's content. * If the module name is empty, then use the current module and method. If set, use the user defined module and method. * - * @param string $moduleName module name. - * @param string $methodName method name. - * @param array $params params. + * @param string $moduleName module name. + * @param string $methodName method name. + * @param array|string $params params. * @access public * @return string the parsed html. */ - public function fetch($moduleName = '', $methodName = '', $params = array(), $appName = '') + public function fetch(string $moduleName = '', string $methodName = '', array|string $params = array(), string $appName = '') { /** * 如果模块名为空,则调用该模块、该方法。 @@ -811,28 +812,28 @@ class baseControl if(!empty($actionExtPath['common'])) { - $commonActionExtFile = $actionExtPath['common'] . strtolower($methodName) . '.php'; + $commonActionExtFile = $actionExtPath['common'] . strtolower((string) $methodName) . '.php'; if(file_exists($commonActionExtFile)) $file2Included = $commonActionExtFile; } if(!empty($actionExtPath['xuan'])) { - $commonActionExtFile = $actionExtPath['xuan'] . strtolower($methodName) . '.php'; + $commonActionExtFile = $actionExtPath['xuan'] . strtolower((string) $methodName) . '.php'; if(file_exists($commonActionExtFile)) $file2Included = $commonActionExtFile; } if(!empty($actionExtPath['vision'])) { - $commonActionExtFile = $actionExtPath['vision'] . strtolower($methodName) . '.php'; + $commonActionExtFile = $actionExtPath['vision'] . strtolower((string) $methodName) . '.php'; if(file_exists($commonActionExtFile)) $file2Included = $commonActionExtFile; } - $commonActionExtFile = $actionExtPath['custom'] . strtolower($methodName) . '.php'; + $commonActionExtFile = $actionExtPath['custom'] . strtolower((string) $methodName) . '.php'; if(file_exists($commonActionExtFile)) $file2Included = $commonActionExtFile; if(!empty($actionExtPath['saas'])) { - $commonActionExtFile = $actionExtPath['saas'] . strtolower($methodName) . '.php'; + $commonActionExtFile = $actionExtPath['saas'] . strtolower((string) $methodName) . '.php'; if(file_exists($commonActionExtFile)) $file2Included = $commonActionExtFile; } @@ -842,12 +843,12 @@ class baseControl * 设置站点扩展。 * every site has it's extension. */ - $siteActionExtFile = $actionExtPath['site'] . strtolower($methodName) . '.php'; + $siteActionExtFile = $actionExtPath['site'] . strtolower((string) $methodName) . '.php'; $file2Included = file_exists($siteActionExtFile) ? $siteActionExtFile : $file2Included; } /* If class name is my{$moduleName} then set classNameToFetch for include this file. */ - if(strpos($file2Included, DS . 'ext' . DS) !== false and stripos(file_get_contents($file2Included), "class my{$moduleName} extends $moduleName") !== false) $classNameToFetch = "my{$moduleName}"; + if(str_contains($file2Included, DS . 'ext' . DS) and stripos(file_get_contents($file2Included), "class my{$moduleName} extends $moduleName") !== false) $classNameToFetch = "my{$moduleName}"; } /** @@ -912,7 +913,7 @@ class baseControl * @access public * @return void */ - public function display($moduleName = '', $methodName = '') + public function display(string $moduleName = '', string $methodName = '') { if(empty($this->output)) $this->parse($moduleName, $methodName); echo $this->output; @@ -922,12 +923,11 @@ class baseControl * 直接输出data数据,通常用于ajax请求中。 * Send data directly, for ajax requests. * - * @param mixed $data * @param string $type * @access public * @return void */ - public function send($data, $type = 'json') + public function send($data, string $type = 'json') { if($type != 'json') die(); @@ -970,9 +970,9 @@ class baseControl if(isset($data['result']) and $data['result'] == 'success') { if(!empty($data['message'])) echo js::alert($data['message']); - $locate = isset($data['locate']) ? $data['locate'] : (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); + $locate = $data['locate'] ?? $_SERVER['HTTP_REFERER'] ?? ''; if(!empty($locate)) die(js::locate($locate)); - die(isset($data['message']) ? $data['message'] : 'success'); + die($data['message'] ?? 'success'); } if(isset($data['result']) and $data['result'] == 'fail') @@ -982,9 +982,9 @@ class baseControl if(is_string($data['message'])) { echo js::alert($data['message']); - $locate = isset($data['locate']) ? $data['locate'] : (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); + $locate = $data['locate'] ?? $_SERVER['HTTP_REFERER'] ?? ''; if (!empty($locate)) die(js::locate($locate)); - die(isset($data['message']) ? $data['message'] : 'fail'); + die($data['message'] ?? 'fail'); } $message = json_decode(json_encode($data['message']), true); @@ -998,7 +998,6 @@ class baseControl /** * return error json * - * @param mixed $error * @return void * @author thanatos thanatos915@163.com */ @@ -1014,7 +1013,7 @@ class baseControl * @return void * @author thanatos thanatos915@163.com */ - public function sendSuccess($data) + public function sendSuccess(array $data) { $data['result'] = 'success'; if(empty($data['message'])) $data['message'] = $this->lang->saveSuccess; @@ -1029,11 +1028,11 @@ class baseControl * @param string $methodName method name * @param string|array $vars the params passed, can be array(key=>value) or key1=value1&key2=value2 * @param string $viewType the view type - * @param string $onlybody remove header and footer or not in iframe + * @param bool $onlybody remove header and footer or not in iframe * @access public * @return string the link string. */ - public function createLink($moduleName, $methodName = 'index', $vars = array(), $viewType = '', $onlybody = false) + public function createLink(string $moduleName, string $methodName = 'index', string|array $vars = array(), string $viewType = '', bool $onlybody = false): string { if(empty($moduleName)) $moduleName = $this->moduleName; return helper::createLink($moduleName, $methodName, $vars, $viewType, $onlybody); @@ -1046,10 +1045,11 @@ class baseControl * @param string $methodName method name * @param string|array $vars the params passed, can be array(key=>value) or key1=value1&key2=value2 * @param string $viewType the view type + * @param bool $onlybody remove header and footer or not in iframe * @access public * @return string the link string. */ - public function inlink($methodName = 'index', $vars = array(), $viewType = '', $onlybody = false) + public function inlink(string $methodName = 'index', string|array $vars = array(), string $viewType = '', bool $onlybody = false) { return helper::createLink($this->moduleName, $methodName, $vars, $viewType, $onlybody); } diff --git a/framework/base/helper.class.php b/framework/base/helper.class.php index 3e5694036e..c3e8cbd086 100644 --- a/framework/base/helper.class.php +++ b/framework/base/helper.class.php @@ -1,4 +1,4 @@ -', $key); $value = serialize($value); $code = ("\$${objName}->{$key}=unserialize(<<requestType == 'PATH_INFO') $link = $config->webRoot . $appName; - if($config->requestType != 'PATH_INFO') $link = $config->webRoot . $appName . basename($_SERVER['SCRIPT_NAME']); + if($config->requestType != 'PATH_INFO') $link = $config->webRoot . $appName . basename((string) $_SERVER['SCRIPT_NAME']); if($config->requestType == 'PATH_INFO2') $link = '/'; /** @@ -166,10 +167,10 @@ class baseHelper { global $config; - $sign = strpos($link, '?') === false ? "?" : "&"; + $sign = !str_contains($link, '?') ? "?" : "&"; $appendString = ''; if($onlyBody or self::inOnlyBodyMode()) $appendString = $sign . "onlybody=yes"; - if(self::isWithTID() and strpos($link, 'tid=') === false) $appendString .= empty($appendString) ? "{$sign}tid={$_GET['tid']}" : "&tid={$_GET['tid']}"; + if(self::isWithTID() and !str_contains($link, 'tid=')) $appendString .= empty($appendString) ? "{$sign}tid={$_GET['tid']}" : "&tid={$_GET['tid']}"; return $link . $appendString; } @@ -210,7 +211,7 @@ class baseHelper static public function import($file) { $file = realpath($file); - if(!is_file($file)) return false; + if($file === false || !is_file($file)) return false; static $includedFiles = array(); if(!isset($includedFiles[$file])) @@ -247,11 +248,11 @@ class baseHelper * @access public * @return string the string like IN('a', 'b'). */ - static public function dbIN($idList) + static public function dbIN(string|array $idList) { if(is_array($idList)) { - foreach($idList as $key=>$value) $idList[$key] = addslashes($value); + foreach($idList as $key=>$value) $idList[$key] = addslashes((string) $value); return "IN ('" . join("','", $idList) . "')"; } @@ -321,7 +322,7 @@ class baseHelper $iv = str_repeat("\0", 8); if(function_exists('mcrypt_encrypt')) { - $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_DES, substr($secret, 0, 8), $password, MCRYPT_MODE_CBC, $iv)); + $encrypted = base64_encode((string) mcrypt_encrypt(MCRYPT_DES, substr((string) $secret, 0, 8), $password, MCRYPT_MODE_CBC, $iv)); } elseif(function_exists('openssl_encrypt')) { @@ -329,7 +330,7 @@ class baseHelper $oversize = strlen($password) % 8; if($oversize != 0) $password .= str_repeat("\0", 8 - $oversize); - $encrypted = openssl_encrypt($password, 'DES-CBC', substr($secret, 0, 8), OPENSSL_ZERO_PADDING, $iv); + $encrypted = openssl_encrypt($password, 'DES-CBC', substr((string) $secret, 0, 8), OPENSSL_ZERO_PADDING, $iv); } } if(empty($encrypted)) $encrypted = $password; @@ -356,11 +357,11 @@ class baseHelper $iv = str_repeat("\0", 8); if(function_exists('mcrypt_decrypt')) { - $decryptedPassword = trim(mcrypt_decrypt(MCRYPT_DES, substr($secret, 0, 8), base64_decode($password), MCRYPT_MODE_CBC, $iv)); + $decryptedPassword = trim((string) mcrypt_decrypt(MCRYPT_DES, substr((string) $secret, 0, 8), base64_decode($password), MCRYPT_MODE_CBC, $iv)); } elseif(function_exists('openssl_decrypt')) { - $decryptedPassword = trim(openssl_decrypt($password, 'DES-CBC', substr($secret, 0, 8), OPENSSL_ZERO_PADDING, $iv)); + $decryptedPassword = trim(openssl_decrypt($password, 'DES-CBC', substr((string) $secret, 0, 8), OPENSSL_ZERO_PADDING, $iv)); } /* Check decrypted password. Judge whether there is garbled code. */ @@ -465,24 +466,24 @@ class baseHelper $agent = $_SERVER["HTTP_USER_AGENT"]; /* Chrome should check before safari.*/ - if(strpos($agent, 'Firefox') !== false) $browser['name'] = "firefox"; - if(strpos($agent, 'Opera') !== false) $browser['name'] = 'opera'; - if(strpos($agent, 'Safari') !== false) $browser['name'] = 'safari'; - if(strpos($agent, 'Chrome') !== false) $browser['name'] = "chrome"; + if(str_contains((string) $agent, 'Firefox')) $browser['name'] = "firefox"; + if(str_contains((string) $agent, 'Opera')) $browser['name'] = 'opera'; + if(str_contains((string) $agent, 'Safari')) $browser['name'] = 'safari'; + if(str_contains((string) $agent, 'Chrome')) $browser['name'] = "chrome"; // Check the name of browser - if(strpos($agent, 'MSIE') !== false || strpos($agent, 'rv:11.0')) $browser['name'] = 'ie'; - if(strpos($agent, 'Edge') !== false) $browser['name'] = 'edge'; + if(str_contains((string) $agent, 'MSIE') || strpos((string) $agent, 'rv:11.0')) $browser['name'] = 'ie'; + if(str_contains((string) $agent, 'Edge')) $browser['name'] = 'edge'; // Check the version of browser - if(preg_match('/MSIE\s(\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1]; - if(preg_match('/FireFox\/(\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1]; - if(preg_match('/Opera[\s|\/](\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1]; - if(preg_match('/Chrome\/(\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1]; + if(preg_match('/MSIE\s(\d+)\..*/i', (string) $agent, $regs)) $browser['version'] = $regs[1]; + if(preg_match('/FireFox\/(\d+)\..*/i', (string) $agent, $regs)) $browser['version'] = $regs[1]; + if(preg_match('/Opera[\s|\/](\d+)\..*/i', (string) $agent, $regs)) $browser['version'] = $regs[1]; + if(preg_match('/Chrome\/(\d+)\..*/i', (string) $agent, $regs)) $browser['version'] = $regs[1]; - if((strpos($agent, 'Chrome') == false) && preg_match('/Safari\/(\d+)\..*$/i', $agent, $regs)) $browser['version'] = $regs[1]; - if(preg_match('/rv:(\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1]; - if(preg_match('/Edge\/(\d+)\..*/i', $agent, $regs)) $browser['version'] = $regs[1]; + if((!str_contains((string) $agent, 'Chrome')) && preg_match('/Safari\/(\d+)\..*$/i', (string) $agent, $regs)) $browser['version'] = $regs[1]; + if(preg_match('/rv:(\d+)\..*/i', (string) $agent, $regs)) $browser['version'] = $regs[1]; + if(preg_match('/Edge\/(\d+)\..*/i', (string) $agent, $regs)) $browser['version'] = $regs[1]; return $browser; } @@ -525,7 +526,7 @@ class baseHelper foreach ($osList as $regex => $value) { - if(preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) return $value; + if(preg_match($regex, (string) $_SERVER['HTTP_USER_AGENT'])) return $value; } return 'unknown'; @@ -611,6 +612,9 @@ class baseHelper $files = array(); $dir = realpath($dir); + + if($dir === false) return array(); + if(is_dir($dir)) $files = glob($dir . DIRECTORY_SEPARATOR . '*' . $pattern); return empty($files) ? array() : $files; } @@ -649,7 +653,7 @@ class baseHelper global $config; /* 去除域名中的端口部分。Remove the port part of the domain. */ - if(strpos($domain, ':') !== false) $domain = substr($domain, 0, strpos($domain, ':')); + if(str_contains($domain, ':')) $domain = substr($domain, 0, strpos($domain, ':')); $domain = strtolower($domain); /* $config里面有定义或者是localhost,直接返回。 Return directly if defined in $config or is localhost. */ @@ -662,15 +666,15 @@ class baseHelper /* 类似a.com的形式。 Domain like a.com. */ $postfix = str_replace($items[0] . '.', '', $domain); - if(isset($config->domainPostfix) and strpos($config->domainPostfix, "|$postfix|") !== false) return $items[0]; + if(isset($config->domainPostfix) and str_contains((string) $config->domainPostfix, "|$postfix|")) return $items[0]; /* 类似www.a.com的形式。 Domain like www.a.com. */ $postfix = str_replace($items[0] . '.' . $items[1] . '.', '', $domain); - if(isset($config->domainPostfix) and strpos($config->domainPostfix, "|$postfix|") !== false) return $items[1]; + if(isset($config->domainPostfix) and str_contains((string) $config->domainPostfix, "|$postfix|")) return $items[1]; /* 类似xxx.sub.a.com的形式。 Domain like xxx.sub.a.com. */ $postfix = str_replace($items[0] . '.' . $items[1] . '.' . $items[2] . '.', '', $domain); - if(isset($config->domainPostfix) and strpos($config->domainPostfix, "|$postfix|") !== false) return $items[0]; + if(isset($config->domainPostfix) and str_contains((string) $config->domainPostfix, "|$postfix|")) return $items[0]; return ''; } @@ -698,7 +702,7 @@ class baseHelper * @access public * @return void */ - public static function header301($locate) + public static function header301($locate): never { header('HTTP/1.1 301 Moved Permanently'); die(header('Location:' . $locate)); @@ -736,7 +740,7 @@ class baseHelper */ public static function restartSession($sessionID = '') { - if(empty($sessionID)) $sessionID = sha1(mt_rand()); + if(empty($sessionID)) $sessionID = sha1(random_int(0, mt_getrandmax())); session_write_close(); session_id($sessionID); @@ -744,12 +748,12 @@ class baseHelper { $ztSessionHandler = new ztSessionHandler($_GET['tid']); session_set_save_handler( - array($ztSessionHandler, "open"), - array($ztSessionHandler, "close"), - array($ztSessionHandler, "read"), - array($ztSessionHandler, "write"), - array($ztSessionHandler, "destroy"), - array($ztSessionHandler, "gc") + $ztSessionHandler->open(...), + $ztSessionHandler->close(...), + $ztSessionHandler->read(...), + $ztSessionHandler->write(...), + $ztSessionHandler->destroy(...), + $ztSessionHandler->gc(...) ); register_shutdown_function('session_write_close'); } @@ -774,7 +778,7 @@ class baseHelper $errorMsg = $errorInfo[2]; $message = $exception->getMessage(); - if(strpos($repairCode, "|$errorCode|") !== false or ($errorCode == '1016' and strpos($errorMsg, 'errno: 145') !== false) or strpos($message, 'repair') !== false) + if(str_contains($repairCode, "|$errorCode|") or ($errorCode == '1016' and str_contains((string) $errorMsg, 'errno: 145')) or str_contains((string) $message, 'repair')) { if(isset($config->framework->autoRepairTable) and $config->framework->autoRepairTable) { @@ -799,7 +803,7 @@ class baseHelper * @param string $viewType * @return string the link string. */ -function inLink($methodName = 'index', $vars = '', $viewType = '', $onlybody = false) +function inLink($methodName = 'index', string|array $vars = '', $viewType = '', $onlybody = false) { global $app; return helper::createLink($app->getModuleName(), $methodName, $vars, $viewType, $onlybody); @@ -829,7 +833,7 @@ function cycle($items) */ function getTime() { - list($usec, $sec) = explode(" ", microtime()); + [$usec, $sec] = explode(" ", microtime()); return ((float)$usec + (float)$sec); } @@ -837,7 +841,6 @@ function getTime() * 打印变量的信息 * dump a var. * - * @param mixed $var * @access public * @return void */ @@ -861,7 +864,7 @@ function isLocalIP() if(isset($config->islocalIP)) return $config->isLocalIP; $serverIP = $_SERVER['SERVER_ADDR']; if($serverIP == '127.0.0.1' or $serverIP == '::1') return true; - if(strpos($serverIP, '10.70') !== false) return false; + if(str_contains((string) $serverIP, '10.70')) return false; return !filter_var($serverIP, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE); } @@ -880,19 +883,19 @@ function getWebRoot($full = false) { if(isset($_SERVER['argv'][1])) { - $url = parse_url($_SERVER['argv'][1]); + $url = parse_url((string) $_SERVER['argv'][1]); $path = empty($url['path']) ? '/' : rtrim($url['path'], '/'); } - $path = empty($path) ? '/' : preg_replace('/\/www$/', '/www/', $path); + $path = empty($path) ? '/' : preg_replace('/\/www$/', '/www/', (string) $path); } if($full) { - $http = (isset($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? 'https://' : 'http://'; - return $http . $_SERVER['HTTP_HOST'] . substr($path, 0, (strrpos($path, '/') + 1)); + $http = (isset($_SERVER['HTTPS']) and strtolower((string) $_SERVER['HTTPS']) != 'off') ? 'https://' : 'http://'; + return $http . $_SERVER['HTTP_HOST'] . substr((string) $path, 0, (strrpos((string) $path, '/') + 1)); } - $path = substr($path, 0, (strrpos($path, '/') + 1)); + $path = substr((string) $path, 0, (strrpos((string) $path, '/') + 1)); $path = str_replace('\\', '/', $path); return $path; } @@ -902,13 +905,12 @@ function getWebRoot($full = false) * When the $var has the $key, return it, else result one default value. * * @param array|object $var - * @param string|int $key * @param mixed $valueWhenNone value when the key not exits. * @param mixed $valueWhenExists value when the key exits. * @access public * @return mixed */ -function zget($var, $key, $valueWhenNone = false, $valueWhenExists = false) +function zget($var, string|int $key, $valueWhenNone = false, $valueWhenExists = false) { if(!is_array($var) and !is_object($var)) return false; @@ -933,9 +935,9 @@ function zget($var, $key, $valueWhenNone = false, $valueWhenExists = false) */ function isHttps() { - if(!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') return true; + if(!empty($_SERVER['HTTPS']) && strtolower((string) $_SERVER['HTTPS']) !== 'off') return true; if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') return true; - if(!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') return true; + if(!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower((string) $_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') return true; return false; } @@ -1010,7 +1012,7 @@ if (!function_exists('getallheaders')) { $headers = array(); foreach ($_SERVER as $name => $value) { - if (substr($name, 0, 5) == 'HTTP_') + if (str_starts_with($name, 'HTTP_')) { $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; } diff --git a/framework/base/model.class.php b/framework/base/model.class.php index 936bde692b..96bba0653a 100644 --- a/framework/base/model.class.php +++ b/framework/base/model.class.php @@ -1,4 +1,4 @@ -app = $app; @@ -156,7 +156,7 @@ class baseModel * Load the tao file auto. */ $taoClass = $moduleName . 'Tao'; - $selfClass = get_class($this); + $selfClass = static::class; $parentClasses = class_parents($this); if($selfClass != $taoClass && !isset($parentClasses[$taoClass])) $this->loadTao($moduleName, $this->appName); } @@ -177,9 +177,9 @@ class baseModel * @access public * @return string the module name. */ - public function getModuleName() + public function getModuleName(): string { - $className = get_class($this); + $className = static::class; $parentClasses = class_parents($this); if(count($parentClasses) > 2) $className = current(array_slice($parentClasses, -3, 1)); if(strtolower(substr($className, -5)) == 'model') $className = strtolower(substr($className, 0, strlen($className) - 5)); @@ -213,7 +213,7 @@ class baseModel * @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 = ''): object|bool { $model = $this->app->loadTarget($moduleName, $appName); if(!$model) return false; @@ -233,7 +233,7 @@ class baseModel * @access public * @return object|bool 如果没有tao文件,返回false,否则返回tao对象。If no tao file, return false, else return the tao object. */ - public function loadTao($moduleName, $appName = '') + public function loadTao(string $moduleName, string $appName = ''): object|bool { $tao = $this->app->loadTarget($moduleName, $appName, 'tao'); if(!$tao) return false; @@ -259,9 +259,9 @@ class baseModel * @param string $extensionName * @param string $moduleName * @access public - * @return void + * @return mixed */ - public function loadExtension($extensionName, $moduleName = '') + public function loadExtension(string $extensionName, string $moduleName = ''): mixed { if(empty($extensionName)) return false; if(empty($moduleName)) $moduleName = $this->getModuleName(); @@ -270,7 +270,7 @@ class baseModel $extensionName = strtolower($extensionName); $type = 'model'; - $className = strtolower(get_class($this)); + $className = strtolower(static::class); if($className == $moduleName . 'tao' || $className == 'ext' . $moduleName . 'tao') $type = 'tao'; /* 设置扩展类的名字。Set the extension class name. */ diff --git a/framework/base/router.class.php b/framework/base/router.class.php index 70a7550b9a..c01957bff7 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -1,4 +1,4 @@ -setPathFix(); $this->setBasePath(); @@ -391,6 +391,7 @@ class baseRouter $this->loadClass('front', $static = true); $this->loadClass('filter', $static = true); + $this->loadClass('form', $static = true); $this->loadClass('dbh', $static = true); $this->loadClass('dao', $static = true); $this->loadClass('mobile', $static = true); @@ -428,9 +429,9 @@ class baseRouter * @access public * @return static the app object */ - public static function createApp($appName = 'demo', $appRoot = '', $className = '') + public static function createApp(string $appName = 'demo', string $appRoot = '', string $className = '') { - if(empty($className)) $className = __CLASS__; + if(empty($className)) $className = self::class; return new $className($appName, $appRoot); } @@ -444,7 +445,7 @@ class baseRouter * @access public * @return void */ - public function setAppName($appName) + public function setAppName(string $appName) { $this->appName = $appName; } @@ -470,7 +471,7 @@ class baseRouter */ public function setBasePath() { - $this->basePath = realpath(dirname(dirname(dirname(__FILE__)))) . DS; + $this->basePath = realpath(dirname(__FILE__, 3)) . DS; } /** @@ -506,7 +507,7 @@ class baseRouter * @access public * @return void */ - public function setAppRoot($appName = 'demo', $appRoot = '') + public function setAppRoot(string $appName = 'demo', string $appRoot = '') { if(empty($appRoot)) $this->appRoot = $this->basePath . 'app' . DS . $appName . DS; if(!empty($appRoot)) $this->appRoot = realpath($appRoot) . DS; @@ -582,7 +583,7 @@ class baseRouter */ public function setWwwRoot() { - $this->wwwRoot = rtrim(dirname($_SERVER['SCRIPT_FILENAME']), DS) . DS; + $this->wwwRoot = rtrim(dirname((string) $_SERVER['SCRIPT_FILENAME']), DS) . DS; } /** @@ -621,9 +622,9 @@ class baseRouter if(isset($_SERVER['REQUEST_URI'])) { $URI = $_SERVER['REQUEST_URI']; - if(strpos($URI, '?') !== false) + if(str_contains((string) $URI, '?')) { - $parsedURL = parse_url($URI); + $parsedURL = parse_url((string) $URI); if(isset($parsedURL['query'])) { parse_str($parsedURL['query'], $parsedQuery); @@ -647,12 +648,12 @@ class baseRouter if($this->config->framework->filterCSRF) { $httpType = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') ? 'https' : 'http'; - if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') $httpType = 'https'; - if(isset($_SERVER['REQUEST_SCHEME']) and strtolower($_SERVER['REQUEST_SCHEME']) == 'https') $httpType = 'https'; + if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and strtolower((string) $_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') $httpType = 'https'; + if(isset($_SERVER['REQUEST_SCHEME']) and strtolower((string) $_SERVER['REQUEST_SCHEME']) == 'https') $httpType = 'https'; $httpHost = zget($_SERVER, 'HTTP_HOST', ''); $apiMode = (defined('RUN_MODE') && RUN_MODE == 'api') || isset($_GET[$this->config->sessionVar]); - if(!$apiMode && (empty($httpHost) or strpos($this->server->http_referer, "$httpType://$httpHost") !== 0)) $_FILES = $_POST = array(); + if(!$apiMode && (empty($httpHost) or !str_starts_with((string) $this->server->http_referer, "$httpType://$httpHost"))) $_FILES = $_POST = array(); } $_FILES = validater::filterFiles(); @@ -710,7 +711,7 @@ class baseRouter { if(isset($this->config->edition)) return $this->config->edition; - $edition = substr($this->config->version, 0, 3); + $edition = substr((string) $this->config->version, 0, 3); if(in_array($edition, array('pro', 'biz', 'max'))) return $this->config->edition = $edition; $this->config->edition = 'open'; } @@ -739,16 +740,16 @@ class baseRouter $user = $this->dbh->query("SELECT * FROM " . TABLE_USER . " WHERE account = $account AND deleted = '0' LIMIT 1")->fetch(); if(!empty($user->visions)) { - $userVisions = explode(',', $user->visions); + $userVisions = explode(',', (string) $user->visions); if(!in_array($vision, $userVisions)) $vision = ''; - if(empty($vision)) list($vision) = $userVisions; + if(empty($vision)) [$vision] = $userVisions; } } - list($defaultVision) = explode(',', trim($this->config->visions, ',')); - if($vision and strpos($this->config->visions, ",{$vision},") === false) $vision = $defaultVision; + [$defaultVision] = explode(',', trim((string) $this->config->visions, ',')); + if($vision and !str_contains((string) $this->config->visions, ",{$vision},")) $vision = $defaultVision; - $this->config->vision = $vision ? $vision : $defaultVision; + $this->config->vision = $vision ?: $defaultVision; } /** @@ -774,7 +775,7 @@ class baseRouter */ public function setErrorHandler() { - set_error_handler(array($this, 'saveError')); + set_error_handler($this->saveError(...)); register_shutdown_function(array($this, 'shutdown')); } @@ -1001,12 +1002,12 @@ class baseRouter { $ztSessionHandler = new ztSessionHandler($_GET['tid']); session_set_save_handler( - array($ztSessionHandler, "open"), - array($ztSessionHandler, "close"), - array($ztSessionHandler, "read"), - array($ztSessionHandler, "write"), - array($ztSessionHandler, "destroy"), - array($ztSessionHandler, "gc") + $ztSessionHandler->open(...), + $ztSessionHandler->close(...), + $ztSessionHandler->read(...), + $ztSessionHandler->write(...), + $ztSessionHandler->destroy(...), + $ztSessionHandler->gc(...) ); } } @@ -1044,7 +1045,7 @@ class baseRouter $module = $this->rawModule; $this->tab = 'my'; if(isset($this->lang->navGroup)) $this->tab = zget($this->lang->navGroup, $module, 'my'); - if(isset($_COOKIE['tab']) and $_COOKIE['tab'] and preg_match('/^\w+$/', $_COOKIE['tab'])) $this->tab = $_COOKIE['tab']; + if(isset($_COOKIE['tab']) and $_COOKIE['tab'] and preg_match('/^\w+$/', (string) $_COOKIE['tab'])) $this->tab = $_COOKIE['tab']; } /** @@ -1075,7 +1076,7 @@ class baseRouter $this->clientLang = $this->config->default->lang; } - setcookie('lang', $this->clientLang, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, false); + setcookie('lang', (string) $this->clientLang, array('expires' => $this->config->cookieLife, 'path' => (string) $this->config->webRoot, 'domain' => '', 'secure' => $this->config->cookieSecure, 'httponly' => false)); if(!isset($_COOKIE['lang'])) $_COOKIE['lang'] = $this->clientLang; return true; @@ -1093,12 +1094,12 @@ class baseRouter if(empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) return ''; $raw = $_SERVER['HTTP_ACCEPT_LANGUAGE']; - $pos = strpos($raw, ','); - $lang = $pos === false ? $raw : substr($raw, 0, $pos); + $pos = strpos((string) $raw, ','); + $lang = $pos === false ? $raw : substr((string) $raw, 0, $pos); /* Fix clientLang for ie >= 10. https://www.drupal.org/node/365615. */ - if(stripos($lang, 'hans')) $lang = 'zh-cn'; - if(stripos($lang, 'hant')) $lang = 'zh-tw'; + if(stripos((string) $lang, 'hans')) $lang = 'zh-cn'; + if(stripos((string) $lang, 'hant')) $lang = 'zh-tw'; return $lang; } @@ -1129,7 +1130,7 @@ class baseRouter $this->clientTheme = $this->config->default->theme; } - setcookie('theme', $this->clientTheme, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, false); + setcookie('theme', (string) $this->clientTheme, array('expires' => $this->config->cookieLife, 'path' => (string) $this->config->webRoot, 'domain' => '', 'secure' => $this->config->cookieSecure, 'httponly' => false)); if(!isset($_COOKIE['theme'])) $_COOKIE['theme'] = $this->clientTheme; return true; @@ -1149,13 +1150,13 @@ class baseRouter if($this->cookie->device == 'mobile') $this->clientDevice = 'mobile'; if($this->cookie->device == 'desktop') $this->clientDevice = 'desktop'; - if(empty($this->cookie->device) || strpos('mobile,desktop', $this->cookie->device) === false) + if(empty($this->cookie->device) || !str_contains('mobile,desktop', (string) $this->cookie->device)) { $mobile = new mobile(); $this->clientDevice = ($mobile->isMobile() and !$mobile->isTablet()) ? 'mobile' : 'desktop'; } - setcookie('device', $this->clientDevice, $this->config->cookieLife, $this->config->webRoot, '', $this->config->cookieSecure, true); + setcookie('device', $this->clientDevice, array('expires' => $this->config->cookieLife, 'path' => (string) $this->config->webRoot, 'domain' => '', 'secure' => $this->config->cookieSecure, 'httponly' => true)); if(!isset($_COOKIE['device'])) $_COOKIE['device'] = $this->clientDevice; return $this->clientDevice; @@ -1253,7 +1254,7 @@ class baseRouter { $this->URI = substr($pathInfo, 0, $dotPos); $this->viewType = substr($pathInfo, $dotPos + 1); - if(strpos($this->config->views, ',' . $this->viewType . ',') === false) + if(!str_contains((string) $this->config->views, ',' . $this->viewType . ',')) { $this->viewType = $this->config->default->view; } @@ -1293,9 +1294,9 @@ class baseRouter elseif(isset($this->URI)) { $value = $this->URI; - $subpath = str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME'])); + $subpath = str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname((string) $_SERVER['SCRIPT_FILENAME'])); if($subpath != '/') $subpath = '/' . $subpath; - if($subpath != '' and $subpath != '/' and strpos($value, $subpath) === 0) $value = substr($value, strlen($subpath)); + if($subpath != '' and $subpath != '/' and str_starts_with($value, $subpath)) $value = substr($value, strlen($subpath)); } else { @@ -1303,12 +1304,12 @@ class baseRouter if(empty($value)) $value = @getenv('ORIG_PATH_INFO'); } - if(strpos($value, $_SERVER['SCRIPT_NAME']) !== false) $value = str_replace($_SERVER['SCRIPT_NAME'], '', $value); - if(strpos($value, '?') === false) return trim($value, '/'); + if(str_contains((string) $value, (string) $_SERVER['SCRIPT_NAME'])) $value = str_replace($_SERVER['SCRIPT_NAME'], '', (string) $value); + if(!str_contains((string) $value, '?')) return trim((string) $value, '/'); - $value = parse_url($value); - $pathInfo = trim(zget($value, 'path', ''), '/'); - if(trim($pathInfo, '/') == trim($this->config->webRoot, '/')) $pathInfo = ''; + $value = parse_url((string) $value); + $pathInfo = trim((string) zget($value, 'path', ''), '/'); + if(trim($pathInfo, '/') == trim((string) $this->config->webRoot, '/')) $pathInfo = ''; return $pathInfo; } @@ -1325,7 +1326,7 @@ class baseRouter if(isset($_GET[$this->config->viewVar])) { $this->viewType = $_GET[$this->config->viewVar]; - if(strpos($this->config->views, ',' . $this->viewType . ',') === false) $this->viewType = $this->config->default->view; + if(!str_contains((string) $this->config->views, ',' . $this->viewType . ',')) $this->viewType = $this->config->default->view; } else { @@ -1382,7 +1383,7 @@ class baseRouter * @access public * @return object|bool the common model object or false if not exits. */ - public function loadCommon() + public function loadCommon(): object|bool { $this->setModuleName('common'); $commonModelFile = $this->setModelFile('common'); @@ -1405,7 +1406,7 @@ class baseRouter * @access public * @return void */ - public function setModuleName($moduleName = '') + public function setModuleName(string $moduleName = '') { if($this->checkModuleName($moduleName)) $this->moduleName = strtolower($moduleName); } @@ -1420,7 +1421,7 @@ class baseRouter * @access public * @return bool */ - public function setControlFile($exitIfNone = true) + public function setControlFile(bool $exitIfNone = true) { $this->controlFile = $this->getModulePath() . 'control.php'; if(file_exists($this->controlFile)) return true; @@ -1435,7 +1436,7 @@ class baseRouter * @access public * @return void */ - public function setMethodName($methodName = '') + public function setMethodName(string $methodName = '') { if($this->checkMethodName($methodName)) $this->methodName = strtolower($methodName); } @@ -1475,13 +1476,13 @@ class baseRouter /* Check file is encode by ioncube. */ $isEncrypted = false; - if(strpos($file2Included, 'extension' . DS . $this->config->edition . DS) !== false) + if(str_contains($file2Included, 'extension' . DS . $this->config->edition . DS)) { $fp = fopen($file2Included, 'r'); $line1 = fgets($fp); $line2 = fgets($fp); fclose($fp); - if(strpos($line1, 'moduleName; $moduleName = strtolower($moduleName); @@ -1631,7 +1632,7 @@ class baseRouter * @access public * @return string the extension path. */ - public function getModuleExtPath($appName, $moduleName, $ext) + public function getModuleExtPath(string $appName, string $moduleName, string $ext) { $saasExtPath = $this->getExtensionRoot() . 'saas' . DS . $moduleName . DS . 'ext' . DS . $ext . DS; @@ -1666,7 +1667,7 @@ class baseRouter * @access public * @return bool */ - public function checkModuleName($var, $exit = true) + public function checkModuleName(string $var, bool $exit = true) { global $filter; static $checkedModule = array(); @@ -1689,7 +1690,7 @@ class baseRouter * @access public * @return bool */ - public function checkMethodName($var, $exit = true) + public function checkMethodName(string $var, bool $exit = true) { global $filter; $rule = $filter->default->methodName; @@ -1784,7 +1785,7 @@ class baseRouter * @access public * @return string the model file */ - public function setModelFile($moduleName, $appName = '') + public function setModelFile(string $moduleName, string $appName = '') { return $this->setTargetFile($moduleName, $appName); } @@ -1799,7 +1800,7 @@ class baseRouter * @access public * @return string the target file */ - public function setTargetFile($moduleName, $appName = '', $class = 'model') + public function setTargetFile(string $moduleName, string $appName = '', string $class = 'model') { if($appName == '') $appName = $this->getAppName(); @@ -1856,12 +1857,12 @@ class baseRouter * @param array $extFiles * @param array $hookFiles * @param array $apiFiles - * @param string $targetExtPaths + * @param array $targetExtPaths * @param string $mainTargetFile * @access public * @return bool */ - public function needTargetFileUpdate($mergedTargetFile, $extFiles, $hookFiles, $apiFiles, $targetExtPaths, $mainTargetFile) + public function needTargetFileUpdate(string $mergedTargetFile, array $extFiles, array $hookFiles, array $apiFiles, array $targetExtPaths, string $mainTargetFile) { $lastTime = file_exists($mergedTargetFile) ? filemtime($mergedTargetFile) : 0; @@ -1897,7 +1898,7 @@ class baseRouter * @access public * @return void */ - public function mergeTargetExtFiles($moduleName, $extFiles, $mergedTargetDir, $class = 'model') + public function mergeTargetExtFiles(string $moduleName, array $extFiles, string $mergedTargetDir, string $class = 'model') { /* 设置类名。Set the class names. */ $targetClass = $moduleName . ucfirst($class); @@ -1911,7 +1912,7 @@ class baseRouter /* 将扩展文件的代码合并到代码中。Cycle all the extension files and merge them into target lines. */ $extTargets = array(); - foreach($extFiles as $extFile) $extTargets[basename($extFile)] = $extFile; + foreach($extFiles as $extFile) $extTargets[basename((string) $extFile)] = $extFile; foreach($extTargets as $extTarget) $targetLines .= self::removePHPTAG($extTarget); /* 做个标记,方便后面替换代码使用。Make a mark for replacing codes. */ @@ -1943,7 +1944,7 @@ class baseRouter * @access public * @return void */ - public function mergeTargetHookFiles($moduleName, $mainTargetFile, $targetLines, $hookFiles, $mergedTargetDir, $mergedTargetFile, $apiFiles, $class = 'model') + public function mergeTargetHookFiles(string $moduleName, string $mainTargetFile, string $targetLines, array $hookFiles, string $mergedTargetDir, string $mergedTargetFile, array $apiFiles, string $class = 'model') { /* 定义相关变量。Init vars. */ $targetClass = $moduleName . ucfirst($class); @@ -1957,8 +1958,8 @@ class baseRouter foreach($apiFiles as $apiFile) { /* 通过文件名获得其对应的方法名。Get methods according it's filename. */ - $fileName = baseName($apiFile); - list($method) = explode('.', $fileName); + $fileName = baseName((string) $apiFile); + [$method] = explode('.', $fileName); $url = self::extractAPIURL($apiFile); if($url) $hookCodes[$method][] = "return helper::requestAPI('$url');"; @@ -1966,8 +1967,8 @@ class baseRouter foreach($hookFiles as $hookFile) { /* 通过文件名获得其对应的方法名。Get methods according it's filename. */ - $fileName = baseName($hookFile); - list($method) = explode('.', $fileName); + $fileName = baseName((string) $hookFile); + [$method] = explode('.', $fileName); $hookCodes[$method][] = self::removePHPTAG($hookFile); } @@ -2008,10 +2009,11 @@ class baseRouter * @access public * @return string */ - static public function removePHPTAG($fileName) + static public function removePHPTAG(string $fileName): string { $code = trim(file_get_contents($fileName)); - if(strpos($code, '') !== false) $code = rtrim($code, '?' . '>'); return trim($code); } @@ -2024,7 +2026,7 @@ class baseRouter * @access public * @return string */ - static public function extractAPIURL($fileName) + static public function extractAPIURL(string $fileName): string { global $config; @@ -2032,7 +2034,7 @@ class baseRouter $lines = file($fileName); foreach($lines as $line) { - $line = trim($line); + $line = trim((string) $line); if(empty($line)) continue; if(preg_match('/^https?\:\/\//', $line)) @@ -2052,8 +2054,10 @@ class baseRouter * @access public * @return void */ - public function sendAPI($apiFile) + public function sendAPI(string $apiFile) { + $css = null; + $js = null; $extension = substr($apiFile, strrpos($apiFile, '.') + 1); if($extension != '302' and $extension != 'api') return false; @@ -2061,7 +2065,7 @@ class baseRouter $url = ''; foreach($lines as $line) { - $line = trim($line); + $line = trim((string) $line); if(empty($line)) continue; if(preg_match('/^https?\:\/\//', $line)) @@ -2072,7 +2076,7 @@ class baseRouter } if(empty($url)) return false; - $url .= (strpos($url, '?') !== false ? '&' : '?') . $this->config->sessionVar . '=' . session_id() . '&account=' . $_SESSION['user']->account; + $url .= (str_contains($url, '?') ? '&' : '?') . $this->config->sessionVar . '=' . session_id() . '&account=' . $_SESSION['user']->account; if($extension == '302') { header("location: $url"); @@ -2126,7 +2130,7 @@ class baseRouter * 根据$requestFix分割符,分割网址。 * There's the request separator, split the URI by it. **/ - if(strpos($this->URI, $this->config->requestFix) !== false) + if(str_contains($this->URI, (string) $this->config->requestFix)) { $items = explode($this->config->requestFix, $this->URI); $this->setModuleName($items[0]); @@ -2166,8 +2170,8 @@ class baseRouter */ public function setRouteByGET() { - $moduleName = isset($_GET[$this->config->moduleVar]) ? strtolower($_GET[$this->config->moduleVar]) : $this->config->default->module; - $methodName = isset($_GET[$this->config->methodVar]) ? strtolower($_GET[$this->config->methodVar]) : $this->config->default->method; + $moduleName = isset($_GET[$this->config->moduleVar]) ? strtolower((string) $_GET[$this->config->moduleVar]) : $this->config->default->module; + $methodName = isset($_GET[$this->config->methodVar]) ? strtolower((string) $_GET[$this->config->methodVar]) : $this->config->default->method; $this->setModuleName($moduleName); $this->setMethodName($methodName); $this->setControlFile(); @@ -2204,7 +2208,7 @@ class baseRouter echo $endResponseException->getContent(); } - return isset($module) ? $module : false; + return $module ?? false; } /** @@ -2217,7 +2221,7 @@ class baseRouter * @access public * @return object|bool 如果没有model文件,返回false,否则返回model对象。If no model file, return false, else return the model object. */ - public function loadTarget($moduleName = '', $appName = '', $class = 'model') + public function loadTarget(string $moduleName = '', string $appName = '', string $class = 'model'): object|bool { if(empty($moduleName)) $moduleName = $this->moduleName; if(empty($appName)) $appName = $this->appName; @@ -2267,7 +2271,7 @@ class baseRouter * @access public * @return void */ - public function setParamsByPathInfo($defaultParams = array(), $type = '') + public function setParamsByPathInfo(array $defaultParams = array(), string $type = '') { $params = array(); if($type != 'fetch') @@ -2302,7 +2306,7 @@ class baseRouter * @access public * @return void */ - public function setParamsByGET($defaultParams, $type = '') + public function setParamsByGET(array $defaultParams, string $type = '') { $params = array(); if($type != 'fetch') @@ -2331,7 +2335,7 @@ class baseRouter * @access public * @return array the merged params. */ - public function mergeParams($defaultParams, $passedParams) + public function mergeParams(array $defaultParams, array $passedParams) { global $filter; @@ -2341,7 +2345,7 @@ class baseRouter unset($passedParams['HTTP_X_REQUESTED_WITH']); /* Check params from URL. */ - $nameRule = isset($filter->{$this->moduleName}->{$this->methodName}->paramName) ? $filter->{$this->moduleName}->{$this->methodName}->paramName : $filter->default->paramName; + $nameRule = $filter->{$this->moduleName}->{$this->methodName}->paramName ?? $filter->default->paramName; foreach($passedParams as $param => $value) { if(!validater::checkByRule($param, $nameRule)) die('Bad Request!'); @@ -2360,7 +2364,7 @@ class baseRouter { if(isset($passedParams[$i])) { - $defaultParams[$key] = strip_tags($passedParams[$i]); + $defaultParams[$key] = strip_tags((string) $passedParams[$i]); } else { @@ -2432,7 +2436,7 @@ class baseRouter * @access public * @return object|bool the instance of the class or just true. */ - public function loadClass($className, $static = false) + public function loadClass(string $className, bool $static = false): object|bool { $className = strtolower($className); @@ -2446,10 +2450,10 @@ class baseRouter if($static) return true; /* 实例化该类(Instance it) */ - global $$className; + global ${$className}; if(!class_exists($className)) $this->triggerError("the class $className not found in $classFile", __FILE__, __LINE__, $exit = true); - if(!is_object($$className)) $$className = new $className(); - return $$className; + if(!is_object(${$className})) ${$className} = new $className(); + return ${$className}; } /** @@ -2501,7 +2505,7 @@ class baseRouter * @access public * @return void */ - public function loadModuleConfig($moduleName, $appName = '') + public function loadModuleConfig(string $moduleName, string $appName = '') { global $config; @@ -2536,7 +2540,7 @@ class baseRouter * @access public * @return void */ - public function mergeConfig($dbConfig, $moduleName = 'common') + public function mergeConfig(array $dbConfig, string $moduleName = 'common') { global $config; @@ -2585,7 +2589,7 @@ class baseRouter $view->URAndSR = zget($this->config->custom, 'URAndSR', '0'); $view->maxUploadSize = strtoupper(ini_get('upload_max_filesize')); - $this->session->set('random', mt_rand(0, 10000)); + $this->session->set('random', random_int(0, 10000)); $view->sessionName = session_name(); $view->sessionID = session_id(); $view->random = $this->session->random; @@ -2604,7 +2608,7 @@ class baseRouter * @access public * @return string. */ - private function getMainLangFile($moduleName, $appName = '') + private function getMainLangFile(string $moduleName, string $appName = '') { $path = $moduleName . DS . 'lang' . DS . $this->clientLang . '.php'; @@ -2649,7 +2653,7 @@ class baseRouter * @access public * @return bool|object the lang object or false. */ - public function loadLang($moduleName, $appName = '') + public function loadLang(string $moduleName, string $appName = ''): bool|object { /* 计算最终要加载的语言文件。 Get the lang files to be loaded. */ $langFilesToLoad = $this->getMainAndExtFiles($moduleName, $appName, 'lang'); @@ -2694,10 +2698,10 @@ class baseRouter * * @param object $params the database params. * @access public - * @return object|bool */ - public function connectByPDO($params) + public function connectByPDO(object $params): object|bool { + $dsn = null; if(!isset($params->driver)) self::triggerError('no pdo driver defined, it should be mysql or sqlite', __FILE__, __LINE__, $exit = true); if(!isset($params->user)) return false; try @@ -2771,8 +2775,9 @@ class baseRouter * @access public * @return void */ - public function triggerError($message, $file, $line, $exit = false) + public function triggerError(string $message, string $file, int $line, bool $exit = false) { + $function = null; /* 设置错误信息(Set the error info) */ $message = htmlSpecialString($message); if(preg_match('/[^\x00-\x80]/', $message)) $message = helper::convertEncoding($message, 'gbk'); @@ -2805,7 +2810,7 @@ class baseRouter * @access public * @return void */ - public function saveError($level, $message, $file, $line) + public function saveError(int $level, string $message, string $file, int $line) { if(empty($this->config->debug)) return true; if(!is_dir($this->logRoot)) return true; @@ -2815,9 +2820,9 @@ class baseRouter * 删除设定时间之前的日志。 * Delete the log before the set time. **/ - if(mt_rand(0, 10) == 1) + if(random_int(0, 10) == 1) { - $logDays = isset($this->config->framework->logDays) ? $this->config->framework->logDays : 14; + $logDays = $this->config->framework->logDays ?? 14; $dayTime = time() - $logDays * 24 * 3600; foreach(glob($this->getLogRoot() . '*') as $logFile) { @@ -2829,7 +2834,7 @@ class baseRouter * 忽略该错误:Redefining already defined constructor。 * Skip the error: Redefining already defined constructor. **/ - if(strpos($message, 'Redefining') !== false) return true; + if(str_contains($message, 'Redefining')) return true; /* * 设置错误信息。 @@ -2917,7 +2922,7 @@ class baseRouter * @access public * @return bool */ - public function isContainer() + public function isContainer(): bool { return strtolower(getenv('IS_CONTAINER')) == 'true'; } @@ -2931,8 +2936,9 @@ class baseRouter * @access public * @return array */ - public function getMainAndExtFiles($moduleName, $appName = '', $type = 'lang') + public function getMainAndExtFiles(string $moduleName, string $appName = '', string $type = 'lang') { + $clientLang = null; /* 初始化变量。Init vars. */ $modulePath = $this->getModulePath($appName, $moduleName); $extFiles = array(); @@ -2949,6 +2955,11 @@ class baseRouter } if($mainFile) $filesToLoad[] = $mainFile; + if($type == 'config') + { + $filesToLoad[] = helper::ls($modulePath . DS . 'config', '.php'); + } + /* 获取扩展文件。If extensionLevel > 0, get extension files. */ if($this->config->framework->extensionLevel > 0) { @@ -2998,7 +3009,7 @@ class config * @access public * @return void */ - public function set($key, $value) + public function set(string $key, $value) { helper::setMember('config', $key, $value); } @@ -3027,7 +3038,7 @@ class language * @access public * @return void */ - public function set($key, $value) + public function set(string $key, $value) { helper::setMember('lang', $key, $value); } @@ -3041,10 +3052,10 @@ class language * @access public * @return void */ - public function show($obj, $key) + public function show(object $obj, string $key) { $obj = (array)$obj; - echo isset($obj[$key]) ? $obj[$key] : ''; + echo $obj[$key] ?? ''; } } @@ -3064,7 +3075,7 @@ class super * @access public * @return void */ - public function __construct($scope, $tab = '') + public function __construct(string $scope, string $tab = '') { $this->scope = $scope; $this->tab = $tab; @@ -3080,7 +3091,7 @@ class super * @access public * @return void */ - public function set($key, $value, $tab = '') + public function set(string $key, $value, string $tab = '') { if($this->scope == 'post') { @@ -3121,7 +3132,7 @@ class super * @access public * @return mixed|bool return the value of the key or false. */ - public function __get($key) + public function __get(string $key) { if($this->scope == 'post') { @@ -3228,7 +3239,6 @@ class EndResponseException extends \Exception class ztSessionHandler { public $sessSavePath; - public $tagID; public $sessionFile; public $sessionID; public $rawID; @@ -3241,9 +3251,8 @@ class ztSessionHandler * @access public * @return void */ - public function __construct($tagID = '') + public function __construct(public string $tagID = '') { - $this->tagID = $tagID; ini_set('session.save_handler', 'files'); register_shutdown_function('session_write_close'); } @@ -3266,7 +3275,7 @@ class ztSessionHandler * @access public * @return string */ - public function getSessionFile($id) + public function getSessionFile(string $id): string { if(!empty($this->sessionFile)) return $this->sessionFile; @@ -3291,7 +3300,7 @@ class ztSessionHandler * @return bool */ #[\ReturnTypeWillChange] - public function open($savePath, $sessionName) + public function open(string $savePath, string $sessionName): bool { $this->sessSavePath = $savePath; return true; @@ -3304,7 +3313,7 @@ class ztSessionHandler * @return bool */ #[\ReturnTypeWillChange] - public function close() + public function close(): bool { return true; } @@ -3314,10 +3323,10 @@ class ztSessionHandler * * @param string $id * @access public - * @return bool + * @return string */ #[\ReturnTypeWillChange] - public function read($id) + public function read(string $id): string { $sessFile = $this->getSessionFile($id); if(!file_exists($sessFile)) @@ -3337,7 +3346,7 @@ class ztSessionHandler * @return bool */ #[\ReturnTypeWillChange] - public function write($id, $sessData) + public function write(string $id, string $sessData): bool { $sessFile = $this->getSessionFile($id); touch($sessFile); @@ -3346,10 +3355,10 @@ class ztSessionHandler if(file_put_contents($sessFile, $sessData, LOCK_EX)) { - if(strpos($sessData, 'user|') !== false) + if(str_contains($sessData, 'user|')) { $rawSessContent = (string) file_get_contents($this->rawFile, false, null, 0, 1024 * 2); - if(strpos($rawSessContent, 'user|') === false) file_put_contents($this->rawFile, $sessData, LOCK_EX); + if(!str_contains($rawSessContent, 'user|')) file_put_contents($this->rawFile, $sessData, LOCK_EX); } return true; @@ -3365,7 +3374,7 @@ class ztSessionHandler * @return bool */ #[\ReturnTypeWillChange] - public function destroy($id) + public function destroy(string $id): bool { $sessFile = $this->getSessionFile($id); if(file_exists($sessFile)) unlink($sessFile); @@ -3383,7 +3392,7 @@ class ztSessionHandler * @return bool */ #[\ReturnTypeWillChange] - public function gc($maxlifeTime) + public function gc(int $maxlifeTime): bool { $time = time(); foreach(glob("$this->sessSavePath/sess_*") as $fileName) diff --git a/framework/control.class.php b/framework/control.class.php index 82549c6859..323fbe1725 100644 --- a/framework/control.class.php +++ b/framework/control.class.php @@ -1,4 +1,4 @@ -config->{$this->moduleName}) and strpos($this->methodName, 'export') !== false) + if(isset($this->config->{$this->moduleName}) and str_contains((string) $this->methodName, 'export')) { if(isset($this->config->{$this->moduleName}->exportFields) or isset($this->config->{$this->moduleName}->list->exportFields)) { @@ -145,7 +145,7 @@ class control extends baseControl { foreach($labels as $label) { - $code = str_replace('browse', '', $label->code); + $code = str_replace('browse', '', (string) $label->code); $this->app->user->rights['rights'][$module][$code] = 1; } } @@ -165,7 +165,7 @@ class control extends baseControl * @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 = ''): object|bool { return parent::loadModel($moduleName); } @@ -181,7 +181,7 @@ class control extends baseControl * @access public * @return object|bool 如果没有model文件,返回false,否则返回model对象。If no model file, return false, else return the model object. */ - public function loadZen($moduleName = '', $appName = '') + public function loadZen(string $moduleName = '', string $appName = ''): object|bool { return parent::loadZen($moduleName); } @@ -204,16 +204,16 @@ class control extends baseControl * @access public * @return void */ - public function loadExtension($extensionName, $moduleName = '') + public function loadExtension(string $extensionName, string $moduleName = '') { if(empty($extensionName)) return false; if(empty($moduleName)) $moduleName = $this->moduleName; - $moduleName = strtolower($moduleName); + $moduleName = strtolower((string) $moduleName); $extensionName = strtolower($extensionName); $type = 'model'; - $className = strtolower(get_class($this)); + $className = strtolower(static::class); if($className == $moduleName . 'zen' || $className == 'ext' . $moduleName . 'zen') $type = 'zen'; /* 设置扩展类的名字。Set the extension class name. */ @@ -252,7 +252,7 @@ class control extends baseControl * @access public * @return string the view file */ - public function setViewFile($moduleName, $methodName) + public function setViewFile(string $moduleName, string $methodName) { $moduleName = strtolower(trim($moduleName)); $methodName = strtolower(trim($methodName)); @@ -309,7 +309,7 @@ class control extends baseControl $viewFile = $commonExtViewFile; } - if(!is_file($viewFile)) $viewFile = dirname(dirname($viewExtPath['common'])) . DS . 'view' . DS . $this->devicePrefix . $methodName . ".{$viewType}.php"; + if(!is_file($viewFile)) $viewFile = dirname((string) $viewExtPath['common'], 2) . DS . 'view' . DS . $this->devicePrefix . $methodName . ".{$viewType}.php"; if(!is_file($viewFile)) die(js::error($this->lang->notPage) . js::locate('back')); /* Get ext hook files. */ @@ -341,7 +341,7 @@ class control extends baseControl * @access public * @return void */ - public function parseDefault($moduleName, $methodName) + public function parseDefault(string $moduleName, string $methodName) { /** * 设置视图文件。(PHP7有一个bug,不能直接$viewFile = $this->setViewFile())。 @@ -407,7 +407,7 @@ class control extends baseControl * @access public * @return string the parsed html. */ - public function fetch($moduleName = '', $methodName = '', $params = array(), $appName = '') + public function fetch(string $moduleName = '', string $methodName = '', array|string $params = array(), string $appName = '') { if($moduleName != $this->moduleName) $this->app->fetchModule = $moduleName; @@ -418,11 +418,11 @@ class control extends baseControl * Build operate menu of a method. * * @param object $object product|project|productplan|release|build|story|task|bug|testtask|testcase|testsuite - * @param string $displayOn view|browse + * @param string $type view|browse * @access public * @return string */ - public function buildOperateMenu($object, $type = 'view') + public function buildOperateMenu(object $object, string $type = 'view') { if(!isset($this->config->bizVersion)) return false; @@ -437,7 +437,7 @@ class control extends baseControl * @access public * @return void */ - public function executeHooks($objectID) + public function executeHooks(int $objectID) { if(!isset($this->config->bizVersion)) return false; @@ -448,7 +448,6 @@ class control extends baseControl /** * Set workflow export fields * - * @param array $fields * @access public * @return array */ @@ -476,12 +475,12 @@ class control extends baseControl * @access public * @return void */ - public function printExtendFields($object, $type, $extras = '', $print = true, $moduleName = '', $methodName = '') + public function printExtendFields(object|string $object, string $type, string $extras = '', bool $print = true, string $moduleName = '', string $methodName = '') { if(!isset($this->config->bizVersion)) return false; - $moduleName = $moduleName ? $moduleName : $this->app->getModuleName(); - $methodName = $methodName ? $methodName : $this->app->getMethodName(); + $moduleName = $moduleName ?: $this->app->getModuleName(); + $methodName = $methodName ?: $this->app->getMethodName(); $fields = $this->loadModel('flow')->printFields($moduleName, $methodName, $object, $type, $extras); if(!$print) return $fields; @@ -496,7 +495,7 @@ class control extends baseControl * @access public * @return string */ - public function processStatus($module, $record) + public function processStatus(string $module, object $record) { $moduleName = $this->moduleName; @@ -508,9 +507,8 @@ class control extends baseControl * * @param string $viewFile * @access public - * @return bool|string */ - public function printViewFile($viewFile) + public function printViewFile(string $viewFile): bool|string { if(!file_exists($viewFile)) return false; @@ -558,7 +556,7 @@ class control extends baseControl if(empty($field->show)) continue; if(!isset($layouts[$field->field])) continue; - $fieldRules = explode(',', trim($field->rules, ',')); + $fieldRules = explode(',', trim((string) $field->rules, ',')); $fieldRules = array_unique($fieldRules); foreach($fieldRules as $ruleID) { @@ -570,7 +568,7 @@ class control extends baseControl { $requiredFields .= ",{$field->field}"; if($field->control == 'radio' or $field->control == 'checkbox') $mustPostFields .= ",{$field->field}"; - if(strpos($field->type, 'int') !== false and $field->control == 'select') $numberFields .= ",{$field->field}"; + if(str_contains((string) $field->type, 'int') and $field->control == 'select') $numberFields .= ",{$field->field}"; } elseif($rule->type == 'system' and isset($_POST[$field->field])) { @@ -622,11 +620,11 @@ class control extends baseControl { $message[$requiredField][] = sprintf($this->lang->error->notempty, $fields[$requiredField]->name); } - elseif(strpos(",{$numberFields},", ",{$requiredField},") !== false and empty($_POST[$requiredField])) + elseif(str_contains(",{$numberFields},", ",{$requiredField},") and empty($_POST[$requiredField])) { $message[$requiredField][] = sprintf($this->lang->error->notempty, $fields[$requiredField]->name); } - elseif(strpos(",{$mustPostFields},", ",{$requiredField},") !== false and !isset($_POST[$requiredField])) + elseif(str_contains(",{$mustPostFields},", ",{$requiredField},") and !isset($_POST[$requiredField])) { $message[$requiredField][] = sprintf($this->lang->error->notempty, $fields[$requiredField]->name); } @@ -643,7 +641,7 @@ class control extends baseControl * @access public * @return mixed */ - public function __call($method, $arguments) + public function __call(string $method, array $arguments) { $moduleName = $this->app->getModuleName(); $zenClass = $moduleName . 'Zen'; @@ -661,7 +659,7 @@ class control extends baseControl * @access public * @return mixed */ - public static function __callStatic($method, $arguments) + public static function __callStatic(string $method, array $arguments) { global $app; $moduleName = $app->getModuleName(); diff --git a/framework/helper.class.php b/framework/helper.class.php index cb474da2c8..ded097373b 100644 --- a/framework/helper.class.php +++ b/framework/helper.class.php @@ -1,4 +1,4 @@ -requestType != 'GET') @@ -28,10 +28,10 @@ class helper extends baseHelper $pathInfo = $app->getPathInfo(); if(!empty($pathInfo)) { - $dotPos = strrpos($pathInfo, '.'); + $dotPos = strrpos((string) $pathInfo, '.'); if($dotPos) { - $viewType = substr($pathInfo, $dotPos + 1); + $viewType = substr((string) $pathInfo, $dotPos + 1); } else { @@ -53,8 +53,8 @@ class helper extends baseHelper } if($source and isset($viewType)) return $viewType; - if(isset($viewType) and strpos($config->views, ',' . $viewType . ',') === false) $viewType = $config->default->view; - return isset($viewType) ? $viewType : $config->default->view; + if(isset($viewType) and !str_contains((string) $config->views, ',' . $viewType . ',')) $viewType = $config->default->view; + return $viewType ?? $config->default->view; } /** @@ -66,13 +66,13 @@ class helper extends baseHelper * @access public * @return string */ - public static function jsonEncode4Parse($data, $options = 0) + public static function jsonEncode4Parse(array $data, int $options = 0) { $json = json_encode($data); if($options) $json = str_replace(array("'", '"'), array('\u0027', '\u0022'), $json); - $escapers = array("\\", "/", "\"", "'", "\n", "\r", "\t", "\x08", "\x0c", "\\\\u"); - $replacements = array("\\\\", "\\/", "\\\"", "\'", "\\n", "\\r", "\\t", "\\f", "\\b", "\\u"); + $escapers = array("\\", "/", "\"", "'", "\n", "\r", "\t", "\x08", "\x0c", "\\\\u"); + $replacements = array("\\\\", "\\/", "\\\"", "\'", "\\n", "\\r", "\\t", "\\f", "\\b", "\\u"); return str_replace($escapers, $replacements, $json); } @@ -84,19 +84,19 @@ class helper extends baseHelper * @access public * @return bool */ - public static function hasFeature($feature) + public static function hasFeature(string $feature): bool { global $config; - if(strpos($feature, '_') !== false) + if(str_contains($feature, '_')) { $code = explode('_', $feature); $code = $code[0] . ucfirst($code[1]); - return strpos(",$config->disabledFeatures,", ",{$code},") === false; + return !str_contains(",$config->disabledFeatures,", ",{$code},"); } else { - if(in_array($feature, array('scrum', 'waterfall', 'agileplus', 'waterfallplus'))) return strpos(",$config->disabledFeatures,", ",{$feature},") === false; + if(in_array($feature, array('scrum', 'waterfall', 'agileplus', 'waterfallplus'))) return !str_contains(",$config->disabledFeatures,", ",{$feature},"); $hasFeature = false; $canConfigFeature = false; @@ -118,7 +118,7 @@ class helper extends baseHelper } } } - return !$canConfigFeature or ($hasFeature && strpos(",$config->disabledFeatures,", ",{$feature},") === false); + return !$canConfigFeature or ($hasFeature && !str_contains(",$config->disabledFeatures,", ",{$feature},")); } } @@ -132,7 +132,7 @@ class helper extends baseHelper * @access public * @return string */ - public static function convertEncoding($string, $fromEncoding, $toEncoding = 'utf-8') + public static function convertEncoding(string $string, string $fromEncoding, string $toEncoding = 'utf-8'): string { $toEncoding = str_replace('utf8', 'utf-8', $toEncoding); if(function_exists('mb_convert_encoding')) @@ -142,7 +142,7 @@ class helper extends baseHelper if($position !== false) $toEncoding = substr($toEncoding, 0, $position); /* Check string encoding. */ - $encodings = array_merge(array('GB2312','GBK','BIG5'), mb_list_encodings()); + $encodings = array_merge(array('GB2312', 'GBK', 'BIG5'), mb_list_encodings()); $encoding = strtolower(mb_detect_encoding($string, $encodings)); if($encoding == $toEncoding) return $string; return mb_convert_encoding($string, $toEncoding, $encoding); @@ -164,10 +164,8 @@ class helper extends baseHelper * * @param string $begin * @param string $end - * - * @return bool|float */ - public static function workDays($begin, $end) + public static function workDays(string $begin, string $end): bool|float { $begin = strtotime($begin); $end = strtotime($end); @@ -189,7 +187,7 @@ class helper extends baseHelper * @access public * @return string */ - public static function unify($string, $to = ',') + public static function unify(string $string, string $to = ',') { $labels = array('_', '、', ' ', '-', '?', '@', '&', '%', '~', '`', '+', '*', '/', '\\', ',', '。'); $string = str_replace($labels, $to, $string); @@ -204,7 +202,7 @@ class helper extends baseHelper * @access public * @return string */ - public static function formatVersion($version) + public static function formatVersion(string $version) { return preg_replace_callback( '/([0-9]+)((?:\.[0-9]+)?)((?:\.[0-9]+)?)(?:[\s\-\+]?)((?:[a-z]+)?)((?:\.?[0-9]+)?)/i', @@ -216,11 +214,7 @@ class helper extends baseHelper $preRelease = $matches[4]; $build = $matches[5]; - $versionStrs = array( - $major, - $minor ?: ".0", - $patch ?: ".0", - ); + $versionStrs = array($major, $minor ?: ".0", $patch ?: ".0"); if($preRelease ?: $build) array_push($versionStrs, "-"); if($preRelease) array_push($versionStrs, $preRelease); @@ -244,7 +238,7 @@ class helper extends baseHelper * @access public * @return string */ - public function trimVersion($version) + public function trimVersion(string $version) { return preg_replace_callback( '/([0-9]+)((?:\.[0-9]+)?)((?:\.[0-9]+)?)(?:[\s\-\+]?)((?:[a-z]+)?)((?:\.?[0-9]+)?)/i', @@ -256,10 +250,7 @@ class helper extends baseHelper $preRelease = $matches[4]; $build = $matches[5]; - $versionStrs = array( - $major, - $minor ?: ".0", - ); + $versionStrs = array($major, $minor ?: ".0"); if($patch && $patch !== ".0" && $patch !== "0") array_push($versionStrs, $patch); if($preRelease ?: $build) array_push($versionStrs, " "); @@ -283,14 +274,14 @@ class helper extends baseHelper * @access public * @return string */ - static public function requestAPI($url) + static public function requestAPI(string $url) { global $config; - $url .= (strpos($url, '?') !== false ? '&' : '?') . $config->sessionVar . '=' . session_id(); + $url .= (str_contains($url, '?') ? '&' : '?') . $config->sessionVar . '=' . session_id(); if(isset($_SESSION['user'])) $url .= '&account=' . $_SESSION['user']->account; $response = common::http($url); - $jsonDecode = json_decode($response); + $jsonDecode = json_decode((string) $response); if(empty($jsonDecode)) return $response; return $jsonDecode; } @@ -301,7 +292,7 @@ class helper extends baseHelper * @param string $content * @return void */ - public static function end($content = '') + public static function end(string $content = ''): never { throw EndResponseException::create($content); } @@ -309,14 +300,11 @@ class helper extends baseHelper /** * Get date interval. * - * @param string|int $begin - * @param string|int $end * @param string $format %Y-%m-%d %H:%i:%s * @static * @access public - * @return object|string */ - public static function getDateInterval($begin, $end = '', $format = '') + public static function getDateInterval(string|int $begin, string|int $end = '', string $format = ''): object|string { if(empty($end)) $end = time(); if(is_int($begin)) $begin = date('Y-m-d H:i:s', $begin); @@ -355,9 +343,9 @@ class helper extends baseHelper * Check exist onlybody param. * * @access public - * @return void + * @return bool */ -function isonlybody() +function isonlybody(): bool { return helper::inOnlyBodyMode(); } @@ -365,12 +353,12 @@ function isonlybody() /** * Format time. * - * @param int $time + * @param string $time * @param string $format * @access public - * @return void + * @return string */ -function formatTime($time, $format = '') +function formatTime(string $time, string $format = ''): string { $time = str_replace('0000-00-00', '', $time); $time = str_replace('00:00:00', '', $time); @@ -382,11 +370,11 @@ function formatTime($time, $format = '') /** * Fix for session error. * - * @param int $class + * @param string $class * @access protected * @return void */ -function autoloader($class) +function autoloader(string $class) { if(!class_exists($class)) { diff --git a/framework/model.class.php b/framework/model.class.php index 2287fb1103..973b4d6b5c 100644 --- a/framework/model.class.php +++ b/framework/model.class.php @@ -1,4 +1,4 @@ -dao->update($table)->set('deleted')->eq(1)->where('id')->eq($id)->exec(); - $object = preg_replace('/^' . preg_quote($this->config->db->prefix) . '/', '', trim($table, '`')); + $object = preg_replace('/^' . preg_quote((string) $this->config->db->prefix) . '/', '', trim($table, '`')); $this->loadModel('action')->create($object, $id, 'deleted', '', $extra = ACTIONMODEL::CAN_UNDELETED); return true; @@ -91,9 +91,9 @@ class model extends baseModel public function buildMenu($moduleName, $methodName, $params, $data, $type = 'view', $icon = '', $target = '', $class = '', $onlyBody = false, $misc = '' , $title = '', $returnHtml = true) { - if(strpos($moduleName, '.') !== false) list($appName, $moduleName) = explode('.', $moduleName); + if(str_contains($moduleName, '.')) [$appName, $moduleName] = explode('.', $moduleName); - if(strpos($methodName, '_') !== false && strpos($methodName, '_') > 0) list($module, $method) = explode('_', $methodName); + if(str_contains($methodName, '_') && strpos($methodName, '_') > 0) [$module, $method] = explode('_', $methodName); if(empty($module)) $module = $moduleName; if(empty($method)) $method = $methodName; @@ -119,7 +119,7 @@ class model extends baseModel if($action->extensionType == 'override') return $this->loadModel('flow')->buildActionMenu($moduleName, $action, $data, $type); - $conditions = json_decode($action->conditions); + $conditions = json_decode((string) $action->conditions); if($conditions and $action->extensionType == 'extend') { if($icon != 'copy' and $methodName != 'create') $title = $action->name; @@ -158,7 +158,7 @@ class model extends baseModel if(!isset($this->config->bizVersion)) return ''; $moduleName = $module; - if(strpos($module, '.') !== false) list($appName, $moduleName) = explode('.', $module); + if(str_contains($module, '.')) [$appName, $moduleName] = explode('.', $module); static $actions; static $relations; @@ -182,7 +182,7 @@ class model extends baseModel $flow = $this->loadModel('workflow', 'flow')->getByModule($moduleName); if($flow->approval == 'enabled' && !empty($data->approval)) { - $extraClass = strpos(',testsuite,build,release,productplan,', ",{$moduleName},") !== false ? 'btn-link' : ''; + $extraClass = str_contains(',testsuite,build,release,productplan,', ",{$moduleName},") ? 'btn-link' : ''; $approvalProgressMenu .= "
"; $approvalProgressMenu .= baseHTML::a(helper::createLink('approval', 'progress', "approvalID={$data->approval}", '', true), $this->lang->flow->approvalProgress, "class='btn {$extraClass} iframe'"); } @@ -193,7 +193,7 @@ class model extends baseModel { foreach($actions as $action) { - if(strpos($action->position, $type) === false || $action->show != $show) continue; + if(!str_contains((string) $action->position, $type) || $action->show != $show) continue; $menu .= $this->flow->buildActionMenu($moduleName, $action, $data, $type, $relations); } @@ -205,7 +205,7 @@ class model extends baseModel $dropdownMenu = ''; foreach($actions as $action) { - if(strpos($action->position, $type) === false) continue; + if(!str_contains((string) $action->position, $type)) continue; if($type == 'view' || $action->show == 'direct') $menu .= $this->flow->buildActionMenu($moduleName, $action, $data, $type, $relations); if($type == 'browse' && $action->show == 'dropdownlist') $dropdownMenu .= $this->flow->buildActionMenu($moduleName, $action, $data, $type, $relations); @@ -313,7 +313,7 @@ class model extends baseModel * @access public * @return void */ - public function executeHooks($objectID) + public function executeHooks(int $objectID) { if(!isset($this->config->bizVersion)) return false; @@ -368,7 +368,7 @@ class model extends baseModel { global $app; - $moduleName = strtolower(get_called_class()); + $moduleName = strtolower(static::class); preg_match_all('/^(ext)?(\w+)model/', $moduleName, $matches); if(isset($matches[2][0])) diff --git a/framework/router.class.php b/framework/router.class.php index ac909cfb8b..e5175d568b 100755 --- a/framework/router.class.php +++ b/framework/router.class.php @@ -1,4 +1,4 @@ -dbh->query('SELECT * FROM' . TABLE_LANG . "WHERE `module`='common' AND `section`='mainNav' AND `lang`='{$this->clientLang}' AND `vision`='{$this->config->vision}'")->fetchAll(); } - catch(PDOException $exception){} + catch(PDOException){} foreach($customMenus as $menu) { $menuKey = $menu->key; - if(isset($lang->mainNav->$menuKey)) $lang->mainNav->$menuKey = zget($lang->navIcons, $menuKey, '') . " {$menu->value}" . substr($lang->mainNav->$menuKey, strpos($lang->mainNav->$menuKey, '|')); + if(isset($lang->mainNav->$menuKey)) $lang->mainNav->$menuKey = zget($lang->navIcons, $menuKey, '') . " {$menu->value}" . substr((string) $lang->mainNav->$menuKey, strpos((string) $lang->mainNav->$menuKey, '|')); } } @@ -162,7 +162,7 @@ class router extends baseRouter if(isset($nullKey))$lang->{$moduleName}->{$section}[$nullKey] = $nullValue; foreach($fields as $key => $value) { - if($section == 'priList' and $key > 0 and trim($value) === '') continue; // Fix bug #23538. + if($section == 'priList' and $key > 0 and trim((string) $value) === '') continue; // Fix bug #23538. if(!isset($lang->{$moduleName})) $lang->{$moduleName} = new stdclass(); if(!isset($lang->{$moduleName}->{$section})) $lang->{$moduleName}->{$section} = array(); @@ -255,20 +255,20 @@ class router extends baseRouter /* Set productCommon, projectCommon and hourCommon. Default english lang. */ $lang->productCommon = $this->config->productCommonList[$this->clientLang][PRODUCT_KEY]; $lang->projectCommon = $this->config->projectCommonList[$this->clientLang][PROJECT_KEY]; - $lang->iterationCommon = isset($this->config->executionCommonList[$this->clientLang][(int)$iterationKey]) ? $this->config->executionCommonList[$this->clientLang][(int)$iterationKey] : $this->config->executionCommonList['en'][(int)$iterationKey]; - $lang->executionCommon = isset($this->config->executionCommonList[$this->clientLang][(int)$projectKey]) ? $this->config->executionCommonList[$this->clientLang][(int)$projectKey] : $this->config->executionCommonList['en'][(int)$projectKey]; - $lang->hourCommon = isset($this->config->hourPointCommonList[$this->clientLang][(int)$hourKey]) ? $this->config->hourPointCommonList[$this->clientLang][(int)$hourKey] : $this->config->hourPointCommonList['en'][(int)$hourKey]; + $lang->iterationCommon = $this->config->executionCommonList[$this->clientLang][(int)$iterationKey] ?? $this->config->executionCommonList['en'][(int)$iterationKey]; + $lang->executionCommon = $this->config->executionCommonList[$this->clientLang][(int)$projectKey] ?? $this->config->executionCommonList['en'][(int)$projectKey]; + $lang->hourCommon = $this->config->hourPointCommonList[$this->clientLang][(int)$hourKey] ?? $this->config->hourPointCommonList['en'][(int)$hourKey]; /* User preference init. */ $config->URSR = $URSR; - $config->URAndSR = ($URAndSR and strpos(",{$config->disabledFeatures},", ',productUR,') === false); + $config->URAndSR = ($URAndSR and !str_contains(",{$config->disabledFeatures},", ',productUR,')); $config->programLink = 'program-browse'; $config->productLink = 'product-all'; $config->projectLink = 'project-browse'; $config->executionLink = 'execution-task'; /* Get user preference. */ - $account = isset($this->session->user->account) ? $this->session->user->account : ''; + $account = $this->session->user->account ?? ''; $userSetting = array(); if($this->dbh and !empty($this->config->db->name) and $account) { @@ -293,7 +293,6 @@ class router extends baseRouter $productProject = $this->dbh->query('SELECT `value` FROM ' . TABLE_CONFIG . "WHERE `owner`='system' AND `module`='custom' AND `key`='productProject'")->fetch(); if($productProject) { - $productProject = $productProject->value; list($productCommon, $projectCommon) = explode('_', $productProject); $lang->productCommon = isset($this->config->productCommonList[$this->clientLang][(int)$productCommon]) ? $this->config->productCommonList[$this->clientLang][(int)$productCommon] : $this->config->productCommonList['en'][0]; } @@ -309,14 +308,14 @@ class router extends baseRouter $SRPairs = array(); foreach($URSRList as $id => $value) { - $URSR = json_decode($value->value); + $URSR = json_decode((string) $value->value); $URPairs[$value->key] = $URSR->URName; $SRPairs[$value->key] = $URSR->SRName; } /* Set default story concept and init UR and SR concept. */ - $lang->URCommon = isset($URPairs[$config->URSR]) ? $URPairs[$config->URSR] : reset($URPairs); - $lang->SRCommon = isset($SRPairs[$config->URSR]) ? $SRPairs[$config->URSR] : reset($SRPairs); + $lang->URCommon = $URPairs[$config->URSR] ?? reset($URPairs); + $lang->SRCommon = $SRPairs[$config->URSR] ?? reset($SRPairs); } /* Replace common lang. */ @@ -325,7 +324,7 @@ class router extends baseRouter { $customMenus = $this->dbh->query('SELECT * FROM' . TABLE_LANG . "WHERE `module`='common' AND `lang`='{$this->clientLang}' AND `section`='' AND `vision`='{$config->vision}'")->fetchAll(); } - catch(PDOException $exception){} + catch(PDOException){} foreach($customMenus as $menu) if(isset($lang->{$menu->key})) $lang->{$menu->key} = $menu->value; } } @@ -342,6 +341,7 @@ class router extends baseRouter */ public function saveError($level, $message, $file, $line) { + $fatalLevel = array(); $fatalLevel[E_ERROR] = E_ERROR; $fatalLevel[E_PARSE] = E_PARSE; $fatalLevel[E_CORE_ERROR] = E_CORE_ERROR; @@ -363,6 +363,7 @@ class router extends baseRouter */ public function loadModuleConfig($moduleName, $appName = '') { + $extConfigPath = array(); global $config; if($config and (!isset($config->$moduleName) or !is_object($config->$moduleName))) $config->$moduleName = new stdclass(); @@ -560,6 +561,8 @@ class router extends baseRouter */ public function setFlowURI($moduleName, $methodName) { + $query = null; + $path = null; $this->rawURI = $this->URI; $this->setModuleName($moduleName); @@ -568,7 +571,7 @@ class router extends baseRouter if($this->config->requestType != 'GET') { /* e.g. $this->URI = /$module-close-1.html. */ - $params = explode($this->config->requestFix, $this->URI); // $params = array($module, 'close', 1); + $params = explode($this->config->requestFix, (string) $this->URI); // $params = array($module, 'close', 1); /* Remove module and method. */ $params = array_slice($params, 2); // $params = array(1); @@ -589,9 +592,9 @@ class router extends baseRouter { /* Extract $path and $query from $params. */ /* e.g. $tshi->URI = /index.php?m=$module&f=close&id=1. */ - $params = parse_url($this->URI); // $params = array('path' => '/index.php', 'query' => m=$module&f=close&id=1; + $params = parse_url((string) $this->URI); // $params = array('path' => '/index.php', 'query' => m=$module&f=close&id=1; extract($params); // $path = '/index.php'; $query = 'm=$module&f=close&id=1'; - parse_str($query, $params); // $params = array('m' => $module, 'f' => 'close', 'id' => 1); + parse_str((string) $query, $params); // $params = array('m' => $module, 'f' => 'close', 'id' => 1); /* Remove module and method. */ unset($params[$this->config->moduleVar]); // $params = array('f' => 'close', 'id' => 1); diff --git a/lib/base/filter/filter.class.php b/lib/base/filter/filter.class.php index fda784c2a2..a05def7b6e 100644 --- a/lib/base/filter/filter.class.php +++ b/lib/base/filter/filter.class.php @@ -1006,9 +1006,9 @@ class baseFixer /** * Special array * - * @param mix $data + * @param mixed $data * @access public - * @return mix + * @return mixed */ public function specialArray($data) { diff --git a/lib/base/front/front.class.php b/lib/base/front/front.class.php index e00226eae8..3909ca2e13 100644 --- a/lib/base/front/front.class.php +++ b/lib/base/front/front.class.php @@ -23,7 +23,6 @@ class baseHTML * 生成title标签。 * Create the title tag. * - * @param mixed $title * @static * @access public * @return string. @@ -112,7 +111,7 @@ class baseHTML $newline = $newline ? "\n" : ''; /* Make sure href is opened in the same tab. */ - if(strpos($misc, 'data-app=') === false) + if(!str_contains($misc, 'data-app=')) { global $app, $lang; $module = $app->rawModule; @@ -168,9 +167,9 @@ class baseHTML /* The begin. */ $id = $name; - if(strpos($name, '[') !== false) $id = trim(str_replace(']', '', str_replace('[', '', $name))); + if(str_contains($name, '[')) $id = trim(str_replace(']', '', str_replace('[', '', $name))); $id = "id='{$id}'"; - if(strpos($attrib, 'id=') !== false) $id = ''; + if(str_contains($attrib, 'id=')) $id = ''; $string = "\n"; /* The options. */ @@ -215,7 +214,7 @@ class baseHTML $string .= "\n"; foreach($options as $key => $value) { - $selected = strpos($selectedItems, ",$key,") !== false ? " selected='selected'" : ''; + $selected = str_contains($selectedItems, ",$key,") ? " selected='selected'" : ''; $string .= "\n"; } $string .= "\n"; @@ -288,7 +287,7 @@ class baseHTML if($isBlock) $string .= "