Skip to content

Commit 9669458

Browse files
committed
merge master code to branch php5
2 parents 1851daf + 423a04b commit 9669458

32 files changed

+3012
-1359
lines changed

README.md

Lines changed: 301 additions & 156 deletions
Large diffs are not rendered by default.

api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# methods API

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: 2 additions & 2 deletions
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
{
@@ -26,7 +26,7 @@ public function rules()
2626
];
2727
}
2828

29-
public function attrTrans()
29+
public function translates()
3030
{
3131
return [
3232
'userId' => '用户Id',

examples/field.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
require __DIR__ . '/simple-loader.php';
4+
5+
$data = [
6+
// 'userId' => 234,
7+
'userId' => 'is not an integer',
8+
'tagId' => '234535',
9+
// 'freeTime' => '1456767657', // filed not exists
10+
'note' => '',
11+
'name' => 'Ajohn',
12+
'existsField' => 'test',
13+
'passwd' => 'password',
14+
'repasswd' => 'repassword',
15+
'insertTime' => '1456767657',
16+
'goods' => [
17+
'apple' => 34,
18+
'pear' => 50,
19+
],
20+
];
21+
22+
$rules = [
23+
['userId', 'required|int'],
24+
['tagId', 'size:0,50'],
25+
];
26+
27+
echo "\n----------------------------\n use FieldValidation\n----------------------------\n\n";
28+
29+
$v = \Inhere\Validate\FieldValidation::make($data, $rules)
30+
->setTranslates([
31+
'goods.pear' => '梨子'
32+
])
33+
->setMessages([
34+
'freeTime.required' => 'freeTime is required!!!!'
35+
])
36+
->validate([], false);
37+
38+
print_r($v->getErrors());

examples/filter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 2017-11-24
6+
* Time: 18:13
7+
*/

examples/index.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
<?php
22

3-
spl_autoload_register(function($class)
4-
{
5-
// e.g. "inhere\validate\ValidationTrait"
6-
if (strpos($class,'\\')) {
7-
$file = dirname(__DIR__) . '/src/' . trim(strrchr($class,'\\'),'\\'). '.php';
8-
} else {
9-
$file = __DIR__ . '/' . $class. '.php';
10-
}
11-
12-
if (is_file($file)) {
13-
include $file;
14-
}
15-
});
3+
require __DIR__ . '/simple-loader.php';
164

175
$data = [
186
// 'userId' => 234,
@@ -23,7 +11,7 @@
2311
'name' => 'Ajohn',
2412
'existsField' => 'test',
2513
'passwd' => 'password',
26-
'repasswd' => 'repassword',
14+
'repasswd' => 'password',
2715
'insertTime' => '1456767657',
2816
'goods' => [
2917
'apple' => 34,
@@ -32,7 +20,7 @@
3220
];
3321

3422
$rules = [
35-
['tagId,userId,freeTime', 'required', 'msg' => '{attr} is required!'],// set message
23+
['tagId,userId,freeTime', 'required'],// set message
3624
['tagId,userId,freeTime', 'number'],
3725
['note', 'email', 'skipOnEmpty' => false], // set skipOnEmpty is false.
3826
['insertTime', 'email', 'scene' => 'otherScene' ],// set scene. will is not validate it on default.
@@ -75,17 +63,23 @@
7563
//$model = new DataModel($_POST,$rules);
7664
$model = new DataModel;
7765
$model->setData($data)->setRules($rules);
66+
$model->setMessages([
67+
'freeTime.required' => 'freeTime is required!!!!'
68+
]);
7869
$model->validate();
7970

8071
print_r($model->getErrors());
8172

8273
echo "\n----------------------------\n use Validation\n----------------------------\n\n";
8374

84-
$valid = \inhere\validate\Validation::make($data, $rules)
85-
->setAttrTrans([
75+
$v = \Inhere\Validate\Validation::make($data, $rules)
76+
->setTranslates([
8677
'goods.pear' => '梨子'
8778
])
79+
->setMessages([
80+
'freeTime.required' => 'freeTime is required!!!!'
81+
])
8882
->validate([], false);
8983

90-
print_r($valid->getErrors());
84+
print_r($v->getErrors());
9185

examples/simple-loader.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
error_reporting(E_ALL);
4+
date_default_timezone_set("Asia/Shanghai");
5+
6+
spl_autoload_register(function($class)
7+
{
8+
$prefix = 'Inhere\\Validate\\';
9+
10+
// e.g. "Inhere\Validate\ValidationTrait"
11+
if (strpos($class, $prefix) !== false) {
12+
$file = dirname(__DIR__) . '/src/' . str_replace('\\', '/', substr($class, strlen($prefix))). '.php';
13+
} else {
14+
$file = __DIR__ . '/' . $class. '.php';
15+
}
16+
17+
if (is_file($file)) {
18+
include $file;
19+
}
20+
});

phpunit.xml.dist

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
bootstrap="./tests/boot.php"
6+
colors="false"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Php Validate-Filter Test Suite">
15+
<directory>./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
<filter>
20+
<whitelist>
21+
<directory suffix=".php">./examples</directory>
22+
</whitelist>
23+
</filter>
24+
</phpunit>

0 commit comments

Comments
 (0)