更新route目录结构以及Router类注释
This commit is contained in:
parent
ba9c63baa3
commit
ce86ace205
|
|
@ -17,14 +17,34 @@ class Router
|
||||||
*/
|
*/
|
||||||
private $driver;
|
private $driver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $module = '';
|
public $module = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 完整控制器类名
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $class = '';
|
public $class = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制器
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $ctrl = '';
|
public $ctrl = '';
|
||||||
|
|
||||||
public $action = '';
|
/**
|
||||||
|
* 方法名称
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $method = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求参数
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
public $params = [];
|
public $params = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -55,7 +75,7 @@ class Router
|
||||||
throw new RouteException('控制器' . $this->class . '不存在');
|
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 . '中不存在');
|
throw new RouteException('方法' . $this->action . '在控制器' . $this->ctrl . '中不存在');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +90,7 @@ class Router
|
||||||
$this->module = $this->driver->module;
|
$this->module = $this->driver->module;
|
||||||
$this->class = $this->driver->class;
|
$this->class = $this->driver->class;
|
||||||
$this->ctrl = $this->driver->ctrl;
|
$this->ctrl = $this->driver->ctrl;
|
||||||
$this->action = $this->driver->action;
|
$this->method = $this->driver->method;
|
||||||
$this->params = $this->driver->params;
|
$this->params = $this->driver->params;
|
||||||
|
|
||||||
$this->check();
|
$this->check();
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ namespace top\library\http;
|
||||||
use top\decorator\ifs\DecoratorIfs;
|
use top\decorator\ifs\DecoratorIfs;
|
||||||
use top\decorator\InitDecorator;
|
use top\decorator\InitDecorator;
|
||||||
use top\library\Register;
|
use top\library\Register;
|
||||||
use top\library\route\Command;
|
use top\library\route\driver\Command;
|
||||||
use top\library\route\Pathinfo;
|
use top\library\route\driver\Pathinfo;
|
||||||
use top\library\Router;
|
use top\library\Router;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -221,7 +221,7 @@ class Request
|
||||||
*/
|
*/
|
||||||
public function method()
|
public function method()
|
||||||
{
|
{
|
||||||
return $this->router->action;
|
return $this->router->method;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -322,7 +322,7 @@ class Request
|
||||||
$this->beforeRoute();
|
$this->beforeRoute();
|
||||||
|
|
||||||
$ctrl = $this->router->class;
|
$ctrl = $this->router->class;
|
||||||
$action = $this->router->action;
|
$method = $this->router->method;
|
||||||
$params = $this->router->params;
|
$params = $this->router->params;
|
||||||
|
|
||||||
$object = new $ctrl();
|
$object = new $ctrl();
|
||||||
|
|
@ -331,7 +331,7 @@ class Request
|
||||||
$data = $object->_init();
|
$data = $object->_init();
|
||||||
}
|
}
|
||||||
if (!isset($data)) {
|
if (!isset($data)) {
|
||||||
$reflectionMethod = new \ReflectionMethod($ctrl, $action);
|
$reflectionMethod = new \ReflectionMethod($ctrl, $method);
|
||||||
$data = $reflectionMethod->invokeArgs($object, $params);
|
$data = $reflectionMethod->invokeArgs($object, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace top\library\route;
|
namespace top\library\route\driver;
|
||||||
|
|
||||||
use top\library\route\ifs\RouteIfs;
|
use top\library\route\ifs\RouteIfs;
|
||||||
|
|
||||||
|
|
@ -16,8 +16,8 @@ class Command implements RouteIfs
|
||||||
// 控制器
|
// 控制器
|
||||||
public $ctrl = '';
|
public $ctrl = '';
|
||||||
|
|
||||||
// 动作
|
// 方法
|
||||||
public $action = '';
|
public $method = '';
|
||||||
|
|
||||||
// 参数
|
// 参数
|
||||||
public $param = [];
|
public $param = [];
|
||||||
|
|
@ -31,7 +31,7 @@ class Command implements RouteIfs
|
||||||
$this->module = $this->module();
|
$this->module = $this->module();
|
||||||
$this->ctrl = $this->ctrl();
|
$this->ctrl = $this->ctrl();
|
||||||
$this->class = '\\' . APP_NS . '\\' . $this->module . '\\controller\\' . $this->ctrl;
|
$this->class = '\\' . APP_NS . '\\' . $this->module . '\\controller\\' . $this->ctrl;
|
||||||
$this->action = $this->action();
|
$this->method = $this->method();
|
||||||
$this->param = $this->param();
|
$this->param = $this->param();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ class Command implements RouteIfs
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function action()
|
public function method()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return 'index';
|
return 'index';
|
||||||
|
|
@ -65,7 +65,7 @@ class Command implements RouteIfs
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function param()
|
public function params()
|
||||||
{
|
{
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return [];
|
return [];
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace top\library\route;
|
namespace top\library\route\driver;
|
||||||
|
|
||||||
use top\library\route\ifs\RouteIfs;
|
use top\library\route\ifs\RouteIfs;
|
||||||
|
|
||||||
|
|
@ -11,34 +11,64 @@ use top\library\route\ifs\RouteIfs;
|
||||||
class Pathinfo implements RouteIfs
|
class Pathinfo implements RouteIfs
|
||||||
{
|
{
|
||||||
|
|
||||||
// 链接数组
|
/**
|
||||||
|
* 链接数组
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
private $uriArray = [];
|
private $uriArray = [];
|
||||||
|
|
||||||
// 原始链接
|
/**
|
||||||
|
* 原始链接
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $rawUri = '';
|
public $rawUri = '';
|
||||||
|
|
||||||
// 链接
|
/**
|
||||||
|
* 链接
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $uri = '';
|
public $uri = '';
|
||||||
|
|
||||||
// 默认访问位置
|
/**
|
||||||
|
* 默认访问位置
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $default = '';
|
public $default = '';
|
||||||
|
|
||||||
// 分隔符
|
/**
|
||||||
|
* 分隔符
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $separator = '/';
|
public $separator = '/';
|
||||||
|
|
||||||
// 模块
|
/**
|
||||||
|
* 模块
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $module = '';
|
public $module = '';
|
||||||
|
|
||||||
// 控制器
|
/**
|
||||||
|
* 控制器
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $ctrl = '';
|
public $ctrl = '';
|
||||||
|
|
||||||
// 动作
|
/**
|
||||||
public $action = '';
|
* 方法
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $method = '';
|
||||||
|
|
||||||
// 参数
|
/**
|
||||||
|
* 参数
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
public $params = [];
|
public $params = [];
|
||||||
|
|
||||||
// 类名
|
/**
|
||||||
|
* 类名
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
public $class = '';
|
public $class = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -71,7 +101,7 @@ class Pathinfo implements RouteIfs
|
||||||
* 具体执行的方法名
|
* 具体执行的方法名
|
||||||
* @return mixed|string
|
* @return mixed|string
|
||||||
*/
|
*/
|
||||||
public function action()
|
public function method()
|
||||||
{
|
{
|
||||||
if (isset($this->uriArray[2]) && $this->uriArray[2]) {
|
if (isset($this->uriArray[2]) && $this->uriArray[2]) {
|
||||||
return $this->uriArray[2];
|
return $this->uriArray[2];
|
||||||
|
|
@ -172,7 +202,7 @@ class Pathinfo implements RouteIfs
|
||||||
$this->module = $this->module();
|
$this->module = $this->module();
|
||||||
$this->ctrl = $this->ctrl();
|
$this->ctrl = $this->ctrl();
|
||||||
$this->class = '\\' . APP_NS . '\\' . $this->module . '\\controller\\' . $this->ctrl;
|
$this->class = '\\' . APP_NS . '\\' . $this->module . '\\controller\\' . $this->ctrl;
|
||||||
$this->action = $this->action();
|
$this->method = $this->method();
|
||||||
$this->params = $this->params();
|
$this->params = $this->params();
|
||||||
unset($this->uriArray);
|
unset($this->uriArray);
|
||||||
}
|
}
|
||||||
|
|
@ -25,9 +25,9 @@ interface RouteIfs
|
||||||
public function ctrl();
|
public function ctrl();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动作
|
* 方法
|
||||||
*/
|
*/
|
||||||
public function action();
|
public function method();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析参数
|
* 解析参数
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue