modify
This commit is contained in:
@@ -409,26 +409,6 @@ class Node extends HttpService
|
|||||||
return $this->childes[$field];
|
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
|
* @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
|
* @param array|Closure|string $class
|
||||||
* @return Node
|
* @return Node
|
||||||
@@ -498,26 +463,10 @@ class Node extends HttpService
|
|||||||
* @throws NotFindClassException
|
* @throws NotFindClassException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function addMiddleware(Closure|string|array $class): static
|
public function addMiddleware(Closure|array $class): static
|
||||||
{
|
{
|
||||||
if (empty($class)) return $this;
|
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) {
|
foreach ($class as $closure) {
|
||||||
if (is_string($closure)) {
|
|
||||||
$closure = [Snowflake::createObject($closure), 'onHandler'];
|
|
||||||
}
|
|
||||||
if (in_array($closure, $this->middleware)) {
|
if (in_array($closure, $this->middleware)) {
|
||||||
continue;
|
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
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|||||||
+574
-547
File diff suppressed because it is too large
Load Diff
@@ -60,7 +60,7 @@ class LengthValidator extends BaseValidator
|
|||||||
return $this->addError('The param :attribute length overflow');
|
return $this->addError('The param :attribute length overflow');
|
||||||
}
|
}
|
||||||
} else {
|
} 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');
|
return $this->addError('The param :attribute length overflow');
|
||||||
}
|
}
|
||||||
if (strlen($value) > $this->value) {
|
if (strlen($value) > $this->value) {
|
||||||
@@ -83,7 +83,7 @@ class LengthValidator extends BaseValidator
|
|||||||
return $this->addError('The param :attribute length error');
|
return $this->addError('The param :attribute length error');
|
||||||
}
|
}
|
||||||
} else {
|
} 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');
|
return $this->addError('The param :attribute length overflow');
|
||||||
}
|
}
|
||||||
if (strlen($value) < $this->value) {
|
if (strlen($value) < $this->value) {
|
||||||
@@ -106,7 +106,7 @@ class LengthValidator extends BaseValidator
|
|||||||
return $this->addError('The param :attribute length error');
|
return $this->addError('The param :attribute length error');
|
||||||
}
|
}
|
||||||
} else {
|
} 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');
|
return $this->addError('The param :attribute length overflow');
|
||||||
}
|
}
|
||||||
if (mb_strlen($value) !== $this->value) {
|
if (mb_strlen($value) !== $this->value) {
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class TypesOfValidator extends BaseValidator
|
|||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
return $this->addError('The ' . $this->field . ' not is number data.');
|
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.');
|
return $this->addError('The ' . $this->field . ' not is number data.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ class TypesOfValidator extends BaseValidator
|
|||||||
*/
|
*/
|
||||||
public function floatFormat($value): bool
|
public function floatFormat($value): bool
|
||||||
{
|
{
|
||||||
$trim = floatval((string)$value);
|
$trim = (float)$value;
|
||||||
if ($trim != $value || !is_float($trim)) {
|
if ($trim != $value || !is_float($trim)) {
|
||||||
return $this->addError('The ' . $this->field . ' not is float data.');
|
return $this->addError('The ' . $this->field . ' not is float data.');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user