This commit is contained in:
2020-08-31 01:27:08 +08:00
parent d6d4027b0d
commit e4f01d9499
119 changed files with 12232 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace HttpServer\Route;
/**
* Class Any
* @package BeReborn\Route
*/
class Any
{
private $nodes = [];
/**
* Any constructor.
* @param array $nodes
*/
public function __construct(array $nodes)
{
$this->nodes = $nodes;
}
/**
* @param $name
* @param $arguments
* @return $this
*/
public function __call($name, $arguments)
{
foreach ($this->nodes as $node) {
$node->{$name}(...$arguments);
}
return $this;
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace HttpServer\Route;
use HttpServer\Http\Request;
use HttpServer\Http\Response;
use HttpServer\Abstracts\MiddlewareHandler;
/**
* Class CoreMiddleware
* @package BeReborn\Route
* 跨域中间件
*/
class CoreMiddleware extends MiddlewareHandler
{
/**
* @param Request $request
* @param \Closure $next
* @return mixed
* @throws \Exception
*/
public function handler(Request $request,\Closure $next)
{
$header = $request->headers;
/** @var Response $response */
$response = \BeReborn::getApp('response');
$request_method = $header->getHeader('access-control-request-method');
$request_headers = $header->getHeader('access-control-request-headers');
$response->addHeader('Access-Control-Allow-Headers', $request_headers);
$response->addHeader('Access-Control-Request-Method', $request_method);
return $next($request);
}
}
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace HttpServer\Route\Dispatch;
use HttpServer\Controller;
/**
* Class Dispatch
* @package HttpServer\Route\Dispatch
*/
class Dispatch
{
protected $handler;
protected $request;
/**
* @param $handler
* @param $request
* @return static
*/
public static function create($handler, $request)
{
$class = new static();
$class->handler = $handler;
$class->request = $request;
if ($handler instanceof \Closure) {
$class->bind();
}
$class->bindParam();
return $class;
}
/**
* @return mixed
* 执行函数
*/
public function dispatch()
{
return call_user_func($this->handler, $this->request);
}
/**
* 设置作用域
*/
protected function bind()
{
$this->handler = \Closure::bind($this->handler, new Controller());
}
/**
* 参数绑定
*/
protected function bindParam()
{
/** @var Controller $controller */
if (is_array($this->handler)) {
$controller = $this->handler[0];
} else {
$controller = $this->handler;
}
$request = \BeReborn::getApp('request');
$controller->setRequest($request);
$controller->setHeaders($request->headers);
$controller->setInput($request->params);
}
}
+129
View File
@@ -0,0 +1,129 @@
<?php
namespace HttpServer\Route;
use HttpServer\Exception\AuthException;
use HttpServer\Route\Filter\BodyFilter;
use HttpServer\Route\Filter\FilterException;
use HttpServer\Route\Filter\HeaderFilter;
use HttpServer\Route\Filter\QueryFilter;
use Exception;
use HttpServer\Application;
/**
* Class Filter
* @package BeReborn\Route
*/
class Filter extends Application
{
/** @var Filter\Filter[] */
private $_filters = [];
/** @var array */
public $grant = [];
/**
* @param array $value
* @return BodyFilter|bool
* @throws Exception
*/
public function setBody(array $value)
{
if (empty($value)) {
return true;
}
/** @var BodyFilter $class */
$class = \BeReborn::createObject(BodyFilter::class);
$class->rules = [];
$class->params = Input()->params();
return $this->_filters[] = $class;
}
/**
* @param array $value
* @return HeaderFilter|bool
* @throws Exception
*/
public function setHeader(array $value)
{
if (empty($value)) {
return true;
}
/** @var HeaderFilter $class */
$class = \BeReborn::createObject(HeaderFilter::class);
$class->rules = [];
$class->params = request()->headers->getHeaders();
return $this->_filters[] = $class;
}
/**
* @param array $value
* @return QueryFilter|bool
* @throws Exception
*/
public function setQuery(array $value)
{
if (empty($value)) {
return true;
}
/** @var QueryFilter $class */
$class = \BeReborn::createObject(QueryFilter::class);
$class->rules = [];
$class->params = request()->headers->getHeaders();
return $this->_filters[] = $class;
}
/**
* @throws Exception
*/
public function handler()
{
if (($error = $this->filters()) !== true) {
throw new FilterException($error);
}
if (!$this->grant()) {
throw new AuthException('Authentication error.');
}
return true;
}
/**
* @return bool
*/
private function filters()
{
if (empty($this->_filters)) {
return true;
}
foreach ($this->_filters as $filter) {
if (!$filter->check()) {
return false;
}
}
return true;
}
/**
* @return bool|mixed
*/
private function grant()
{
if (!is_callable($this->grant, true)) {
return true;
}
return call_user_func($this->grant);
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace HttpServer\Route\Filter;
use Exception;
/**
* Class BodyFilter
* @package BeReborn\Route\Filter
*/
class BodyFilter extends Filter
{
/**
* @return bool
* @throws Exception
*/
public function check()
{
return $this->validator();
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace HttpServer\Route\Filter;
use Exception;
use HttpServer\Application;
use validator\Validator;
/**
* Class Filter
* @package BeReborn\Route\Filter
*/
abstract class Filter extends Application
{
public $rules = [];
public $params = [];
abstract public function check();
/**
* @return bool
* @throws Exception
*/
protected function validator()
{
$validator = Validator::getInstance();
$validator->setParams($this->params);
foreach ($this->rules as $val) {
$field = array_shift($val);
if (empty($val)) {
continue;
}
$validator->make($field, $val);
}
if (!$validator->validation()) {
return $this->addError($validator->getError());
}
return true;
}
}
@@ -0,0 +1,17 @@
<?php
namespace HttpServer\Route\Filter;
use Throwable;
class FilterException extends \Exception
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace HttpServer\Route\Filter;
use Exception;
/**
* Class HeaderFilter
* @package BeReborn\Route\Filter
*/
class HeaderFilter extends Filter
{
/**
* @return bool
* @throws Exception
*/
public function check()
{
return $this->validator();
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace HttpServer\Route\Filter;
use Exception;
/**
* Class QueryFilter
* @package BeReborn\Route\Filter
*/
class QueryFilter extends Filter
{
/**
* @return bool
* @throws Exception
*/
public function check()
{
return $this->validator();
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace HttpServer\Route;
use Exception;
use HttpServer\Application;
/**
* Class TcpListen
* @package BeReborn\Route
*/
class Handler extends Application
{
/** @var Router */
protected $router;
/**
* Listen constructor.
* @throws Exception
*/
public function __construct()
{
$this->router = \BeReborn::$app->getRouter();
parent::__construct([]);
}
/**
* @param $config
* @param $handler
*/
public function group($config, $handler)
{
$this->router->group($config, $handler, $this);
}
/**
* @param $route
* @param $handler
* @return Handler
*/
public function handler($route, $handler)
{
return $this->router->addRoute($route, $handler, 'receive');
}
}
+69
View File
@@ -0,0 +1,69 @@
<?php
namespace HttpServer\Route;
use Exception;
use HttpServer\Application;
/**
* Class Limits
* @package BeReborn\Route
*/
class Limits extends Application
{
public $route = [];
/**
* @param string $path
* @param int $limit
* @param int $duration
* @param bool $isBindConsumer
* @return $this
* 设置限流
*/
public function addLimits(string $path, int $limit, int $duration = 60, bool $isBindConsumer = false)
{
if ($limit < 0) {
$limit = 0;
}
$this->route[$path] = [$limit, $duration, $isBindConsumer];
return $this;
}
/**
* @param int $userId
* @return bool
* @throws Exception
*
* 判断有没有被限流
*/
public function isRestrictedCurrent(int $userId = 0)
{
$path = \request()->getUri();
if (!isset($this->route[$path])) {
return false;
}
$redis = \BeReborn::getRedis();
[$limit, $duration, $isBindConsumer] = $this->route[$path];
if ($limit < 1) {
return false;
}
if ($isBindConsumer && $userId < 1) {
return true;
}
$uri = md5($path) . '_' . $userId;
if ($redis->incr($uri) > $limit) {
return true;
}
if ($redis->ttl($uri) == -1) {
$redis->expire($uri, $duration);
}
return false;
}
}
+77
View File
@@ -0,0 +1,77 @@
<?php
/**
* Created by PhpStorm.
* User: admin
* Date: 2019-03-20
* Time: 02:17
*/
namespace HttpServer\Route;
use Closure;
use Exception;
use HttpServer\IInterface\IMiddleware;
use HttpServer\Route\Dispatch\Dispatch;
/**
* Class Middleware
* @package BeReborn\Route
*/
class Middleware
{
/** @var array */
private $middleWares = [];
/**
* @param $call
* @return $this
*/
public function set($call)
{
$this->middleWares[] = $call;
return $this;
}
/**
* @param array $array
* @return $this
*/
public function setMiddleWares(array $array)
{
$this->middleWares = $array;
return $this;
}
/**
* @param $dispatch
* @return mixed
* @throws Exception
*/
public function getGenerate($dispatch)
{
$last = function ($passable) use ($dispatch) {
return Dispatch::create($dispatch, $passable)->dispatch();
};
$data = array_reduce(array_reverse($this->middleWares), $this->core(), $last);
$this->middleWares = [];
return $data;
}
/**
* @return Closure
*/
public function core()
{
return function ($stack, $pipe) {
return function ($passable) use ($stack, $pipe) {
if ($pipe instanceof IMiddleware) {
return $pipe->handler($passable, $stack);
} else {
return $pipe($passable, $stack);
}
};
};
}
}
+313
View File
@@ -0,0 +1,313 @@
<?php
namespace HttpServer\Route;
use HttpServer\Http\Request;
use Exception;
use HttpServer\Application;
/**
* Class Node
* @package BeReborn\Route
*/
class Node extends Application
{
public $path;
public $index = 0;
public $method;
/** @var Node[] $childes */
public $childes = [];
public $group = [];
public $options = null;
private $_error = '';
public $rules = [];
public $handler;
public $htmlSuffix = '.html';
public $enableHtmlSuffix = false;
public $namespace = [];
public $middleware = [];
public $callback = [];
/**
* @param $handler
* @return Node
* @throws
*/
public function bindHandler($handler)
{
if ($handler instanceof \Closure) {
$this->handler = $handler;
} else if (is_string($handler) && strpos($handler, '@') !== false) {
list($controller, $action) = explode('@', $handler);
if (!empty($this->namespace)) {
$controller = implode('\\', $this->namespace) . '\\' . $controller;
}
$this->handler = $this->getReflect($controller, $action);
} else if ($handler != null && !is_callable($handler, true)) {
$this->_error = 'Controller is con\'t exec.';
} else {
$this->handler = $handler;
}
return $this->newExec();
}
/**
* @param $request
* @return bool
*/
public function methodAllow(Request $request)
{
if ($this->method == $request->getMethod()) {
return true;
}
return $this->method == 'any';
}
/**
* @return bool
* @throws Exception
*/
public function checkSuffix()
{
if ($this->enableHtmlSuffix) {
$url = request()->getUri();
$nowLength = strlen($this->htmlSuffix);
if (strpos($url, $this->htmlSuffix) !== strlen($url) - $nowLength) {
return false;
}
}
return $this->checkRule();
}
/**
* @return bool
* @throws Exception
*/
private function checkRule()
{
if (empty($this->rules)) {
return true;
}
foreach ($this->rules as $rule) {
if (!isset($rule['class'])) {
$rule['class'] = Filter::class;
}
/** @var Filter $object */
$object = \BeReborn::createObject($rule);
if (!$object->handler()) {
return false;
};
}
return true;
}
/**
* @param string $controller
* @param string $action
* @return null|array
* @throws Exception
*/
private function getReflect(string $controller, string $action)
{
try {
$reflect = new \ReflectionClass($controller);
if (!$reflect->isInstantiable()) {
throw new Exception($controller . ' Class is con\'t Instantiable.');
}
if (!empty($action) && !$reflect->hasMethod($action)) {
throw new Exception('method ' . $action . ' not exists at ' . $controller . '.');
}
return [$reflect->newInstance(), $action];
} catch (Exception $exception) {
$this->_error = $exception->getMessage();
$this->error($exception->getMessage(), 'router');
return null;
}
}
/**
* @return string
* 错误信息
*/
public function getError()
{
return $this->_error;
}
/**
* @param Node $node
* @param string $field
* @return Node
*/
public function addChild(Node $node, string $field)
{
/** @var Node $oLod */
$oLod = $this->childes[$field] ?? null;
if (!empty($oLod)) {
$node = $oLod;
}
$this->childes[$field] = $node;
return $this->childes[$field];
}
/**
* @param $rule
* @return $this
*/
public function filter($rule)
{
if (empty($rule)) {
return $this;
}
if (!isset($rule[0])) {
$rule = [$rule];
}
foreach ($rule as $value) {
if (empty($value)) {
continue;
}
$this->rules[] = $value;
}
return $this;
}
/**
* @param string $search
* @return Node|mixed
*/
public function findNode(string $search)
{
if (empty($this->childes)) {
return null;
}
if (isset($this->childes[$search])) {
return $this->childes[$search];
}
$_searchMatch = '/<(\w+)?:(.+)?>/';
foreach ($this->childes as $key => $val) {
if (preg_match($_searchMatch, $key, $match)) {
\Input()->addGetParam($match[1] ?? '--', $search);
return $this->childes[$key];
}
}
return null;
}
/**
* @param $options
* @return $this
*/
public function bindOptions($options)
{
if (is_object($options)) {
$this->options = $options;
} else {
$options = array_filter($options);
$last = $options[count($options) - 1];
if (empty($last)) {
return $this;
}
$this->options = $last;
}
return $this;
}
/**
* @param string $alias
* @return $this
* 别称
*/
public function alias(string $alias)
{
$_alias = $alias;
return $this;
}
/**
* @param int $limit
* @param int $duration
* @param bool $isBindConsumer
* @return $this
* @throws Exception
*/
public function limits(int $limit, int $duration = 60, bool $isBindConsumer = false)
{
$limits = \BeReborn::$app->getLimits();
$limits->addLimits($this->path, $limit, $duration, $isBindConsumer);
return $this;
}
/**
* @param $middles
* @throws
*/
public function bindMiddleware(array $middles)
{
$_tmp = [];
if (empty($middles)) {
return;
}
foreach ($middles as $middle) {
if (empty($middle)) {
continue;
}
try {
if (is_array($middle)) {
$_tmp = $this->each($middle, $_tmp);
} else {
$_tmp[] = \BeReborn::createObject($middle);
}
} catch (Exception $exception) {
}
}
$this->middleware = $_tmp;
$this->newExec();
}
/**
* @throws Exception
*/
private function newExec()
{
if (!empty($this->handler)) {
$made = new Middleware();
$made->setMiddleWares($this->middleware);
$this->callback = $made->getGenerate($this->handler);
}
return $this;
}
/**
* @param $array
* @param $_temp
* @return array
* @throws Exception
*/
private function each($array, $_temp)
{
if (empty($array)) {
return $_temp;
}
foreach ($array as $class) {
if (is_array($class)) {
$_temp = $this->each($class, $_temp);
} else {
$_temp[] = \BeReborn::createObject($class);
}
}
return $_temp;
}
}
+504
View File
@@ -0,0 +1,504 @@
<?php
namespace HttpServer\Route;
use Closure;
use Exception;
use HttpServer\Http\Context;
use HttpServer\Controller;
use HttpServer\IInterface\RouterInterface;
use HttpServer\Application;
use Snowflake\Config;
use Snowflake\Core\JSON;
use Snowflake\Exception\ConfigException;
/**
* Class Router
* @package BeReborn\Route
*/
class Router extends Application implements RouterInterface
{
/** @var Node[] $nodes */
public $nodes = [];
public $groupTacks = [];
public $dir = 'App\\Controllers';
/** @var string[] */
public $methods = ['get', 'post', 'options', 'put', 'delete', 'receive'];
/**
* @throws ConfigException
* 初始化函数路径
*/
public function init()
{
$this->dir = Config::get('controller.path', false, $this->dir);
}
/**
* @param $path
* @param $handler
* @param string $method
* @return mixed|Node|null
* @throws
*/
public function addRoute($path, $handler, $method = 'any')
{
if (!isset($this->nodes[$method])) {
$this->nodes[$method] = [];
}
list($first, $explode) = $this->split($path);
$parent = $this->nodes[$method][$first] ?? null;
if ($handler instanceof \Closure) {
$handler = Closure::bind($handler, new Controller());
}
if (empty($parent)) {
$parent = $this->NodeInstance($first, 0, $method);
$this->nodes[$method][$first] = $parent;
}
if ($first === '/') {
return $parent->bindHandler($handler);
}
$parent = $this->bindNode($parent, $explode, $method);
return $parent->bindHandler($handler);
}
/**
* @param Node $parent
* @param array $explode
* @param $method
* @return Node
*/
private function bindNode($parent, $explode, $method)
{
$a = 0;
if (empty($explode)) {
return $parent->addChild($this->NodeInstance('/', $a, $method), '/');
}
foreach ($explode as $value) {
if (empty($value)) {
continue;
}
++$a;
$search = $parent->findNode($value);
if ($search === null) {
$parent = $parent->addChild($this->NodeInstance($value, $a, $method), $value);
} else {
$parent = $search;
}
}
return $parent;
}
/**
* @param $route
* @param $handler
* @return Node|mixed|null
*/
public function socket($route, $handler)
{
return $this->addRoute($route, $handler, 'socket');
}
/**
* @param $route
* @param $handler
* @param int $port
* @return Node|mixed|null
*/
public function gRpc($route, $handler, $port = 33007)
{
$route = ltrim($route, '/');
if (!empty($port)) {
$route = $port . '/' . $route;
}
return $this->addRoute($route, $handler, 'grpc');
}
/**
* @param $route
* @param $handler
* @return Node|mixed|null
*/
public function task($route, $handler)
{
return $this->addRoute($route, $handler, 'Task');
}
/**
* @param $route
* @param $handler
* @return mixed|Node|null
* @throws
*/
public function post($route, $handler)
{
return $this->addRoute($route, $handler, 'post');
}
/**
* @param $route
* @param $handler
* @return mixed|Node|null
* @throws
*/
public function get($route, $handler)
{
return $this->addRoute($route, $handler, 'get');
}
/**
* @param $route
* @param $handler
* @return mixed|Node|null
* @throws
*/
public function options($route, $handler)
{
return $this->addRoute($route, $handler, 'options');
}
/**
* @param $port
* @param Closure $closure
* @throws
*/
public function listen(int $port, Closure $closure)
{
$stdClass = \BeReborn::createObject(Handler::class);
$this->group(['prefix' => $port], $closure, $stdClass);
}
/**
* @param $route
* @param $handler
* @return Any
*/
public function any($route, $handler)
{
$nodes = [];
foreach (['get', 'post', 'options', 'put', 'delete'] as $method) {
$nodes[] = $this->addRoute($route, $handler, $method);
}
return new Any($nodes);
}
/**
* @param $route
* @param $handler
* @return mixed|Node|null
* @throws
*/
public function delete($route, $handler)
{
return $this->addRoute($route, $handler, 'delete');
}
/**
* @param $route
* @param $handler
* @return mixed|Node|null
* @throws
*/
public function put($route, $handler)
{
return $this->addRoute($route, $handler, 'put');
}
/**
* @param $value
* @param $index
* @param $method
* @return Node
* @throws
*/
public function NodeInstance($value, $index = 0, $method = 'get')
{
$node = new Node();
$node->childes = [];
$node->path = $value;
$node->index = $index;
$node->method = $method;
$name = array_column($this->groupTacks, 'namespace');
$dir = array_column($this->groupTacks, 'dir');
if (!empty($dir)) {
array_unshift($name, implode('\\', $dir));
} else {
if ($method == 'receive') {
$dir = 'App\\Tcp';
} else if ($method == 'package') {
$dir = 'App\\Udp';
} else {
$dir = $this->dir;
}
array_unshift($name, $dir);
}
if (!empty($name) && $name = array_filter($name)) {
$node->namespace = $name;
}
$name = array_column($this->groupTacks, 'middleware');
if (!empty($name) && $name = array_filter($name)) {
$node->bindMiddleware($name);
}
$options = array_column($this->groupTacks, 'options');
if (!empty($options) && is_array($options)) {
$node->bindOptions($options);
}
$rules = array_column($this->groupTacks, 'filter');
$rules = array_shift($rules);
if (!empty($rules) && is_array($rules)) {
$node->filter($rules);
}
return $node;
}
/**
* @param array $config
* @param callable $callback
* 路由分组
* @param null $stdClass
*/
public function group(array $config, callable $callback, $stdClass = null)
{
$this->groupTacks[] = $config;
if ($stdClass) {
$callback($stdClass);
} else {
$callback($this);
}
array_pop($this->groupTacks);
}
/**
* @return string
*/
public function addPrefix()
{
$prefix = array_column($this->groupTacks, 'prefix');
$prefix = array_filter($prefix);
if (empty($prefix)) {
return '';
}
return '/' . implode('/', $prefix);
}
/**
* @param array $explode
* @param $method
* @return Node|null
* 查找指定路由
*/
public function tree_search($explode, $method)
{
if (empty($explode)) {
return $this->nodes[$method]['/'] ?? null;
}
$first = array_shift($explode);
if (!($parent = $this->nodes[$method][$first] ?? null)) {
return null;
}
if (empty($explode)) {
return $parent->findNode('/');
}
while ($value = array_shift($explode)) {
$node = $parent->findNode($value);
if (!$node) {
break;
}
$parent = $node;
}
return $parent;
}
/**
* @param $path
* @return array
* '*'
*/
public function split($path)
{
$prefix = $this->addPrefix();
$path = ltrim($path, '/');
if (!empty($prefix)) {
$path = $prefix . '/' . $path;
}
$explode = array_filter(explode('/', $path));
if (empty($explode)) {
return ['/', []];
}
$first = array_shift($explode);
if (empty($explode)) {
$explode = [];
}
return [$first, $explode];
}
/**
* @return array
*/
public function each()
{
$paths = [];
foreach ($this->nodes as $node) {
/** @var Node[] $node */
foreach ($node as $_node) {
if ($_node->path == '/') {
continue;
}
$path = strtoupper($_node->method) . ' : ' . $_node->path;
if (!empty($_node->childes)) {
$path = $this->readByChild($_node->childes, $path);
}
$paths[] = $path;
}
}
return $this->readByArray($paths);
}
/**
* @param $array
* @param array $returns
* @return array
*/
private function readByArray($array, $returns = [])
{
foreach ($array as $value) {
if (empty($value)) {
continue;
}
if (is_array($value)) {
$returns = $this->readByArray($value, $returns);
} else {
[$method, $route] = explode(' : ', $value);
$returns[] = ['method' => $method, 'route' => $route];
}
}
return $returns;
}
/**
* @param $child
* @param string $paths
* @return array
*/
private function readByChild($child, $paths = '')
{
$newPath = [];
/** @var Node $item */
foreach ($child as $item) {
if ($item->path == '/') {
continue;
}
if (!empty($item->childes)) {
$newPath[] = $this->readByChild($item->childes, $paths . '/' . $item->path);
} else {
[$first, $route] = explode(' : ', $paths);
$newPath[] = strtoupper($item->method) . ' : ' . $route . '/' . $item->path;
}
}
return $newPath;
}
/**
* @return mixed
* @throws
*/
public function dispatch()
{
$request = Context::getContext('request');
if (!($node = $this->find_path($request))) {
return JSON::to(404, 'Page not found.');
}
if (empty($node->callback)) {
return JSON::to(404, 'Page not found.');
}
return call_user_func($node->callback, $request);
}
/**
* @param $request
* @return Node|false|int|mixed|string|null
*/
private function find_path($request)
{
$node = $this->tree_search($request->getExplode(), $request->getMethod());
if ($node instanceof Node) {
return $node;
}
if (!$request->isOption) {
return null;
}
$node = $this->tree_search(['*'], $request->getMethod());
if (!($node instanceof Node)) {
return null;
}
return $node;
}
/**
* @throws
*/
public function loader()
{
try {
$this->loadDir(APP_PATH . '/routes');
} catch (Exception $exception) {
$this->error($exception->getMessage());
}
}
/**
* @param $path
* @throws Exception
* 加载目录下的路由文件
*/
private function loadDir($path)
{
try {
$files = glob($path . '/*');
for ($i = 0; $i < count($files); $i++) {
if (is_dir($files[$i])) {
$this->loadDir($files[$i]);
} else {
$this->loadFile($files[$i]);
}
}
} catch (Exception $exception) {
$this->error($exception->getMessage());
}
}
/**
* @param $file
*/
private function loadFile($file)
{
$router = $this;
include_once "Router.php";
}
}