Skip to content

Commit

Permalink
IsEmail规则
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Mar 15, 2023
1 parent 9357aa8 commit 6fc1a1b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/Validator/IsEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace EasySwoole\HttpAnnotation\Validator;

use EasySwoole\HttpAnnotation\Attributes\Param;
use EasySwoole\HttpAnnotation\Validator\AbstractInterface\AbstractValidator;
use Psr\Http\Message\ServerRequestInterface;

class IsEmail extends AbstractValidator
{
function __construct(?string $errorMsg = null)
{
if(empty($errorMsg)){
$errorMsg = "{#name} must be a email address";
}
$this->errorMsg($errorMsg);
}


protected function validate(Param $param, ServerRequestInterface $request): bool
{
$itemData = $param->parsedValue();
if (!is_string($itemData)) {
return false;
}

if (!filter_var($itemData, FILTER_VALIDATE_EMAIL)) {
return false;
}
return true;
}

function ruleName(): string
{
return 'IsEmail';
}
}
1 change: 0 additions & 1 deletion src/Validator/IsUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class IsUrl extends AbstractValidator
{
private $test = false;
function __construct(?string $errorMsg = null)
{
if(empty($errorMsg)){
Expand Down

0 comments on commit 6fc1a1b

Please sign in to comment.