改名
This commit is contained in:
@@ -39,7 +39,7 @@ class Annotation extends \Snowflake\Annotation\Annotation
|
||||
private $Middleware = '';
|
||||
|
||||
|
||||
// private $Route = '';
|
||||
// private $After = '';
|
||||
|
||||
|
||||
protected $_annotations = [];
|
||||
@@ -87,6 +87,9 @@ class Annotation extends \Snowflake\Annotation\Annotation
|
||||
case 'Limits':
|
||||
$this->bindLimits($node, $annotation);
|
||||
break;
|
||||
// case 'After':
|
||||
// $this->bindAfter($node, $annotation);
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +161,38 @@ class Annotation extends \Snowflake\Annotation\Annotation
|
||||
$node->addInterceptor($this->pop($this->getName(...$params)));
|
||||
}
|
||||
}
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * @param Node $node
|
||||
// * @param $annotation
|
||||
// * @throws
|
||||
// */
|
||||
// private function bindAfter($node, $annotation)
|
||||
// {
|
||||
// if (!isset($annotation[1][2])) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// $explode = explode(',', $annotation[1][2]);
|
||||
//
|
||||
// [$keyName, $matchs] = $annotation;
|
||||
// foreach ($explode as $middleware) {
|
||||
// $middleware = 'App\Http\Interceptor\\' . $middleware;
|
||||
// if (!class_exists($middleware)) {
|
||||
// continue;
|
||||
// }
|
||||
// $middleware = Snowflake::createObject($middleware);
|
||||
// if (!($middleware instanceof Interceptor)) {
|
||||
// continue;
|
||||
// }
|
||||
// $node->addAfter([$middleware, 'Interceptor']);
|
||||
// continue;
|
||||
//
|
||||
// $params = [$keyName, [$matchs[0], $matchs[1], $middleware]];
|
||||
// $node->addInterceptor($this->pop($this->getName(...$params)));
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,13 +52,22 @@ class Middleware
|
||||
$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 = [];
|
||||
$data = $this->reduce($last, $this->annotation($node));
|
||||
return $node->callback = $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $last
|
||||
* @param $middleWares
|
||||
* @return mixed|null
|
||||
*/
|
||||
private function reduce($last, $middleWares)
|
||||
{
|
||||
return array_reduce(array_reverse($middleWares), $this->core(), $last);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Node $node
|
||||
* @return array
|
||||
@@ -66,6 +75,7 @@ class Middleware
|
||||
protected function annotation($node)
|
||||
{
|
||||
$middleWares = $this->middleWares;
|
||||
$this->middleWares = [];
|
||||
if (!$node->hasInterceptor()) {
|
||||
return $this->annotation_limit($node, $middleWares);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ class Node extends Application
|
||||
public $callback = [];
|
||||
|
||||
private $_interceptors = [];
|
||||
private $_after = [];
|
||||
private $_limits = [];
|
||||
|
||||
/**
|
||||
@@ -92,6 +93,15 @@ class Node extends Application
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAfters()
|
||||
{
|
||||
return $this->_after;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
@@ -194,6 +204,17 @@ class Node extends Application
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Closure|array|string $handler
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addAfter($handler)
|
||||
{
|
||||
$this->_after[] = $handler;
|
||||
$this->restructure();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Closure|array|string $handler
|
||||
* @throws Exception
|
||||
|
||||
Reference in New Issue
Block a user