改名
This commit is contained in:
@@ -82,6 +82,9 @@ class Annotation extends \Snowflake\Annotation\Annotation
|
||||
case 'Middleware':
|
||||
$this->bindMiddleware($node, $annotation);
|
||||
break;
|
||||
case 'Limits':
|
||||
$this->bindLimits($node, $annotation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +147,27 @@ class Annotation extends \Snowflake\Annotation\Annotation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Node $node
|
||||
* @param $annotation
|
||||
* @throws
|
||||
*/
|
||||
private function bindLimits($node, $annotation)
|
||||
{
|
||||
if (!isset($annotation[1][2])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$explode = explode(',', $annotation[1][2]);
|
||||
|
||||
[$keyName, $matchs] = $annotation;
|
||||
foreach ($explode as $middleware) {
|
||||
$params = [$keyName, [$matchs[0], $matchs[1], $middleware]];
|
||||
$node->addLimits($this->pop($this->getName(...$params)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $controller
|
||||
* @param $methodName
|
||||
|
||||
@@ -63,15 +63,32 @@ class Middleware
|
||||
* @param Node $node
|
||||
* @return array
|
||||
*/
|
||||
public function annotation($node)
|
||||
protected function annotation($node)
|
||||
{
|
||||
$middleWares = $this->middleWares;
|
||||
if (!$node->hasInterceptor()) {
|
||||
return $middleWares;
|
||||
return $this->annotation_limit($node, $middleWares);
|
||||
}
|
||||
foreach ($node->getInterceptor() as $item) {
|
||||
$middleWares[] = $item[0];
|
||||
}
|
||||
return $this->annotation_limit($node, $middleWares);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Node $node
|
||||
* @param $middleWares
|
||||
* @return array
|
||||
*/
|
||||
protected function annotation_limit($node, $middleWares)
|
||||
{
|
||||
if (!$node->hasLimits()) {
|
||||
return $middleWares;
|
||||
}
|
||||
foreach ($node->getLimits() as $item) {
|
||||
$middleWares[] = $item[0];
|
||||
}
|
||||
return $middleWares;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ class Node extends Application
|
||||
public $callback = [];
|
||||
|
||||
private $_interceptors = [];
|
||||
private $_limits = [];
|
||||
|
||||
/**
|
||||
* @param $handler
|
||||
@@ -73,6 +74,15 @@ class Node extends Application
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasLimits()
|
||||
{
|
||||
return count($this->_limits) > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -81,6 +91,16 @@ class Node extends Application
|
||||
return $this->_interceptors;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLimits()
|
||||
{
|
||||
return $this->_limits;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $request
|
||||
* @return bool
|
||||
@@ -174,6 +194,17 @@ class Node extends Application
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Closure|array|string $handler
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addLimits($handler)
|
||||
{
|
||||
$this->_limits[] = $handler;
|
||||
$this->restructure();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* 错误信息
|
||||
|
||||
Reference in New Issue
Block a user