Skip to content

Commit 80f0c24

Browse files
committed
change namespace and class name to upper
1 parent cf032cd commit 80f0c24

12 files changed

+62
-34
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ git clone https://github.com/inhere/php-validate.git // github
4848
<a name="how-to-use"></a>
4949
### 方式 1: 创建一个新的class,并继承Validation
5050

51-
创建一个新的class,并继承 `inhere\validate\Validation`。用于一个(或一系列相关)请求的验证, 相当于 laravel 的 表单请求验证
51+
创建一个新的class,并继承 `Inhere\Validate\Validation`。用于一个(或一系列相关)请求的验证, 相当于 laravel 的 表单请求验证
5252

5353
> 此方式是最为完整的使用方式
5454
5555
```php
5656

57-
use inhere\validate\Validation;
57+
use Inhere\Validate\Validation;
5858

5959
class PageRequest extends Validation
6060
{
@@ -129,11 +129,11 @@ $db->save($safeData);
129129

130130
### 方式 2: 直接使用类 Validation
131131

132-
需要快速简便的使用验证时,可直接使用 `inhere\validate\Validation`
132+
需要快速简便的使用验证时,可直接使用 `Inhere\Validate\Validation`
133133

134134
```php
135135

136-
use inhere\validate\Validation;
136+
use Inhere\Validate\Validation;
137137

138138
class SomeController
139139
{
@@ -160,14 +160,14 @@ $db->save($safeData);
160160

161161
### 方式 1: 创建一个新的class,使用 ValidationTrait
162162

163-
创建一个新的class,并使用 Trait `inhere\validate\ValidationTrait`。 此方式是高级自定义的使用方式, 可以方便的嵌入到其他类中
163+
创建一个新的class,并使用 Trait `Inhere\Validate\ValidationTrait`。 此方式是高级自定义的使用方式, 可以方便的嵌入到其他类中
164164

165165
如下, 嵌入到一个数据模型类中,添加数据库记录前自动进行验证
166166

167167
```php
168168
class DataModel
169169
{
170-
use \inhere\validate\ValidationTrait;
170+
use \Inhere\Validate\ValidationTrait;
171171

172172
protected $data = [];
173173

@@ -235,7 +235,7 @@ $db->save($safeData);
235235

236236
## 如何添加自定义验证器
237237

238-
- 在继承了 `inhere\validate\Validation` 的子类添加验证方法. 请看上面的 **使用方式1**
238+
- 在继承了 `Inhere\Validate\Validation` 的子类添加验证方法. 请看上面的 **使用方式1**
239239
- 通过 `Validation::addValidator()` 添加自定义验证器. e.g:
240240

241241
```php

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "inhere/php-validate",
33
"type": "library",
44
"description": "a simple validate library of the php",
5-
"keywords": ["library","validate"],
5+
"keywords": ["library", "validate"],
66
"homepage": "http://github.com/inhere/php-validate",
77
"license": "MIT",
88
"authors": [
@@ -17,7 +17,7 @@
1717
},
1818
"autoload": {
1919
"psr-4": {
20-
"inhere\\validate\\" : "src/"
20+
"Inhere\\Validate\\" : "src/"
2121
}
2222
},
2323
"suggest": {

examples/DataModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
class DataModel
99
{
10-
use \inhere\validate\ValidationTrait;
10+
use \Inhere\Validate\ValidationTrait;
1111

1212
protected $data = [];
1313

examples/PageRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Class PageRequest
1111
*/
12-
class PageRequest extends \inhere\validate\Validation
12+
class PageRequest extends \Inhere\Validate\Validation
1313
{
1414
public function rules()
1515
{

examples/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
spl_autoload_register(function($class)
44
{
5-
// e.g. "inhere\validate\ValidationTrait"
5+
// e.g. "Inhere\Validate\ValidationTrait"
66
if (strpos($class,'\\')) {
77
$file = dirname(__DIR__) . '/src/' . trim(strrchr($class,'\\'),'\\'). '.php';
88
} else {
@@ -81,8 +81,8 @@
8181

8282
echo "\n----------------------------\n use Validation\n----------------------------\n\n";
8383

84-
$valid = \inhere\validate\Validation::make($data, $rules)
85-
->setAttrTrans([
84+
$valid = \Inhere\Validate\Validation::make($data, $rules)
85+
->setTranslates([
8686
'goods.pear' => '梨子'
8787
])
8888
->validate([], false);

src/ErrorMessage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Time: 11:26
77
*/
88

9-
namespace inhere\validate;
9+
namespace Inhere\Validate;
1010

1111
/**
1212
* Class ErrorMessage
13-
* @package inhere\validate
13+
* @package Inhere\Validate
1414
*
1515
*/
1616
class ErrorMessage

src/FilterList.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
* @date 2015.08.05
44
* 过滤器(strainer/filter): 过滤数据,去除不合要求的数据,返回过滤后的数据(始终返回字符串, 全部不符合返回空字符串)
55
*/
6-
namespace inhere\validate;
6+
namespace Inhere\Validate;
77

88
/**
99
* Class FilterList
10-
* @package inhere\validate
10+
* @package Inhere\Validate
1111
*/
1212
final class FilterList
1313
{
14-
/////////////////////////////// php internal Filter ///////////////////////////////
15-
1614
/**
1715
* simple trim space
1816
* @param $var

src/Filtration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Time: 23:19
77
*/
88

9-
namespace inhere\validate;
9+
namespace Inhere\Validate;
1010

1111
/**
1212
* Class Filtration
13-
* @package inhere\validate
13+
* @package Inhere\Validate
1414
*
1515
* usage:
1616
*

src/Helper.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
/**
33
*
44
*/
5-
namespace inhere\validate;
5+
namespace Inhere\Validate;
66

77
/**
88
* Class StrHelper
9-
* @package inhere\validate
9+
* @package Inhere\Validate
1010
*/
1111
class Helper
1212
{
@@ -193,4 +193,31 @@ public static function getValueOfArray(array $array, $key, $default = null)
193193

194194
return $array;
195195
}
196+
197+
/**
198+
* @param $cb
199+
* @param array $args
200+
* @return mixed
201+
*/
202+
public static function call($cb, array $args = [])
203+
{
204+
$args = array_values($args);
205+
206+
if (
207+
(is_object($cb) && method_exists($cb, '__invoke')) ||
208+
(is_string($cb) && function_exists($cb))
209+
) {
210+
$ret = $cb(...$args);
211+
} elseif (is_array($cb)) {
212+
list($obj, $mhd) = $cb;
213+
214+
$ret = is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args);
215+
} elseif (method_exists('Swoole\Coroutine', 'call_user_func_array')) {
216+
$ret = \Swoole\Coroutine::call_user_func_array($cb, $args);
217+
} else {
218+
$ret = call_user_func_array($cb, $args);
219+
}
220+
221+
return $ret;
222+
}
196223
}

src/Validation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Time: 23:19
77
*/
88

9-
namespace inhere\validate;
9+
namespace Inhere\Validate;
1010

1111
/**
1212
* Class Validation
13-
* @package inhere\validate
13+
* @package Inhere\Validate
1414
*
1515
* usage:
1616
*
@@ -52,7 +52,7 @@ public function __construct(array $data = [], array $rules = [], array $translat
5252
$this
5353
->setRules($rules)
5454
->setScene($scene)
55-
->setAttrTrans($translates);
55+
->setTranslates($translates);
5656

5757
if ($startValidate) {
5858
$this->validate();

src/ValidationTrait.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
* Used: 主要功能是 hi
88
*/
99

10-
namespace inhere\validate;
10+
namespace Inhere\Validate;
1111

1212
/**
1313
* Trait ValidationTrait
14-
* @package inhere\validate
14+
* @package Inhere\Validate
1515
*
1616
* @property array $data To verify the data list. please define it on main class. 待验证的数据列表
1717
*/
@@ -256,7 +256,7 @@ public function validate(array $onlyChecked = [], $stopOnError = null)
256256
}
257257

258258
// 设定了为空跳过 并且 值为空
259-
if ($skipOnEmpty && call_user_func($isEmpty, $value)) {
259+
if ($skipOnEmpty && Helper::call($isEmpty, $value)) {
260260
continue;
261261
}
262262

@@ -796,10 +796,13 @@ public function addValidator(string $name, \Closure $callback, string $msg = '')
796796
* @param \Closure $callback
797797
* @param string $msg
798798
*/
799-
public static function setValidator(string $name, \Closure $callback, string $msg = '')
799+
public static function setValidator(string $name, \Closure $callback, string $msg = null)
800800
{
801801
self::$_validators[$name] = $callback;
802-
self::setDefaultMessage($name, $msg);
802+
803+
if ($msg) {
804+
self::setDefaultMessage($name, $msg);
805+
}
803806
}
804807

805808
/**

src/ValidatorList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
* 后期通过类似 $_GET['test']='help'; 将不会存在 输入数据常量中(INPUT_GET 没有test项)。
88
*/
99

10-
namespace inhere\validate;
10+
namespace Inhere\Validate;
1111

1212
/**
1313
* Class ValidatorList
14-
* @package inhere\validate
14+
* @package Inhere\Validate
1515
*/
1616
final class ValidatorList
1717
{

0 commit comments

Comments
 (0)