eee
This commit is contained in:
@@ -3,13 +3,22 @@ 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 Email implements ValidatorInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -26,6 +35,14 @@ class Email implements ValidatorInterface
|
||||
*/
|
||||
public function dispatch(object $class, string $name): bool
|
||||
{
|
||||
return filter_var($class->{$name}, FILTER_VALIDATE_EMAIL);
|
||||
if ($this->request->getIsPost()) {
|
||||
$data = $this->request->post($name, null);
|
||||
} else {
|
||||
$data = $this->request->query($name, null);
|
||||
}
|
||||
if ($data === null) {
|
||||
return false;
|
||||
}
|
||||
return filter_var($data, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,22 @@ 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 In implements ValidatorInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
|
||||
/**
|
||||
* @param array $value
|
||||
*/
|
||||
@@ -25,6 +34,14 @@ class In implements ValidatorInterface
|
||||
*/
|
||||
public function dispatch(object $class, string $name): bool
|
||||
{
|
||||
return in_array($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 in_array($data, $this->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,20 @@ 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 Length implements ValidatorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
@@ -26,6 +34,14 @@ class Length 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,20 @@ 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 Max implements ValidatorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
@@ -26,6 +34,14 @@ class Max implements ValidatorInterface
|
||||
public function dispatch(object $class, string $name): bool
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
return $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 $data <= $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,23 @@ 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
|
||||
*/
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,22 @@ 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 Min implements ValidatorInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*/
|
||||
@@ -26,6 +35,14 @@ class Min implements ValidatorInterface
|
||||
public function dispatch(object $class, string $name): bool
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
return $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 $data >= $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,22 @@ 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 MinLength implements ValidatorInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*/
|
||||
@@ -26,6 +35,14 @@ class MinLength 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,20 @@ 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 Must implements ValidatorInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
@@ -27,7 +35,12 @@ class Must implements ValidatorInterface
|
||||
public function dispatch(object $class, string $name): bool
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
return $class->{$name} === $this->value;
|
||||
if ($this->request->getIsPost()) {
|
||||
$data = $this->request->post($name, null);
|
||||
} else {
|
||||
$data = $this->request->query($name, null);
|
||||
}
|
||||
return $data === $this->value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,22 @@ 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 NotEmpty implements ValidatorInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $name
|
||||
@@ -17,6 +27,11 @@ class NotEmpty implements ValidatorInterface
|
||||
public function dispatch(object $class, string $name): bool
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
return !empty($class->{$name});
|
||||
if ($this->request->getIsPost()) {
|
||||
$data = $this->request->post($name, null);
|
||||
} else {
|
||||
$data = $this->request->query($name, null);
|
||||
}
|
||||
return !empty($data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ 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)]
|
||||
@@ -11,6 +13,14 @@ class NotIn implements ValidatorInterface
|
||||
{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
|
||||
/**
|
||||
* @param array $value
|
||||
*/
|
||||
@@ -27,6 +37,11 @@ class NotIn implements ValidatorInterface
|
||||
public function dispatch(object $class, string $name): bool
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
return !in_array($class->{$name}, $this->value);
|
||||
if ($this->request->getIsPost()) {
|
||||
$data = $this->request->post($name, null);
|
||||
} else {
|
||||
$data = $this->request->query($name, null);
|
||||
}
|
||||
return !in_array($data, $this->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,21 @@ 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 NotNull implements ValidatorInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $name
|
||||
@@ -18,6 +26,11 @@ class NotNull implements ValidatorInterface
|
||||
public function dispatch(object $class, string $name): bool
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
return $class->{$name} !== null;
|
||||
if ($this->request->getIsPost()) {
|
||||
$data = $this->request->post($name, null);
|
||||
} else {
|
||||
$data = $this->request->query($name, null);
|
||||
}
|
||||
return !($data === null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,22 @@ 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 Phone implements ValidatorInterface
|
||||
{
|
||||
const REG = '/^1[356789]\d{9}$/';
|
||||
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $name
|
||||
@@ -17,6 +26,11 @@ class Phone implements ValidatorInterface
|
||||
*/
|
||||
public function dispatch(object $class, string $name): bool
|
||||
{
|
||||
return preg_match(self::REG, $class->{$name});
|
||||
if ($this->request->getIsPost()) {
|
||||
$data = $this->request->post($name, null);
|
||||
} else {
|
||||
$data = $this->request->query($name, null);
|
||||
}
|
||||
return preg_match(self::REG, $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,21 @@ 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 Required implements ValidatorInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Container(RequestInterface::class)]
|
||||
public RequestInterface $request;
|
||||
|
||||
/**
|
||||
* @param object $class
|
||||
* @param string $name
|
||||
@@ -17,8 +25,12 @@ class Required implements ValidatorInterface
|
||||
*/
|
||||
public function dispatch(object $class, string $name): bool
|
||||
{
|
||||
// TODO: Implement dispatch() method.
|
||||
return $class->$name === null;
|
||||
if ($this->request->getIsPost()) {
|
||||
$data = $this->request->post($name, null);
|
||||
} else {
|
||||
$data = $this->request->query($name, null);
|
||||
}
|
||||
return !($data === null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user