更新route目录结构以及Router类注释

This commit is contained in:
TOP糯米 2019-07-08 16:41:04 +08:00
parent ba9c63baa3
commit ce86ace205
7 changed files with 81 additions and 31 deletions

View File

@ -1 +1 @@
### TOP-Framework
### TOP-Framework

View File

@ -17,14 +17,34 @@ class Router
*/
private $driver;
/**
* 模块
* @var string
*/
public $module = '';
/**
* 完整控制器类名
* @var string
*/
public $class = '';
/**
* 控制器
* @var string
*/
public $ctrl = '';
public $action = '';
/**
* 方法名称
* @var string
*/
public $method = '';
/**
* 请求参数
* @var array
*/
public $params = [];
/**
@ -55,7 +75,7 @@ class Router
throw new RouteException('控制器' . $this->class . '不存在');
}
// 检查方法在控制器中是否存在
if (!in_array($this->action, get_class_methods($this->class))) {
if (!in_array($this->method, get_class_methods($this->class))) {
throw new RouteException('方法' . $this->action . '在控制器' . $this->ctrl . '中不存在');
}
}
@ -70,7 +90,7 @@ class Router
$this->module = $this->driver->module;
$this->class = $this->driver->class;
$this->ctrl = $this->driver->ctrl;
$this->action = $this->driver->action;
$this->method = $this->driver->method;
$this->params = $this->driver->params;
$this->check();

View File

@ -5,8 +5,8 @@ namespace top\library\http;
use top\decorator\ifs\DecoratorIfs;
use top\decorator\InitDecorator;
use top\library\Register;
use top\library\route\Command;
use top\library\route\Pathinfo;
use top\library\route\driver\Command;
use top\library\route\driver\Pathinfo;
use top\library\Router;
/**
@ -221,7 +221,7 @@ class Request
*/
public function method()
{
return $this->router->action;
return $this->router->method;
}
/**
@ -322,7 +322,7 @@ class Request
$this->beforeRoute();
$ctrl = $this->router->class;
$action = $this->router->action;
$method = $this->router->method;
$params = $this->router->params;
$object = new $ctrl();
@ -331,7 +331,7 @@ class Request
$data = $object->_init();
}
if (!isset($data)) {
$reflectionMethod = new \ReflectionMethod($ctrl, $action);
$reflectionMethod = new \ReflectionMethod($ctrl, $method);
$data = $reflectionMethod->invokeArgs($object, $params);
}

View File

@ -1,6 +1,6 @@
<?php
namespace top\library\route;
namespace top\library\route\driver;
use top\library\route\ifs\RouteIfs;
@ -16,8 +16,8 @@ class Command implements RouteIfs
// 控制器
public $ctrl = '';
// 动作
public $action = '';
// 方法
public $method = '';
// 参数
public $param = [];
@ -31,7 +31,7 @@ class Command implements RouteIfs
$this->module = $this->module();
$this->ctrl = $this->ctrl();
$this->class = '\\' . APP_NS . '\\' . $this->module . '\\controller\\' . $this->ctrl;
$this->action = $this->action();
$this->method = $this->method();
$this->param = $this->param();
}
@ -56,7 +56,7 @@ class Command implements RouteIfs
/**
*
*/
public function action()
public function method()
{
// TODO Auto-generated method stub
return 'index';
@ -65,7 +65,7 @@ class Command implements RouteIfs
/**
*
*/
public function param()
public function params()
{
// TODO Auto-generated method stub
return [];

View File

@ -1,6 +1,6 @@
<?php
namespace top\library\route;
namespace top\library\route\driver;
use top\library\route\ifs\RouteIfs;
@ -11,34 +11,64 @@ use top\library\route\ifs\RouteIfs;
class Pathinfo implements RouteIfs
{
// 链接数组
/**
* 链接数组
* @var array
*/
private $uriArray = [];
// 原始链接
/**
* 原始链接
* @var string
*/
public $rawUri = '';
// 链接
/**
* 链接
* @var string
*/
public $uri = '';
// 默认访问位置
/**
* 默认访问位置
* @var string
*/
public $default = '';
// 分隔符
/**
* 分隔符
* @var string
*/
public $separator = '/';
// 模块
/**
* 模块
* @var string
*/
public $module = '';
// 控制器
/**
* 控制器
* @var string
*/
public $ctrl = '';
// 动作
public $action = '';
/**
* 方法
* @var string
*/
public $method = '';
// 参数
/**
* 参数
* @var array
*/
public $params = [];
// 类名
/**
* 类名
* @var string
*/
public $class = '';
/**
@ -71,7 +101,7 @@ class Pathinfo implements RouteIfs
* 具体执行的方法名
* @return mixed|string
*/
public function action()
public function method()
{
if (isset($this->uriArray[2]) && $this->uriArray[2]) {
return $this->uriArray[2];
@ -172,7 +202,7 @@ class Pathinfo implements RouteIfs
$this->module = $this->module();
$this->ctrl = $this->ctrl();
$this->class = '\\' . APP_NS . '\\' . $this->module . '\\controller\\' . $this->ctrl;
$this->action = $this->action();
$this->method = $this->method();
$this->params = $this->params();
unset($this->uriArray);
}

View File

@ -25,9 +25,9 @@ interface RouteIfs
public function ctrl();
/**
* 动作
* 方法
*/
public function action();
public function method();
/**
* 解析参数