-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
67 lines (62 loc) · 2.01 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once __DIR__. '/vendor/autoload.php';
use Sanitizer\Sanitizers\Integer;
use Sanitizer\Sanitizers\Strings;
use Sanitizer\Sanitizers\Booleans;
use Sanitizer\Sanitizers\Emails;
use Sanitizer\Sanitizers\ArrayInteger;
use Sanitizer\Sanitizers\Floats;
use Sanitizer\Sanitizers\ArrayString;
use Sanitizer\Sanitizers\Date;
$_POST['a'] = 2;
$_POST['b'] = "asdssf11f";
$_POST['c'] = "'false'";
$_POST['d'] = "'true'";
$_POST['e'] = "0";
$_POST['f'] = "1";
$_POST['g'] = "2";
$_POST['h'] = true;
$_POST['i'] = null;
$_POST['l'] = false;
$_POST['m'] = 'false';
$_POST['aa'] = 'asfsadfsa@dfjsdf.com';
$_POST['ab'] = 'fsdkfso@diasfdsdf.com';
$_POST['ac'] = 'kfrokfeor@dirfdssd.com';
$_POST['ba'] = '1,11';
$_POST['bb'] = 2.22;
$_POST['bc'] = '3.33';
$_POST['ca'] = [1,2,3,4,5,6,7,8];
$_POST['cb'] = [3,4,'bbdfbfd',false, null,'false'];
$_POST['cc'] = '3.33';
$_POST['ee'] = ['aaaa','bbbb', 'ccc'];
$_POST['fa'] = "2018-10-22";
$_POST['fb'] = "22-10-2018";
$_POST['fc'] = "fdsfs";
$cls = new \Sanitizer\ArrayCaster($_POST, [
(new Integer("a"))
->setMinimum(2)
->setMaximum(10)
->setNullAsDefault(true),
(new Strings("b"))
->setMinLength(5)
->setMaxLength(10),
new Booleans("e"),
new Booleans("f"),
new Emails("aa"),
new Floats("bc"),
(new ArrayInteger("ca"))->setMaximum(4),
(new ArrayInteger("cb"))->setMaxItems(1),
(new ArrayInteger("cc")),
(new ArrayString("ee")),
(new Date("fa"))->setReadFormat("Y-m-d", true),
(new Date("fb"))->setReadFormat("d-m-Y", true)->setReturnAsObject(true),
(new Date("fc"))->setReadFormat("Y-m-d", true),
]);
echo PHP_EOL;
echo " ----------- input ---------";
echo PHP_EOL;
var_dump($_POST);
echo PHP_EOL;
echo " ----------- output ---------";
echo PHP_EOL;
var_dump($cls->getData());