This commit is contained in:
as2252258@163.com
2021-04-07 01:53:32 +08:00
parent c3617e89d5
commit ed6cb4cf28
4 changed files with 580 additions and 627 deletions
+1 -75
View File
@@ -409,26 +409,6 @@ class Node extends HttpService
return $this->childes[$field];
}
/**
* @param $rule
* @return $this
*/
public function filter($rule): static
{
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
@@ -476,21 +456,6 @@ class Node extends HttpService
}
/**
* @param int $limit
* @param int $duration
* @param bool $isBindConsumer
* @return $this
* @throws Exception
*/
public function limits(int $limit, int $duration = 60, bool $isBindConsumer = false): static
{
$limits = Snowflake::app()->getLimits();
$limits->addLimits($this->path, $limit, $duration, $isBindConsumer);
return $this;
}
/**
* @param array|Closure|string $class
* @return Node
@@ -498,26 +463,10 @@ class Node extends HttpService
* @throws NotFindClassException
* @throws Exception
*/
public function addMiddleware(Closure|string|array $class): static
public function addMiddleware(Closure|array $class): static
{
if (empty($class)) return $this;
if (is_string($class)) {
$class = $this->resolve_aop($class);
if ($class === null) {
return $this;
}
}
if (is_array($class)) {
if (isset($class[0]) && is_object($class[0])) {
$class = [$class];
}
} else {
$class = [$class];
}
foreach ($class as $closure) {
if (is_string($closure)) {
$closure = [Snowflake::createObject($closure), 'onHandler'];
}
if (in_array($closure, $this->middleware)) {
continue;
}
@@ -527,29 +476,6 @@ class Node extends HttpService
}
/**
* @param string $class
* @return array|null
* @throws NotFindClassException
* @throws ReflectionException
*/
private function resolve_aop(string $class): array|null
{
$class = Snowflake::createObject($class);
if ($class instanceof \HttpServer\IInterface\Middleware) {
return [$class, 'onHandler'];
} else if ($class instanceof Interceptor) {
return [$class, 'Interceptor'];
} else if ($class instanceof After) {
return [$class, 'onHandler'];
} else if ($class instanceof Limits) {
return [$class, 'next'];
} else {
return null;
}
}
/**
* @return array
*/
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -60,7 +60,7 @@ class LengthValidator extends BaseValidator
return $this->addError('The param :attribute length overflow');
}
} else {
if (is_numeric($value) && strlen(floatval($value)) > $this->value) {
if (is_numeric($value) && strlen((string)$value) > $this->value) {
return $this->addError('The param :attribute length overflow');
}
if (strlen($value) > $this->value) {
@@ -83,7 +83,7 @@ class LengthValidator extends BaseValidator
return $this->addError('The param :attribute length error');
}
} else {
if (is_numeric($value) && strlen(floatval($value)) < $this->value) {
if (is_numeric($value) && strlen((string)$value) < $this->value) {
return $this->addError('The param :attribute length overflow');
}
if (strlen($value) < $this->value) {
@@ -106,7 +106,7 @@ class LengthValidator extends BaseValidator
return $this->addError('The param :attribute length error');
}
} else {
if (is_numeric($value) && mb_strlen(floatval($value)) !== $this->value) {
if (is_numeric($value) && strlen((string)$value) !== $this->value) {
return $this->addError('The param :attribute length overflow');
}
if (mb_strlen($value) !== $this->value) {
+2 -2
View File
@@ -126,7 +126,7 @@ class TypesOfValidator extends BaseValidator
if (!is_numeric($value)) {
return $this->addError('The ' . $this->field . ' not is number data.');
}
if (intval($value) != $value) {
if ((int)$value != $value) {
return $this->addError('The ' . $this->field . ' not is number data.');
}
@@ -139,7 +139,7 @@ class TypesOfValidator extends BaseValidator
*/
public function floatFormat($value): bool
{
$trim = floatval((string)$value);
$trim = (float)$value;
if ($trim != $value || !is_float($trim)) {
return $this->addError('The ' . $this->field . ' not is float data.');
}