This commit is contained in:
2020-12-15 18:50:28 +08:00
parent 4695c2a598
commit 46171f5bed
+26 -11
View File
@@ -223,7 +223,12 @@ class Node extends Application
*/ */
public function addInterceptor(Closure|string|array $handler) public function addInterceptor(Closure|string|array $handler)
{ {
$this->_interceptors[] = $handler; if (!is_array($handler) || is_object($handler[0])) {
$handler = [$handler];
}
foreach ($handler as $closure) {
$this->_interceptors[] = $closure;
}
$this->restructure(); $this->restructure();
} }
@@ -234,7 +239,12 @@ class Node extends Application
*/ */
public function addAfter(Closure|string|array $handler) public function addAfter(Closure|string|array $handler)
{ {
$this->_after[] = $handler; if (!is_array($handler) || is_object($handler[0])) {
$handler = [$handler];
}
foreach ($handler as $closure) {
$this->_after[] = $closure;
}
$this->restructure(); $this->restructure();
} }
@@ -245,7 +255,12 @@ class Node extends Application
*/ */
public function addLimits(Closure|string|array $handler) public function addLimits(Closure|string|array $handler)
{ {
$this->_limits[] = $handler; if (!is_array($handler) || is_object($handler[0])) {
$handler = [$handler];
}
foreach ($handler as $closure) {
$this->_limits[] = $closure;
}
$this->restructure(); $this->restructure();
} }
@@ -254,7 +269,7 @@ class Node extends Application
* @return string * @return string
* 错误信息 * 错误信息
*/ */
public function getError() public function getError(): string
{ {
return $this->_error; return $this->_error;
} }
@@ -264,7 +279,7 @@ class Node extends Application
* @param string $field * @param string $field
* @return Node * @return Node
*/ */
public function addChild(Node $node, string $field) public function addChild(Node $node, string $field): Node
{ {
/** @var Node $oLod */ /** @var Node $oLod */
$oLod = $this->childes[$field] ?? null; $oLod = $this->childes[$field] ?? null;
@@ -279,7 +294,7 @@ class Node extends Application
* @param $rule * @param $rule
* @return $this * @return $this
*/ */
public function filter($rule) public function filter($rule): static
{ {
if (empty($rule)) { if (empty($rule)) {
return $this; return $this;
@@ -298,9 +313,9 @@ class Node extends Application
/** /**
* @param string $search * @param string $search
* @return Node|mixed * @return Node|null
*/ */
public function findNode(string $search) public function findNode(string $search): ?Node
{ {
if (empty($this->childes)) { if (empty($this->childes)) {
return null; return null;
@@ -326,7 +341,7 @@ class Node extends Application
* @return $this * @return $this
* 别称 * 别称
*/ */
public function alias(string $alias) public function alias(string $alias): static
{ {
$this->_alias = $alias; $this->_alias = $alias;
return $this; return $this;
@@ -336,7 +351,7 @@ class Node extends Application
/** /**
* @return string * @return string
*/ */
public function getAlias() public function getAlias(): string
{ {
return $this->_alias; return $this->_alias;
} }
@@ -349,7 +364,7 @@ class Node extends Application
* @return $this * @return $this
* @throws Exception * @throws Exception
*/ */
public function limits(int $limit, int $duration = 60, bool $isBindConsumer = false) public function limits(int $limit, int $duration = 60, bool $isBindConsumer = false): static
{ {
$limits = Snowflake::app()->getLimits(); $limits = Snowflake::app()->getLimits();
$limits->addLimits($this->path, $limit, $duration, $isBindConsumer); $limits->addLimits($this->path, $limit, $duration, $isBindConsumer);