eee
This commit is contained in:
+13
-1
@@ -12,6 +12,7 @@ use Kiri\Router\Validator\ValidatorMiddleware;
|
|||||||
use Kiri\Router\Base\Middleware as MiddlewareManager;
|
use Kiri\Router\Base\Middleware as MiddlewareManager;
|
||||||
use Kiri\Router\Constrict\RequestMethod;
|
use Kiri\Router\Constrict\RequestMethod;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -61,6 +62,7 @@ class Router
|
|||||||
/**
|
/**
|
||||||
* @param string $route
|
* @param string $route
|
||||||
* @param string $handler
|
* @param string $handler
|
||||||
|
*
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public static function post(string $route, string $handler): void
|
public static function post(string $route, string $handler): void
|
||||||
@@ -72,6 +74,7 @@ class Router
|
|||||||
/**
|
/**
|
||||||
* @param string $route
|
* @param string $route
|
||||||
* @param string $handler
|
* @param string $handler
|
||||||
|
*
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public static function get(string $route, string $handler): void
|
public static function get(string $route, string $handler): void
|
||||||
@@ -84,6 +87,7 @@ class Router
|
|||||||
/**
|
/**
|
||||||
* @param string $route
|
* @param string $route
|
||||||
* @param string $handler
|
* @param string $handler
|
||||||
|
*
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public static function options(string $route, string $handler): void
|
public static function options(string $route, string $handler): void
|
||||||
@@ -96,6 +100,7 @@ class Router
|
|||||||
/**
|
/**
|
||||||
* @param string $route
|
* @param string $route
|
||||||
* @param string $handler
|
* @param string $handler
|
||||||
|
*
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public static function any(string $route, string $handler): void
|
public static function any(string $route, string $handler): void
|
||||||
@@ -107,6 +112,7 @@ class Router
|
|||||||
/**
|
/**
|
||||||
* @param string $route
|
* @param string $route
|
||||||
* @param string $handler
|
* @param string $handler
|
||||||
|
*
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public static function delete(string $route, string $handler): void
|
public static function delete(string $route, string $handler): void
|
||||||
@@ -119,6 +125,7 @@ class Router
|
|||||||
/**
|
/**
|
||||||
* @param string $route
|
* @param string $route
|
||||||
* @param string $handler
|
* @param string $handler
|
||||||
|
*
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public static function head(string $route, string $handler): void
|
public static function head(string $route, string $handler): void
|
||||||
@@ -131,6 +138,7 @@ class Router
|
|||||||
/**
|
/**
|
||||||
* @param string $route
|
* @param string $route
|
||||||
* @param string $handler
|
* @param string $handler
|
||||||
|
*
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public static function put(string $route, string $handler): void
|
public static function put(string $route, string $handler): void
|
||||||
@@ -158,6 +166,7 @@ class Router
|
|||||||
/**
|
/**
|
||||||
* @param array $config
|
* @param array $config
|
||||||
* @param Closure $closure
|
* @param Closure $closure
|
||||||
|
*
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public static function group(array $config, Closure $closure): void
|
public static function group(array $config, Closure $closure): void
|
||||||
@@ -192,6 +201,7 @@ class Router
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
@@ -202,7 +212,7 @@ class Router
|
|||||||
$middlewares = MiddlewareManager::get($method->getClass(), $method->getMethod());
|
$middlewares = MiddlewareManager::get($method->getClass(), $method->getMethod());
|
||||||
$validator = MiddlewareManager::getValidator($method->getClass(), $method->getMethod());
|
$validator = MiddlewareManager::getValidator($method->getClass(), $method->getMethod());
|
||||||
if (!is_null($validator)) {
|
if (!is_null($validator)) {
|
||||||
array_unshift($middlewares, new ValidatorMiddleware($method->getClass(), $method->getMethod()));
|
array_unshift($middlewares, new ValidatorMiddleware(di(ResponseInterface::class), $method->getClass(), $method->getMethod()));
|
||||||
}
|
}
|
||||||
$router->setHttpHandler($name, new HttpRequestHandler($middlewares, $method));
|
$router->setHttpHandler($name, new HttpRequestHandler($middlewares, $method));
|
||||||
}
|
}
|
||||||
@@ -211,6 +221,7 @@ class Router
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $path
|
* @param $path
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
@@ -230,6 +241,7 @@ class Router
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $files
|
* @param $files
|
||||||
|
*
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
private function resolve_file($files): void
|
private function resolve_file($files): void
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ class ValidatorMiddleware implements MiddlewareInterface
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param ResponseInterface $response
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @param string $method
|
* @param string $method
|
||||||
*/
|
*/
|
||||||
public function __construct(public string $class, public string $method)
|
public function __construct(public ResponseInterface $response ,public string $class, public string $method)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ class ValidatorMiddleware implements MiddlewareInterface
|
|||||||
if (!$validator->run($request)) {
|
if (!$validator->run($request)) {
|
||||||
Kiri::getLogger()->println($request->getUri()->getPath() . ' `' . $validator->error() . '`');
|
Kiri::getLogger()->println($request->getUri()->getPath() . ' `' . $validator->error() . '`');
|
||||||
|
|
||||||
return di(ResponseInterface::class)->html($validator->error(), 415);
|
return $this->response->html($validator->error(), 415);
|
||||||
} else {
|
} else {
|
||||||
return $handler->handle($request);
|
return $handler->handle($request);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user