-
Notifications
You must be signed in to change notification settings - Fork 2
/
datas.php
49 lines (43 loc) · 1.08 KB
/
datas.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
<?php
/**
* Datas class extending native Prefab
*
* @package 1.0
*/
class Datas extends Prefab{
/**
Check validity on @datas using @rules rulez
@return mix (array|false)
@param $datas array
@param $rules array
**/
function check($datas,$rules){
foreach($rules as $item=>$rule){
$rulz=explode(',',$rule);
$check[$item]=array_map(function ($rul) use ($datas,$item){
if(!isset($datas[$item])){
return;
}
if($rul=='required'){
if(!$datas[$item])
return 'false';
}
if (preg_match("/(\w+)->(\w+)/i",$rul,$matches)){
$valid=new $matches[1];
if(!$valid->$matches[2]($datas[$item]))
return 'false';
}
if(preg_match("/^=(\w+)/",$rul,$matches)){
if($datas[$item]!=$datas[$matches[1]])
return 'false';
}
},$rulz);
}
$checked=array_filter(array_map(function($item){return implode(', ',array_filter($item,'strlen'));},$check));
if(count($checked)<1){
return false;
}
return $checked;
}
}
?>