Skip to content

Commit

Permalink
优化 params 获取
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhei2008 committed Aug 28, 2019
1 parent f9d8ede commit 51e56e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ vendor/
.env
.DS_Store
*.lock
node_modules/*
27 changes: 20 additions & 7 deletions src/validation/src/Middleware/ValidationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@

namespace Hyperf\Validation\Middleware;

use Hyperf\HttpServer\CoreMiddleware;
use Hyperf\Validation\Contracts\Validation\ValidatesWhenResolved;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class ValidationMiddleware extends CoreMiddleware
class ValidationMiddleware implements MiddlewareInterface
{
/**
* @var ContainerInterface
Expand All @@ -28,16 +31,26 @@ public function __construct(ContainerInterface $container)
parent::__construct($container, 'http');
}

public function parseParameters(string $controller, string $action, array $arguments): array
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$params = parent::parseParameters($controller, $action, $arguments);

$params = $request->get(Dispatched);
foreach ($params as $param) {
if ($param instanceof ValidatesWhenResolved) {
$param->validateResolved();
}
}

return $params;
}
//
// public function parseParameters(string $controller, string $action, array $arguments): array
// {
// $params = parent::parseParameters($controller, $action, $arguments);
//
// foreach ($params as $param) {
// if ($param instanceof ValidatesWhenResolved) {
// $param->validateResolved();
// }
// }
//
// return $params;
// }
}

0 comments on commit 51e56e5

Please sign in to comment.