diff --git a/var/Typecho/Common.php b/var/Typecho/Common.php index de4054da..792d23f3 100644 --- a/var/Typecho/Common.php +++ b/var/Typecho/Common.php @@ -14,16 +14,17 @@ define('__TYPECHO_MB_SUPPORTED__', function_exists('mb_get_info') && function_ex /** * I18n function * - * @param string $string 需要翻译的文字 + * @param ...$args 需要翻译的文字 * * @return string */ -function _t($string) +function _t(...$args) { - if (func_num_args() <= 1) { + [$string] = $args; + + if (count($args) <= 1) { return Typecho_I18n::translate($string); } else { - $args = func_get_args(); array_shift($args); return vsprintf(Typecho_I18n::translate($string), $args); } @@ -32,13 +33,12 @@ function _t($string) /** * I18n function, translate and echo * - * @param string $string 需要翻译并输出的文字 + * @param ...$args 需要翻译的文字 * * @return void */ -function _e() +function _e(...$args) { - $args = func_get_args(); echo call_user_func_array('_t', $args); } diff --git a/var/Typecho/Db/Query.php b/var/Typecho/Db/Query.php index 34e81be0..50db9264 100644 --- a/var/Typecho/Db/Query.php +++ b/var/Typecho/Db/Query.php @@ -277,20 +277,18 @@ class Typecho_Db_Query /** * OR条件查询语句 * - * @param string $condition 查询条件 - * @param mixed $param 条件值 + * @param ...$args * @return Typecho_Db_Query */ - public function orWhere() + public function orWhere(...$args) { - $condition = func_get_arg(0); + [$condition] = $args; $condition = str_replace('?', "%s", $this->filterColumn($condition)); $operator = empty($this->_sqlPreBuild['where']) ? ' WHERE ' : ' OR'; if (func_num_args() <= 1) { $this->_sqlPreBuild['where'] .= $operator . ' (' . $condition . ')'; } else { - $args = func_get_args(); array_shift($args); $this->_sqlPreBuild['where'] .= $operator . ' (' . vsprintf($condition, $this->quoteValues($args)) . ')'; } @@ -422,14 +420,12 @@ class Typecho_Db_Query /** * 选择查询字段 * - * @access public - * @param mixed $field 查询字段 - * @return Typecho_Db_Query + * @param mixed ...$args 查询字段 + * @return $this */ - public function select($field = '*') + public function select(...$args): Typecho_Db_Query { $this->_sqlPreBuild['action'] = Typecho_Db::SELECT; - $args = func_get_args(); $this->_sqlPreBuild['fields'] = $this->getColumnFromParameters($args); return $this; diff --git a/var/Typecho/Widget.php b/var/Typecho/Widget.php index 3defa99f..e1195124 100644 --- a/var/Typecho/Widget.php +++ b/var/Typecho/Widget.php @@ -290,13 +290,12 @@ abstract class Typecho_Widget /** * 根据余数输出 * - * @access public + * @param mixed ...$args * @return void */ - public function alt() + public function alt(...$args) { - $args = func_get_args(); - $num = func_num_args(); + $num = count($args); $split = $this->sequence % $num; echo $args[(0 == $split ? $num : $split) - 1]; } diff --git a/var/Widget/Abstract/Contents.php b/var/Widget/Abstract/Contents.php index 3ee16ffe..46ed6ac7 100644 --- a/var/Widget/Abstract/Contents.php +++ b/var/Widget/Abstract/Contents.php @@ -592,28 +592,26 @@ class Widget_Abstract_Contents extends Widget_Abstract /** * 输出文章评论数 * - * @access public + * @param ...$args */ - public function commentsNum() + public function commentsNum(...$args) { - $args = func_get_args(); - if (!$args) { + if (empty($args)) { $args[] = '%d'; } $num = intval($this->commentsNum); - echo sprintf(isset($args[$num]) ? $args[$num] : array_pop($args), $num); + echo sprintf($args[$num] ?? array_pop($args), $num); } /** * 获取文章权限 * - * @access public + * @param ...$permissions */ - public function allow() + public function allow(...$permissions): bool { - $permissions = func_get_args(); $allow = true; foreach ($permissions as $permission) { diff --git a/var/Widget/Comments/Archive.php b/var/Widget/Comments/Archive.php index 5618a459..582c5557 100644 --- a/var/Widget/Comments/Archive.php +++ b/var/Widget/Comments/Archive.php @@ -350,14 +350,11 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments /** * 根据深度余数输出 * - * @access public - * @param string $param 需要输出的值 - * @return void + * @param ...$args 需要输出的值 */ - public function levelsAlt() + public function levelsAlt(...$args) { - $args = func_get_args(); - $num = func_num_args(); + $num = count($args); $split = $this->levels % $num; echo $args[(0 == $split ? $num : $split) - 1]; } @@ -365,13 +362,11 @@ class Widget_Comments_Archive extends Widget_Abstract_Comments /** * 重载alt函数,以适应多级评论 * - * @access public - * @return void + * @param ...$args */ - public function alt() + public function alt(...$args) { - $args = func_get_args(); - $num = func_num_args(); + $num = count($args); $sequence = $this->levels <= 0 ? $this->sequence : $this->order; diff --git a/var/Widget/Comments/Ping.php b/var/Widget/Comments/Ping.php index acfa201e..8be53b1f 100644 --- a/var/Widget/Comments/Ping.php +++ b/var/Widget/Comments/Ping.php @@ -51,18 +51,15 @@ class Widget_Comments_Ping extends Widget_Abstract_Comments /** * 输出文章回响数 * - * @access public - * @param string $string 评论数格式化数据 - * @return void + * @param ...$args 评论数格式化数据 */ - public function num() + public function num(...$args) { - $args = func_get_args(); - if (!$args) { + if (empty($args)) { $args[] = '%d'; } - echo sprintf($args[$this->length] ?? array_pop($this->length), $this->length); + echo sprintf($args[$this->length] ?? array_pop($args), $this->length); } /** diff --git a/var/Widget/Contents/Post/Edit.php b/var/Widget/Contents/Post/Edit.php index a2967a9d..eab7f243 100644 --- a/var/Widget/Contents/Post/Edit.php +++ b/var/Widget/Contents/Post/Edit.php @@ -61,11 +61,12 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg /** * 获取文章权限 * + * @param mixed ...$permissions + * * @return bool */ - public function allow() + public function allow(...$permissions): bool { - $permissions = func_get_args(); $allow = true; foreach ($permissions as $permission) { diff --git a/var/Widget/Metas/Category/List.php b/var/Widget/Metas/Category/List.php index a4eed1f1..6246b76c 100644 --- a/var/Widget/Metas/Category/List.php +++ b/var/Widget/Metas/Category/List.php @@ -257,13 +257,11 @@ class Widget_Metas_Category_List extends Widget_Abstract_Metas /** * 根据深度余数输出 * - * @access public - * @return void + * @param ...$args */ - public function levelsAlt() + public function levelsAlt(...$args) { - $args = func_get_args(); - $num = func_num_args(); + $num = count($args); $split = $this->levels % $num; echo $args[(0 == $split ? $num : $split) - 1]; } diff --git a/var/Widget/Metas/Tag/Cloud.php b/var/Widget/Metas/Tag/Cloud.php index 46e993dc..5d8d96e6 100644 --- a/var/Widget/Metas/Tag/Cloud.php +++ b/var/Widget/Metas/Tag/Cloud.php @@ -48,13 +48,10 @@ class Widget_Metas_Tag_Cloud extends Widget_Abstract_Metas /** * 按分割数输出字符串 * - * @access public - * @param string $param 需要输出的值 - * @return void + * @param ...$args 需要输出的值 */ - public function split() + public function split(...$args) { - $args = func_get_args(); array_unshift($args, $this->count); echo call_user_func_array(['Typecho_Common', 'splitByCount'], $args); }