This commit is contained in:
xl
2023-11-09 20:25:33 +08:00
parent 39329b9f02
commit dbe4288de3
13 changed files with 266 additions and 66 deletions
+20 -2
View File
@@ -3,14 +3,24 @@ declare(strict_types=1);
namespace Kiri\Router\Validator\Inject;
use Kiri\Di\Inject\Container;
use Kiri\Router\Interface\ValidatorInterface;
use Psr\Http\Message\RequestInterface;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class MaxLength implements ValidatorInterface
{
/**
/**
* @var RequestInterface
*/
#[Container(RequestInterface::class)]
public RequestInterface $request;
/**
* @param int $value
*/
public function __construct(readonly public int $value)
@@ -26,6 +36,14 @@ class MaxLength implements ValidatorInterface
public function dispatch(object $class, string $name): bool
{
// TODO: Implement dispatch() method.
return mb_strlen((string)$class->{$name}) <= $this->value;
if ($this->request->getIsPost()) {
$data = $this->request->post($name, null);
} else {
$data = $this->request->query($name, null);
}
if ($data === null) {
return false;
}
return mb_strlen((string)$data) <= $this->value;
}
}