-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from xingshuwangluo/master
增加 闭包验证类 功能
- Loading branch information
Showing
5 changed files
with
107 additions
and
0 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
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,18 @@ | ||
<?php | ||
|
||
namespace Inhere\Validate\Validator; | ||
|
||
abstract class AbstractValidator implements ValidatorInterface | ||
{ | ||
|
||
/** | ||
* 魔术方法,在试图函数式使用对象是调用 | ||
* @param type $value | ||
* @param type $data | ||
* @return bool | ||
*/ | ||
public function __invoke($value, $data): bool { | ||
return (bool) $this->validate($value, $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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Inhere\Validate\Validator; | ||
|
||
/** | ||
* | ||
* 验证器借口 | ||
*/ | ||
interface ValidatorInterface | ||
{ | ||
|
||
/** | ||
* 验证方法,进行验证返回bool类型 | ||
* @param type $value 当前值 | ||
* @param type $data 全部的值 | ||
* @return bool | ||
*/ | ||
public function validate($value, $data): bool; | ||
|
||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Inhere\ValidateTest\Validator; | ||
|
||
/** | ||
* Class ClassValidator | ||
* @package Inhere\ValidateTest\Validator | ||
*/ | ||
class AdemoValidatorTest extends \Inhere\Validate\Validator\AbstractValidator | ||
{ | ||
|
||
|
||
public function validate($value, $data): bool | ||
{ | ||
if ($value == 1) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |