Files
kiri-router/src/Validator/Inject/Length.php
T

34 lines
592 B
PHP
Raw Normal View History

2023-04-15 23:29:27 +08:00
<?php
2023-04-16 01:24:30 +08:00
declare(strict_types=1);
2023-04-15 23:29:27 +08:00
2023-04-15 23:31:16 +08:00
namespace Kiri\Router\Validator\Inject;
use Kiri\Router\Interface\ValidatorInterface;
2023-04-15 23:29:27 +08:00
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Length implements ValidatorInterface
{
2023-11-09 20:25:33 +08:00
/**
2023-04-15 23:29:27 +08:00
* @param int $value
*/
public function __construct(readonly public int $value)
{
}
2023-11-09 22:08:24 +08:00
/**
* @param mixed $data
* @param object $class
* @return bool
*/
public function dispatch(mixed $data, object $class): bool
{
2023-11-09 20:25:33 +08:00
if ($data === null) {
return false;
}
return mb_strlen((string)$data) === $this->value;
2023-04-15 23:29:27 +08:00
}
}