eee
This commit is contained in:
+10
-7
@@ -5,6 +5,7 @@ namespace Kiri\Router\Base;
|
||||
|
||||
use Kiri;
|
||||
use Kiri\Router\Validator\Validator;
|
||||
use Kiri\Router\Validator\ValidatorMiddleware;
|
||||
|
||||
class Middleware
|
||||
{
|
||||
@@ -48,21 +49,23 @@ class Middleware
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param array $validators
|
||||
* @param string $class
|
||||
* @param string $method
|
||||
* @param Validator $validators
|
||||
*/
|
||||
public static function setValidator(string $path, array $validators): void
|
||||
public static function setValidator(string $class, string $method, Validator $validators): void
|
||||
{
|
||||
self::$validators[$path] = $validators;
|
||||
self::$validators[$class . '::' . $method] = $validators;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $class
|
||||
* @param string $method
|
||||
* @return Validator|null
|
||||
*/
|
||||
public static function getValidator(string $path): ?Validator
|
||||
public static function getValidator(string $class, string $method): ?Validator
|
||||
{
|
||||
return static::$validators[$path] ?? null;
|
||||
return static::$validators[$class . '::' . $method] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -190,10 +190,12 @@ class Router
|
||||
public function reset(ContainerInterface $container): void
|
||||
{
|
||||
$router = $container->get(DataGrip::class)->get(static::$type);
|
||||
$middleware = $container->get(MiddlewareManager::class);
|
||||
foreach ($router->getMethods() as $name => $method) {
|
||||
$middlewares = $middleware->get($method->getClass(), $method->getMethod());
|
||||
|
||||
$middlewares = MiddlewareManager::get($method->getClass(), $method->getMethod());
|
||||
$validator = MiddlewareManager::getValidator($method->getClass(), $method->getMethod());
|
||||
if (!is_null($validator)) {
|
||||
$middlewares = array_unshift($middlewares, $validator);
|
||||
}
|
||||
$router->setHttpHandler($name, new HttpRequestHandler($middlewares, $method));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,10 +54,7 @@ class BindForm implements InjectParameterInterface
|
||||
}
|
||||
}
|
||||
|
||||
$middleware = \instance(ValidatorMiddleware::class);
|
||||
$middleware->validator = $validator;
|
||||
|
||||
Middleware::set($class, $method, $middleware);
|
||||
Middleware::setValidator($class, $method, $validator);
|
||||
|
||||
return $validator->getFormData();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user