改名
This commit is contained in:
@@ -49,13 +49,16 @@ class Middleware
|
||||
*/
|
||||
public function getGenerate($node)
|
||||
{
|
||||
$last = function ($passable) use ($node) {
|
||||
return Dispatch::create($node->handler, $passable)->dispatch();
|
||||
};
|
||||
$middleWares = $this->annotation($node);
|
||||
$data = array_reduce(array_reverse($middleWares), $this->core(), $last);
|
||||
$this->middleWares = [];
|
||||
return $node->callback = $data;
|
||||
foreach ($node->handler as $key => $value) {
|
||||
$last = function ($passable) use ($node) {
|
||||
return Dispatch::create($node->handler, $passable)->dispatch();
|
||||
};
|
||||
$middleWares = $this->annotation($node);
|
||||
$data = array_reduce(array_reverse($middleWares), $this->core(), $last);
|
||||
$this->middleWares = [];
|
||||
$node->callback[$key] = $data;
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Node extends Application
|
||||
private $_error = '';
|
||||
|
||||
public $rules = [];
|
||||
public $handler;
|
||||
public $handler = [];
|
||||
public $htmlSuffix = '.html';
|
||||
public $enableHtmlSuffix = false;
|
||||
public $namespace = [];
|
||||
@@ -42,23 +42,24 @@ class Node extends Application
|
||||
|
||||
/**
|
||||
* @param $handler
|
||||
* @param $method
|
||||
* @return Node
|
||||
* @throws
|
||||
* @throws Exception
|
||||
*/
|
||||
public function bindHandler($handler)
|
||||
public function bindHandler($handler, $method)
|
||||
{
|
||||
if ($handler instanceof Closure) {
|
||||
$this->handler = $handler;
|
||||
$this->handler[$method] = $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);
|
||||
$this->handler[$method] = $this->getReflect($controller, $action);
|
||||
} else if ($handler != null && !is_callable($handler, true)) {
|
||||
$this->_error = 'Controller is con\'t exec.';
|
||||
} else {
|
||||
$this->handler = $handler;
|
||||
$this->handler[$method] = $handler;
|
||||
}
|
||||
return $this->restructure();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class Router extends Application implements RouterInterface
|
||||
if ($first !== '/') {
|
||||
$parent = $this->bindNode($parent, $explode, $method);
|
||||
}
|
||||
return $parent->bindHandler($handler);
|
||||
return $parent->bindHandler($handler, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -429,7 +429,7 @@ class Router extends Application implements RouterInterface
|
||||
if (!in_array($request->getMethod(), $node->method)) {
|
||||
return JSON::to(405, 'Method not allowed.');
|
||||
}
|
||||
if (empty($node->callback)) {
|
||||
if (empty($node->callback) || isset($node->callback[$request->getMethod()])) {
|
||||
return JSON::to(404, 'Method does not exist.');
|
||||
}
|
||||
return call_user_func($node->callback, $request);
|
||||
|
||||
Reference in New Issue
Block a user