Skip to content

Commit ba3d3a8

Browse files
'首次提交'
1 parent a800f54 commit ba3d3a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+22380
-0
lines changed

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "v_yanlguo/think-wq",
3+
"description": "app",
4+
"type": "p",
5+
"require": {
6+
"php": "^7.0"
7+
},
8+
"license": "apache-2.0",
9+
"authors": [
10+
{
11+
"name": "yanlong guo",
12+
"email": "guoqiaotian@126.com"
13+
}
14+
],
15+
"minimum-stability": "dev",
16+
"autoload": {
17+
"psr-4": {
18+
"think\\": "src/think",
19+
"thinkWQ\\": "src"
20+
}
21+
}
22+
}

src/Input.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
namespace thinkWQ;
3+
/**
4+
* thinkyaf
5+
* 基于yaf和thinkPHP5的组件抽取,封装而成的PHP框架
6+
* @author storm <admin@yumufeng.com>
7+
*/
8+
9+
/**
10+
* Input 输入过滤
11+
* 支持PUT GET POST 和 COOKIE , ENV ,SYSTEM , PUT
12+
*
13+
* @author NewFuture
14+
*
15+
* @todo 性能和便捷性
16+
*/
17+
class Input
18+
{
19+
/**
20+
* 输入过滤
21+
*
22+
* @param string $param [输入参数]
23+
* @param mixed &$export [description]
24+
* @param mixed $filter [过滤条件]
25+
* @param type $default [description]
26+
*
27+
* @example if(I('post.phone',$phone,'phone')){}//phone()方法验证
28+
* @example if(I('get.id',$uid,'int',1)){}//数字,int函数验证,默认1
29+
* @example if(I('put.text',$uid,'/^\w{5,50}$/'){}//正则验证
30+
* @example if(I('cookie.token',$uid,'token'){}//使用配置中的regex.token的值进行验证
31+
*/
32+
public static function I($param, &$export, $filter = null, $default = null)
33+
{
34+
if (strpos($param, '.')) {
35+
list($method, $name) = explode('.', $param, 2);
36+
/*PUT请求已在REST中注入到$GLOBAL中*/
37+
$method = '_' . strtoupper($method);
38+
$input = &$GLOBALS[$method];
39+
} else {
40+
// 默认为自动判断
41+
$input = &$_REQUEST;
42+
$name = $param;
43+
}
44+
$r = self::filter($input, $name, $export, $filter) or ($export = $default);
45+
return $r;
46+
}
47+
48+
/*put,get,post等输入过滤*/
49+
public static function put($name, &$export, $filter = null, $default = null)
50+
{
51+
($r = self::filter($GLOBALS['_PUT'], $name, $export, $filter)) or ($export = $default);
52+
return $r;
53+
}
54+
55+
public static function get($name, &$export, $filter = null, $default = null)
56+
{
57+
($r = self::filter($_GET, $name, $export, $filter)) or ($export = $default);
58+
return $r;
59+
}
60+
61+
public static function post($name, &$export, $filter = null, $default = null)
62+
{
63+
($r = self::filter($_POST, $name, $export, $filter)) or ($export = $default);
64+
return $r;
65+
}
66+
67+
/**
68+
* 过滤器
69+
*
70+
* @param string &$input [输入参数]
71+
* @param mixed &$index [description]
72+
* @param mixed &$export [description]
73+
* @param mixed $filter [过滤条件]
74+
*
75+
* @return bool 验证是否有效
76+
*/
77+
private static function filter(&$input, &$index, &$export, $filter)
78+
{
79+
if (isset($input[$index])) {
80+
$export = $input[$index];
81+
82+
switch (gettype($filter)) {
83+
case 'NULL':
84+
case null: //无需过滤
85+
return true;
86+
case 'int'://整型常量
87+
case 'integer':
88+
/*系统过滤函数*/
89+
$export = filter_var($export, $filter);
90+
return $export;
91+
case 'object':
92+
/*匿名回调函数*/
93+
$r = $filter($export);
94+
return $r ? ($export = $r) : false;
95+
96+
case 'string': //字符串
97+
if (strlen($filter) < 1) {
98+
return $export;
99+
} elseif ($filter[0] == '/') {
100+
/*正则表达式验证*/
101+
return preg_match($filter, $export);
102+
} elseif (function_exists($filter)) {
103+
/*已经定义的函数*/
104+
$r = $filter($export);
105+
//返回值不是true型的进行赋值(过滤),否则进行验证
106+
return $r ? (is_bool($r) or $export = $r) : $export = $r;
107+
} elseif ($filterid = filter_id($filter)) {
108+
/*系统过滤函数*/
109+
return $export = filter_var($export, $filterid);
110+
}
111+
//继续往下走
112+
// no break
113+
default:
114+
if (Config::get('debug')) {
115+
throw new Exception('未知过滤方法' . $filter);
116+
}
117+
return false;
118+
}
119+
} else {
120+
/*不存在*/
121+
return null;
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)