-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dffffa2
commit e47dfc3
Showing
9 changed files
with
787 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
/.idea/ | ||
/.vscode/ | ||
/.vs/ | ||
/Example/ | ||
/vendor/ | ||
/composer.lock | ||
/composer.lock | ||
/.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<phpunit colors="true" bootstrap="vendor/autoload.php"> | ||
<testsuites> | ||
<testsuite name="Unit Tests"> | ||
<directory>tests/Validation</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* @author Muhammet ŞAFAK <[email protected]> | ||
* @copyright Copyright © 2022 InitPHP | ||
* @license http://initphp.github.io/license.txt MIT | ||
* @version 1.0 | ||
* @version 1.0.2 | ||
* @link https://www.muhammetsafak.com.tr | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* @author Muhammet ŞAFAK <[email protected]> | ||
* @copyright Copyright © 2022 InitPHP | ||
* @license http://initphp.github.io/license.txt MIT | ||
* @version 1.0 | ||
* @version 1.0.2 | ||
* @link https://www.muhammetsafak.com.tr | ||
*/ | ||
|
||
|
@@ -65,7 +65,7 @@ trait RulesTrait | |
], | ||
]; | ||
|
||
private array $patterns = [ | ||
protected array $patterns = [ | ||
'uri' => '[A-Za-z0-9-\/_?&=]+', | ||
'slug' => '[-a-z0-9_-]', | ||
'url' => '[A-Za-z0-9-:.\/_?&=#]+', | ||
|
@@ -81,7 +81,7 @@ trait RulesTrait | |
'address' => '[\p{L}0-9\s.,()°-]+', | ||
'date_dmy' => '[0-9]{1,2}\-[0-9]{1,2}\-[0-9]{4}', | ||
'date_ymd' => '[0-9]{4}\-[0-9]{1,2}\-[0-9]{1,2}', | ||
'email' => '[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+[.]+[a-z-A-Z]' | ||
'email' => '[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+[.]?[a-z-A-Z]?' | ||
]; | ||
|
||
protected function rule_integer($data): bool | ||
|
@@ -167,13 +167,19 @@ protected function rule_mail($data): bool | |
return (bool)filter_var((string)$data, FILTER_VALIDATE_EMAIL); | ||
} | ||
|
||
protected function rule_mailhost($data, $domain): bool | ||
protected function rule_mailhost($data, ...$domain): bool | ||
{ | ||
if(filter_var($data, FILTER_VALIDATE_EMAIL)){ | ||
$parse = explode('@', $data); | ||
$parseDNS = $parse[1] ?? null; | ||
if(trim($parseDNS) === trim($domain)){ | ||
return true; | ||
$parse = explode('@', $data, 2); | ||
$mailHost = trim(($parse[1] ?? '')); | ||
foreach ($domain as $host) { | ||
$host = trim($host); | ||
if(empty($host)){ | ||
continue; | ||
} | ||
if($mailHost === $host){ | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
|
@@ -184,15 +190,21 @@ protected function rule_url($data): bool | |
return (bool)filter_var((string)$data, FILTER_VALIDATE_URL); | ||
} | ||
|
||
protected function rule_urlhost($data, $domain): bool | ||
protected function rule_urlhost($data, ...$domains): bool | ||
{ | ||
if(filter_var($data, FILTER_VALIDATE_URL)){ | ||
$host = parse_url($data, PHP_URL_HOST); | ||
if($host === $domain){ | ||
return true; | ||
} | ||
if(mb_substr($host, -(mb_strlen($domain) + 1)) === '.' . $domain){ | ||
return true; | ||
foreach ($domains as $domain) { | ||
$domain = trim($domain); | ||
if(empty($domain)){ | ||
continue; | ||
} | ||
if($domain === $host){ | ||
return true; | ||
} | ||
if(mb_substr($host, (0 - (mb_strlen($domain) + 1))) === '.' . $domain){ | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
|
@@ -360,7 +372,7 @@ protected function rule_endwith($data, $endWith): bool | |
|
||
protected function rule_in($data, $search): bool | ||
{ | ||
if(is_string($data) && is_numeric($data)){ | ||
if(is_string($data) || is_numeric($data)){ | ||
return mb_stripos((string)$data, (string)$search) !== FALSE; | ||
} | ||
if(is_array($data)){ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* @author Muhammet ŞAFAK <[email protected]> | ||
* @copyright Copyright © 2022 InitPHP | ||
* @license http://initphp.github.io/license.txt MIT | ||
* @version 1.0 | ||
* @version 1.0.2 | ||
* @link https://www.muhammetsafak.com.tr | ||
*/ | ||
|
||
|
@@ -81,6 +81,13 @@ public function clear(): self | |
return $this; | ||
} | ||
|
||
public function pattern(string $name, string $pattern = '[\w]+'): self | ||
{ | ||
$name = strtolower($name); | ||
$this->patterns[$name] = $pattern; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string|string[] $key | ||
* @param string|callable|string[]|callable[] $rule | ||
|
@@ -140,6 +147,7 @@ public function validation(): bool | |
$this->callableProcessValidation($rule); | ||
} | ||
} | ||
$this->rule = []; | ||
return empty($this->error); | ||
} | ||
|
||
|
Oops, something went wrong.