Skip to content

Commit

Permalink
fix action
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Aug 27, 2021
1 parent 539ef5e commit 93b5656
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 136 deletions.
2 changes: 1 addition & 1 deletion var/Typecho/Widget/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function throwContent(string $content, string $contentType = 'text/html')
}

/**
* @param string $message
* @param mixed $message
*/
public function throwXml(string $message)
{
Expand Down
17 changes: 11 additions & 6 deletions var/Widget/Do.php → var/Widget/Action.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace Widget;

use Typecho\Widget;

if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
Expand All @@ -9,7 +13,7 @@
*
* @package Widget
*/
class Widget_Do extends Typecho_Widget
class Action extends Widget
{
/**
* 路由映射
Expand Down Expand Up @@ -46,7 +50,7 @@ class Widget_Do extends Typecho_Widget
/**
* 入口函数,初始化路由器
*
* @throws Typecho_Widget_Exception|Typecho_Exception
* @throws Widget\Exception
*/
public function execute()
{
Expand All @@ -61,13 +65,14 @@ public function execute()
}

if (isset($widgetName) && class_exists($widgetName)) {
$reflectionWidget = new ReflectionClass($widgetName);
if ($reflectionWidget->implementsInterface('Widget_Interface_Do')) {
self::widget($widgetName)->action();
$widget = self::widget($widgetName);

if ($widget instanceof ActionInterface) {
$widget->action();
return;
}
}

throw new Typecho_Widget_Exception(_t('请求的地址不存在'), 404);
throw new Widget\Exception(_t('请求的地址不存在'), 404);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* 可以被Widget_Do调用的接口
*/
interface DoInterface
interface ActionInterface
{
/**
* 接口需要实现的入口函数
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @category typecho
* @package Widget
*/
class Ajax extends BaseOptions implements DoInterface
class Ajax extends BaseOptions implements ActionInterface
{
/**
* 针对rewrite验证的请求返回
Expand Down
18 changes: 6 additions & 12 deletions var/Widget/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -1834,13 +1834,11 @@ private function singleHandle(Query $select, bool &$hasPushed)
/**
* 处理分类
*
* @access private
* @param Query $select 查询对象
* @param boolean $hasPushed 是否已经压入队列
* @return void
* @throws WidgetException
* @throws WidgetException|Db\Exception
*/
private function categoryHandle(Query $select, &$hasPushed)
private function categoryHandle(Query $select, bool &$hasPushed)
{
/** 如果是分类 */
$categorySelect = $this->db->select()
Expand Down Expand Up @@ -1920,13 +1918,11 @@ private function categoryHandle(Query $select, &$hasPushed)
/**
* 处理标签
*
* @access private
* @param Query $select 查询对象
* @param boolean $hasPushed 是否已经压入队列
* @return void
* @throws WidgetException
* @throws WidgetException|Db\Exception
*/
private function tagHandle(Query $select, &$hasPushed)
private function tagHandle(Query $select, bool &$hasPushed)
{
$tagSelect = $this->db->select()->from('table.metas')
->where('type = ?', 'tag')->limit(1);
Expand Down Expand Up @@ -1991,13 +1987,11 @@ private function tagHandle(Query $select, &$hasPushed)
/**
* 处理作者
*
* @access private
* @param Query $select 查询对象
* @param boolean $hasPushed 是否已经压入队列
* @return void
* @throws WidgetException
* @throws WidgetException|Db\Exception
*/
private function authorHandle(Query $select, &$hasPushed)
private function authorHandle(Query $select, bool &$hasPushed)
{
$uid = $this->request->filter('int')->uid;

Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Base/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function excerpt(int $length = 100, string $trim = '...')
* 获取当前内容结构
*
* @return array|null
* @throws Exception|\Typecho\Widget\Exception
* @throws Exception
*/
protected function ___parentContent(): ?array
{
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Base/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Typecho\Widget;
use Widget\Base;
use Widget\Metas\Category\Rows;
use Widget\User\Author;
use Widget\Users\Author;

if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
Expand Down
4 changes: 2 additions & 2 deletions var/Widget/Comments/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Typecho\Db\Exception;
use Widget\Base\Comments;
use Widget\DoInterface;
use Widget\ActionInterface;
use Widget\Notice;

if (!defined('__TYPECHO_ROOT_DIR__')) {
Expand All @@ -20,7 +20,7 @@
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
*/
class Edit extends Comments implements DoInterface
class Edit extends Comments implements ActionInterface
{
/**
* 标记为待审核
Expand Down
4 changes: 2 additions & 2 deletions var/Widget/Contents/Attachment/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Typecho\Widget\Exception;
use Typecho\Widget\Helper\Form;
use Typecho\Widget\Helper\Layout;
use Widget\DoInterface;
use Widget\ActionInterface;
use Widget\Contents\Post\Edit as PostEdit;
use Widget\Notice;
use Widget\Upload;
Expand All @@ -24,7 +24,7 @@
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
*/
class Edit extends PostEdit implements DoInterface
class Edit extends PostEdit implements ActionInterface
{
/**
* 执行函数
Expand Down
4 changes: 2 additions & 2 deletions var/Widget/Contents/Page/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Typecho\Date;
use Typecho\Widget\Exception;
use Widget\Contents\Post\Edit as PostEdit;
use Widget\DoInterface;
use Widget\ActionInterface;
use Widget\Notice;
use Widget\Service;

Expand All @@ -23,7 +23,7 @@
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
*/
class Edit extends PostEdit implements DoInterface
class Edit extends PostEdit implements ActionInterface
{
/**
* 自定义字段的hook名称
Expand Down
4 changes: 2 additions & 2 deletions var/Widget/Contents/Post/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Typecho\Widget\Helper\Layout;
use Widget\Base\Contents;
use Widget\Base\Metas;
use Widget\DoInterface;
use Widget\ActionInterface;
use Typecho\Db\Exception as DbException;
use Typecho\Date as TypechoDate;
use Widget\Notice;
Expand All @@ -29,7 +29,7 @@
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
*/
class Edit extends Contents implements DoInterface
class Edit extends Contents implements ActionInterface
{
/**
* 自定义字段的hook名称
Expand Down

0 comments on commit 93b5656

Please sign in to comment.