@@ -72,8 +72,7 @@ discard block |
||
72 | 72 | /** |
73 | 73 | * 创建类的实例 |
74 | 74 | * @access public |
75 | - * @param string $class 类名或者标识 |
|
76 | - * @param array $args 变量 |
|
75 | + * @param array $vars 变量 |
|
77 | 76 | * @return object |
78 | 77 | */ |
79 | 78 | public function make($abstract, $vars = []) |
@@ -98,7 +97,7 @@ discard block |
||
98 | 97 | /** |
99 | 98 | * 执行函数或者闭包方法 支持参数调用 |
100 | 99 | * @access public |
101 | - * @param string|array|\Closure $function 函数或者闭包 |
|
100 | + * @param \Closure $function 函数或者闭包 |
|
102 | 101 | * @param array $vars 变量 |
103 | 102 | * @return mixed |
104 | 103 | */ |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | // 容器对象实例 |
13 | 13 | protected static $instance; |
14 | 14 | // 容器中的对象实例 |
15 | - protected $instances = []; |
|
15 | + protected $instances=[]; |
|
16 | 16 | // 容器中绑定的对象标识 |
17 | - protected $bind = []; |
|
17 | + protected $bind=[]; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * 获取当前容器的实例(单例) |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | public static function getInstance() |
25 | 25 | { |
26 | 26 | if (is_null(static::$instance)) { |
27 | - static::$instance = new static; |
|
27 | + static::$instance=new static; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | return static::$instance; |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * @param string|\Closure $concrete 要绑定的类或者闭包 |
38 | 38 | * @return void |
39 | 39 | */ |
40 | - public function bind($abstract, $concrete = null) |
|
40 | + public function bind($abstract, $concrete=null) |
|
41 | 41 | { |
42 | 42 | if (is_array($abstract)) { |
43 | - $this->bind = array_merge($this->bind, $abstract); |
|
43 | + $this->bind=array_merge($this->bind, $abstract); |
|
44 | 44 | } else { |
45 | - $this->bind[$abstract] = $concrete; |
|
45 | + $this->bind[$abstract]=$concrete; |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function instance($abstract, $instance) |
57 | 57 | { |
58 | - $this->instances[$abstract] = $instance; |
|
58 | + $this->instances[$abstract]=$instance; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -76,21 +76,21 @@ discard block |
||
76 | 76 | * @param array $args 变量 |
77 | 77 | * @return object |
78 | 78 | */ |
79 | - public function make($abstract, $vars = []) |
|
79 | + public function make($abstract, $vars=[]) |
|
80 | 80 | { |
81 | 81 | if (isset($this->instances[$abstract])) { |
82 | - $object = $this->instances[$abstract]; |
|
82 | + $object=$this->instances[$abstract]; |
|
83 | 83 | } elseif (isset($this->bind[$abstract])) { |
84 | - $concrete = $this->bind[$abstract]; |
|
84 | + $concrete=$this->bind[$abstract]; |
|
85 | 85 | if ($concrete instanceof \Closure) { |
86 | - $object = call_user_func_array($concrete, $vars); |
|
86 | + $object=call_user_func_array($concrete, $vars); |
|
87 | 87 | } else { |
88 | - $object = $this->make($concrete, $vars); |
|
88 | + $object=$this->make($concrete, $vars); |
|
89 | 89 | } |
90 | 90 | } else { |
91 | - $object = $this->invokeClass($abstract, $vars); |
|
91 | + $object=$this->invokeClass($abstract, $vars); |
|
92 | 92 | |
93 | - $this->instances[$abstract] = $object; |
|
93 | + $this->instances[$abstract]=$object; |
|
94 | 94 | } |
95 | 95 | return $object; |
96 | 96 | } |
@@ -102,10 +102,10 @@ discard block |
||
102 | 102 | * @param array $vars 变量 |
103 | 103 | * @return mixed |
104 | 104 | */ |
105 | - public function invokeFunction($function, $vars = []) |
|
105 | + public function invokeFunction($function, $vars=[]) |
|
106 | 106 | { |
107 | - $reflect = new \ReflectionFunction($function); |
|
108 | - $args = $this->bindParams($reflect, $vars); |
|
107 | + $reflect=new \ReflectionFunction($function); |
|
108 | + $args=$this->bindParams($reflect, $vars); |
|
109 | 109 | return $reflect->invokeArgs($args); |
110 | 110 | } |
111 | 111 | |
@@ -116,16 +116,16 @@ discard block |
||
116 | 116 | * @param array $vars 变量 |
117 | 117 | * @return mixed |
118 | 118 | */ |
119 | - public function invokeMethod($method, $vars = []) |
|
119 | + public function invokeMethod($method, $vars=[]) |
|
120 | 120 | { |
121 | 121 | if (is_array($method)) { |
122 | - $class = is_object($method[0]) ? $method[0] : $this->invokeClass($method[0]); |
|
123 | - $reflect = new \ReflectionMethod($class, $method[1]); |
|
122 | + $class=is_object($method[0]) ? $method[0] : $this->invokeClass($method[0]); |
|
123 | + $reflect=new \ReflectionMethod($class, $method[1]); |
|
124 | 124 | } else { |
125 | 125 | // 静态方法 |
126 | - $reflect = new \ReflectionMethod($method); |
|
126 | + $reflect=new \ReflectionMethod($method); |
|
127 | 127 | } |
128 | - $args = $this->bindParams($reflect, $vars); |
|
128 | + $args=$this->bindParams($reflect, $vars); |
|
129 | 129 | return $reflect->invokeArgs(isset($class) ? $class : null, $args); |
130 | 130 | } |
131 | 131 | |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | * @param array $vars 变量 |
137 | 137 | * @return mixed |
138 | 138 | */ |
139 | - public function invoke($callable, $vars = []) |
|
139 | + public function invoke($callable, $vars=[]) |
|
140 | 140 | { |
141 | 141 | if ($callable instanceof \Closure) { |
142 | - $result = $this->invokeFunction($callable, $vars); |
|
142 | + $result=$this->invokeFunction($callable, $vars); |
|
143 | 143 | } else { |
144 | - $result = $this->invokeMethod($callable, $vars); |
|
144 | + $result=$this->invokeMethod($callable, $vars); |
|
145 | 145 | } |
146 | 146 | return $result; |
147 | 147 | } |
@@ -153,14 +153,14 @@ discard block |
||
153 | 153 | * @param array $vars 变量 |
154 | 154 | * @return mixed |
155 | 155 | */ |
156 | - public function invokeClass($class, $vars = []) |
|
156 | + public function invokeClass($class, $vars=[]) |
|
157 | 157 | { |
158 | - $reflect = new \ReflectionClass($class); |
|
159 | - $constructor = $reflect->getConstructor(); |
|
158 | + $reflect=new \ReflectionClass($class); |
|
159 | + $constructor=$reflect->getConstructor(); |
|
160 | 160 | if ($constructor) { |
161 | - $args = $this->bindParams($constructor, $vars); |
|
161 | + $args=$this->bindParams($constructor, $vars); |
|
162 | 162 | } else { |
163 | - $args = []; |
|
163 | + $args=[]; |
|
164 | 164 | } |
165 | 165 | return $reflect->newInstanceArgs($args); |
166 | 166 | } |
@@ -172,28 +172,28 @@ discard block |
||
172 | 172 | * @param array $vars 变量 |
173 | 173 | * @return array |
174 | 174 | */ |
175 | - protected function bindParams($reflect, $vars = []) |
|
175 | + protected function bindParams($reflect, $vars=[]) |
|
176 | 176 | { |
177 | - $args = []; |
|
177 | + $args=[]; |
|
178 | 178 | if ($reflect->getNumberOfParameters() > 0) { |
179 | 179 | // 判断数组类型 数字数组时按顺序绑定参数 |
180 | 180 | reset($vars); |
181 | - $type = key($vars) === 0 ? 1 : 0; |
|
182 | - $params = $reflect->getParameters(); |
|
181 | + $type=key($vars) === 0 ? 1 : 0; |
|
182 | + $params=$reflect->getParameters(); |
|
183 | 183 | foreach ($params as $param) { |
184 | - $name = $param->getName(); |
|
185 | - $class = $param->getClass(); |
|
184 | + $name=$param->getName(); |
|
185 | + $class=$param->getClass(); |
|
186 | 186 | if ($class) { |
187 | - $className = $class->getName(); |
|
188 | - $args[] = $this->make($className); |
|
187 | + $className=$class->getName(); |
|
188 | + $args[]=$this->make($className); |
|
189 | 189 | } elseif (1 == $type && !empty($vars)) { |
190 | - $args[] = array_shift($vars); |
|
190 | + $args[]=array_shift($vars); |
|
191 | 191 | } elseif (0 == $type && isset($vars[$name])) { |
192 | - $args[] = $vars[$name]; |
|
192 | + $args[]=$vars[$name]; |
|
193 | 193 | } elseif ($param->isDefaultValueAvailable()) { |
194 | - $args[] = $param->getDefaultValue(); |
|
194 | + $args[]=$param->getDefaultValue(); |
|
195 | 195 | } else { |
196 | - throw new \InvalidArgumentException('method param miss:' . $name); |
|
196 | + throw new \InvalidArgumentException('method param miss:'.$name); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | class Facade |
10 | 10 | { |
11 | 11 | |
12 | - protected static $bind = []; |
|
12 | + protected static $bind=[]; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * 绑定类的静态代理 |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | * @param string $class 实际类名 |
20 | 20 | * @return object |
21 | 21 | */ |
22 | - public static function bind($name, $class = null) |
|
22 | + public static function bind($name, $class=null) |
|
23 | 23 | { |
24 | 24 | if (is_array($name)) { |
25 | - self::$bind = array_merge(self::$bind, $name); |
|
25 | + self::$bind=array_merge(self::$bind, $name); |
|
26 | 26 | } else { |
27 | - self::$bind[$name] = $class; |
|
27 | + self::$bind[$name]=$class; |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | * @param array $args 变量 |
37 | 37 | * @return object |
38 | 38 | */ |
39 | - protected static function createFacade($class = '', $args = []) |
|
39 | + protected static function createFacade($class='', $args=[]) |
|
40 | 40 | { |
41 | - $class = $class ?: static::class; |
|
42 | - $facadeClass = static::getFacadeClass(); |
|
41 | + $class=$class ?: static::class; |
|
42 | + $facadeClass=static::getFacadeClass(); |
|
43 | 43 | if ($facadeClass) { |
44 | - $class = $facadeClass; |
|
44 | + $class=$facadeClass; |
|
45 | 45 | } elseif (isset(self::$bind[$class])) { |
46 | - $class = self::$bind[$class]; |
|
46 | + $class=self::$bind[$class]; |
|
47 | 47 | } |
48 | 48 | return Container::getInstance()->make($class, $args); |
49 | 49 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param array $args 变量 |
68 | 68 | * @return object |
69 | 69 | */ |
70 | - public static function make($class, $args = []) |
|
70 | + public static function make($class, $args=[]) |
|
71 | 71 | { |
72 | 72 | return self::createFacade($class, $args); |
73 | 73 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | /** |
96 | 96 | * session管理函数 |
97 | - * @param string|array $name session名称 如果为数组则表示进行session设置 |
|
97 | + * @param string $name session名称 如果为数组则表示进行session设置 |
|
98 | 98 | * @param mixed $value session值 |
99 | 99 | * @return mixed |
100 | 100 | */ |
@@ -407,6 +407,11 @@ discard block |
||
407 | 407 | $value .= ' '; |
408 | 408 | } |
409 | 409 | } |
410 | +/** |
|
411 | + * @param string $name |
|
412 | + * |
|
413 | + * @return string|null |
|
414 | + */ |
|
410 | 415 | function config($name=null,$value=null,$default=null){ |
411 | 416 | $config=\puck\Conf::load(); |
412 | 417 | if ($name===null){ |
@@ -70,15 +70,10 @@ |
||
70 | 70 | |
71 | 71 | |
72 | 72 | /** |
73 | - |
|
74 | 73 | * 数据签名认证 |
75 | - |
|
76 | 74 | * @param array $data 被认证的数据 |
77 | - |
|
78 | 75 | * @return string 签名 |
79 | - |
|
80 | 76 | * @author 麦当苗儿 <[email protected]> |
81 | - |
|
82 | 77 | */ |
83 | 78 | function data_auth_sign($data) { |
84 | 79 | //数据类型检测 |
@@ -6,46 +6,46 @@ discard block |
||
6 | 6 | * @param boolean $adv 是否进行高级模式获取(有可能被伪装) |
7 | 7 | * @return mixed |
8 | 8 | */ |
9 | -function get_client_ip($type = 0, $adv = true) |
|
9 | +function get_client_ip($type=0, $adv=true) |
|
10 | 10 | { |
11 | - $type = $type ? 1 : 0; |
|
12 | - static $ip = null; |
|
11 | + $type=$type ? 1 : 0; |
|
12 | + static $ip=null; |
|
13 | 13 | if (null !== $ip) { |
14 | 14 | return $ip[$type]; |
15 | 15 | } |
16 | 16 | if ($adv) { |
17 | 17 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
18 | - $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
|
19 | - $pos = array_search('unknown', $arr); |
|
18 | + $arr=explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
|
19 | + $pos=array_search('unknown', $arr); |
|
20 | 20 | if (false !== $pos) { |
21 | 21 | unset($arr[$pos]); |
22 | 22 | } |
23 | - $ip = trim($arr[0]); |
|
23 | + $ip=trim($arr[0]); |
|
24 | 24 | } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { |
25 | - $ip = $_SERVER['HTTP_CLIENT_IP']; |
|
25 | + $ip=$_SERVER['HTTP_CLIENT_IP']; |
|
26 | 26 | } elseif (isset($_SERVER['REMOTE_ADDR'])) { |
27 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
27 | + $ip=$_SERVER['REMOTE_ADDR']; |
|
28 | 28 | } |
29 | 29 | } elseif (isset($_SERVER['REMOTE_ADDR'])) { |
30 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
30 | + $ip=$_SERVER['REMOTE_ADDR']; |
|
31 | 31 | } |
32 | 32 | // IP地址合法验证 |
33 | - $long = sprintf("%u", ip2long($ip)); |
|
34 | - $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); |
|
33 | + $long=sprintf("%u", ip2long($ip)); |
|
34 | + $ip=$long ? array($ip, $long) : array('0.0.0.0', 0); |
|
35 | 35 | return $ip[$type]; |
36 | 36 | } |
37 | 37 | //2为直接输出数组 |
38 | -function show_json($arr,$type=2) |
|
38 | +function show_json($arr, $type=2) |
|
39 | 39 | { |
40 | - if(isset($arr['status']) && $type==2){ |
|
40 | + if (isset($arr['status']) && $type == 2) { |
|
41 | 41 | $ret=$arr; |
42 | 42 | } |
43 | - else{ |
|
44 | - $ret['status'] = $type; |
|
45 | - $ret['data'] = $arr; |
|
43 | + else { |
|
44 | + $ret['status']=$type; |
|
45 | + $ret['data']=$arr; |
|
46 | 46 | } |
47 | 47 | |
48 | - $obj = json_encode($ret); |
|
48 | + $obj=json_encode($ret); |
|
49 | 49 | header('Content-Type: application/json'); |
50 | 50 | echo $obj; |
51 | 51 | exit(); |
@@ -53,16 +53,16 @@ discard block |
||
53 | 53 | |
54 | 54 | function success($arr) |
55 | 55 | { |
56 | - show_json($arr,1); |
|
56 | + show_json($arr, 1); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function error($arr) |
60 | 60 | { |
61 | 61 | /* $db=\MysqliDb::getInstance(); |
62 | 62 | $db->_transaction_status_check();*/ |
63 | - show_json($arr,0); |
|
63 | + show_json($arr, 0); |
|
64 | 64 | } |
65 | -function not_found($str='page not found,that is all we know!'){ |
|
65 | +function not_found($str='page not found,that is all we know!') { |
|
66 | 66 | header('HTTP/1.1 404 Not Found'); |
67 | 67 | header("status: 404 Not Found"); |
68 | 68 | exit($str); |
@@ -83,13 +83,13 @@ discard block |
||
83 | 83 | function data_auth_sign($data) { |
84 | 84 | //数据类型检测 |
85 | 85 | |
86 | - if(!is_array($data)){ |
|
86 | + if (!is_array($data)) { |
|
87 | 87 | |
88 | - $data = (array)$data; |
|
88 | + $data=(array) $data; |
|
89 | 89 | } |
90 | 90 | ksort($data); //排序 |
91 | - $code = http_build_query($data); //url编码并生成query字符串 |
|
92 | - $sign = sha1($code); //生成签名 |
|
91 | + $code=http_build_query($data); //url编码并生成query字符串 |
|
92 | + $sign=sha1($code); //生成签名 |
|
93 | 93 | return $sign; |
94 | 94 | } |
95 | 95 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param mixed $value session值 |
99 | 99 | * @return mixed |
100 | 100 | */ |
101 | -function session($name = '', $value = '') { |
|
101 | +function session($name='', $value='') { |
|
102 | 102 | if (is_array($name)) { |
103 | 103 | |
104 | 104 | if (isset($name['id'])) { |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | session_start(); |
151 | 151 | } elseif ('[destroy]' == $name) { |
152 | 152 | // 销毁session |
153 | - $_SESSION = array(); |
|
153 | + $_SESSION=array(); |
|
154 | 154 | session_unset(); |
155 | 155 | session_destroy(); |
156 | 156 | } elseif ('[regenerate]' == $name) { |
157 | 157 | // 重新生成id |
158 | 158 | session_regenerate_id(); |
159 | 159 | } |
160 | - }else { |
|
160 | + } else { |
|
161 | 161 | if (strpos($name, '.')) { |
162 | - list($name1, $name2) = explode('.', $name); |
|
162 | + list($name1, $name2)=explode('.', $name); |
|
163 | 163 | return isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; |
164 | 164 | } else { |
165 | 165 | return isset($_SESSION[$name]) ? $_SESSION[$name] : null; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | } elseif (is_null($value)) { |
169 | 169 | // 删除session |
170 | 170 | if (strpos($name, '.')) { |
171 | - list($name1, $name2) = explode('.', $name); |
|
171 | + list($name1, $name2)=explode('.', $name); |
|
172 | 172 | unset($_SESSION[$name1][$name2]); |
173 | 173 | } else { |
174 | 174 | unset($_SESSION[$name]); |
@@ -176,30 +176,30 @@ discard block |
||
176 | 176 | } else { |
177 | 177 | // 设置session |
178 | 178 | if (strpos($name, '.')) { |
179 | - list($name1, $name2) = explode('.', $name); |
|
180 | - $_SESSION[$name1][$name2] = $value; |
|
179 | + list($name1, $name2)=explode('.', $name); |
|
180 | + $_SESSION[$name1][$name2]=$value; |
|
181 | 181 | } else { |
182 | - $_SESSION[$name] = $value; |
|
182 | + $_SESSION[$name]=$value; |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | return null; |
186 | 186 | } |
187 | 187 | |
188 | 188 | |
189 | -function admin_is_login(){ |
|
190 | - $user = session('admin_user_auth'); |
|
189 | +function admin_is_login() { |
|
190 | + $user=session('admin_user_auth'); |
|
191 | 191 | if (empty($user)) { |
192 | 192 | return 0; |
193 | 193 | } else { |
194 | 194 | $auth_sign=session('admin_user_auth_sign'); |
195 | - if(data_auth_sign($user)!=$auth_sign){ |
|
195 | + if (data_auth_sign($user) != $auth_sign) { |
|
196 | 196 | return 0; |
197 | 197 | } |
198 | 198 | return $user['uid']; |
199 | 199 | } |
200 | 200 | } |
201 | -function json($str){ |
|
202 | - $obj = json_encode($str,JSON_UNESCAPED_UNICODE); |
|
201 | +function json($str) { |
|
202 | + $obj=json_encode($str, JSON_UNESCAPED_UNICODE); |
|
203 | 203 | header('Content-Type: application/json'); |
204 | 204 | echo $obj; |
205 | 205 | } |
@@ -211,20 +211,20 @@ discard block |
||
211 | 211 | * @param integer $flags htmlspecialchars flags |
212 | 212 | * @return void|string |
213 | 213 | */ |
214 | -function dump($var, $echo = true, $label = null, $flags = ENT_SUBSTITUTE) |
|
214 | +function dump($var, $echo=true, $label=null, $flags=ENT_SUBSTITUTE) |
|
215 | 215 | { |
216 | - $label = (null === $label) ? '' : rtrim($label) . ':'; |
|
216 | + $label=(null === $label) ? '' : rtrim($label).':'; |
|
217 | 217 | ob_start(); |
218 | 218 | var_dump($var); |
219 | - $output = ob_get_clean(); |
|
220 | - $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); |
|
219 | + $output=ob_get_clean(); |
|
220 | + $output=preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); |
|
221 | 221 | if (IS_CLI) { |
222 | - $output = PHP_EOL . $label . $output . PHP_EOL; |
|
222 | + $output=PHP_EOL.$label.$output.PHP_EOL; |
|
223 | 223 | } else { |
224 | 224 | if (!extension_loaded('xdebug')) { |
225 | - $output = htmlspecialchars($output, $flags); |
|
225 | + $output=htmlspecialchars($output, $flags); |
|
226 | 226 | } |
227 | - $output = '<pre>' . $label . $output . '</pre>'; |
|
227 | + $output='<pre>'.$label.$output.'</pre>'; |
|
228 | 228 | } |
229 | 229 | if ($echo) { |
230 | 230 | echo($output); |
@@ -249,95 +249,95 @@ discard block |
||
249 | 249 | * @param mixed $datas 要获取的额外数据源 |
250 | 250 | * @return mixed |
251 | 251 | */ |
252 | -function I($name, $default = '', $filter = null, $datas = null) |
|
252 | +function I($name, $default='', $filter=null, $datas=null) |
|
253 | 253 | { |
254 | - static $_PUT = null; |
|
254 | + static $_PUT=null; |
|
255 | 255 | if (strpos($name, '/')) { |
256 | 256 | // 指定修饰符 |
257 | - list($name, $type) = explode('/', $name, 2); |
|
258 | - } else{ |
|
257 | + list($name, $type)=explode('/', $name, 2); |
|
258 | + } else { |
|
259 | 259 | // 默认强制转换为字符串 |
260 | - $type = 's'; |
|
260 | + $type='s'; |
|
261 | 261 | } |
262 | 262 | if (strpos($name, '.')) { |
263 | 263 | // 指定参数来源 |
264 | - list($method, $name) = explode('.', $name, 2); |
|
264 | + list($method, $name)=explode('.', $name, 2); |
|
265 | 265 | } else { |
266 | 266 | // 默认为自动判断 |
267 | - $method = 'param'; |
|
267 | + $method='param'; |
|
268 | 268 | } |
269 | 269 | switch (strtolower($method)) { |
270 | 270 | case 'get': |
271 | - $input = &$_GET; |
|
271 | + $input=&$_GET; |
|
272 | 272 | break; |
273 | 273 | case 'post': |
274 | - $input = &$_POST; |
|
274 | + $input=&$_POST; |
|
275 | 275 | break; |
276 | 276 | case 'put': |
277 | 277 | if (is_null($_PUT)) { |
278 | 278 | parse_str(file_get_contents('php://input'), $_PUT); |
279 | 279 | } |
280 | - $input = $_PUT; |
|
280 | + $input=$_PUT; |
|
281 | 281 | break; |
282 | 282 | case 'param': |
283 | 283 | switch ($_SERVER['REQUEST_METHOD']) { |
284 | 284 | case 'POST': |
285 | - $input = $_POST; |
|
285 | + $input=$_POST; |
|
286 | 286 | break; |
287 | 287 | case 'PUT': |
288 | 288 | if (is_null($_PUT)) { |
289 | 289 | parse_str(file_get_contents('php://input'), $_PUT); |
290 | 290 | } |
291 | - $input = $_PUT; |
|
291 | + $input=$_PUT; |
|
292 | 292 | break; |
293 | 293 | default: |
294 | - $input = $_GET; |
|
294 | + $input=$_GET; |
|
295 | 295 | } |
296 | 296 | break; |
297 | 297 | case 'path': |
298 | - $input = array(); |
|
298 | + $input=array(); |
|
299 | 299 | if (!empty($_SERVER['PATH_INFO'])) { |
300 | - $depr = C('URL_PATHINFO_DEPR'); |
|
301 | - $input = explode($depr, trim($_SERVER['PATH_INFO'], $depr)); |
|
300 | + $depr=C('URL_PATHINFO_DEPR'); |
|
301 | + $input=explode($depr, trim($_SERVER['PATH_INFO'], $depr)); |
|
302 | 302 | } |
303 | 303 | break; |
304 | 304 | case 'request': |
305 | - $input = &$_REQUEST; |
|
305 | + $input=&$_REQUEST; |
|
306 | 306 | break; |
307 | 307 | case 'session': |
308 | - $input = &$_SESSION; |
|
308 | + $input=&$_SESSION; |
|
309 | 309 | break; |
310 | 310 | case 'cookie': |
311 | - $input = &$_COOKIE; |
|
311 | + $input=&$_COOKIE; |
|
312 | 312 | break; |
313 | 313 | case 'server': |
314 | - $input = &$_SERVER; |
|
314 | + $input=&$_SERVER; |
|
315 | 315 | break; |
316 | 316 | case 'globals': |
317 | - $input = &$GLOBALS; |
|
317 | + $input=&$GLOBALS; |
|
318 | 318 | break; |
319 | 319 | case 'data': |
320 | - $input = &$datas; |
|
320 | + $input=&$datas; |
|
321 | 321 | break; |
322 | 322 | default: |
323 | 323 | return null; |
324 | 324 | } |
325 | 325 | if ('' == $name) { |
326 | 326 | // 获取全部变量 |
327 | - $data = $input; |
|
328 | - $filters = isset($filter) ? $filter : 'htmlspecialchars'; |
|
327 | + $data=$input; |
|
328 | + $filters=isset($filter) ? $filter : 'htmlspecialchars'; |
|
329 | 329 | if ($filters) { |
330 | 330 | if (is_string($filters)) { |
331 | - $filters = explode(',', $filters); |
|
331 | + $filters=explode(',', $filters); |
|
332 | 332 | } |
333 | 333 | foreach ($filters as $filter) { |
334 | - $data = array_map_recursive($filter, $data); // 参数过滤 |
|
334 | + $data=array_map_recursive($filter, $data); // 参数过滤 |
|
335 | 335 | } |
336 | 336 | } |
337 | 337 | } elseif (isset($input[$name])) { |
338 | 338 | // 取值操作 |
339 | - $data = $input[$name]; |
|
340 | - $filters = isset($filter) ? $filter : 'htmlspecialchars'; |
|
339 | + $data=$input[$name]; |
|
340 | + $filters=isset($filter) ? $filter : 'htmlspecialchars'; |
|
341 | 341 | if ($filters) { |
342 | 342 | if (is_string($filters)) { |
343 | 343 | if (0 === strpos($filters, '/')) { |
@@ -346,19 +346,19 @@ discard block |
||
346 | 346 | return isset($default) ? $default : null; |
347 | 347 | } |
348 | 348 | } else { |
349 | - $filters = explode(',', $filters); |
|
349 | + $filters=explode(',', $filters); |
|
350 | 350 | } |
351 | 351 | } elseif (is_int($filters)) { |
352 | - $filters = array($filters); |
|
352 | + $filters=array($filters); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | if (is_array($filters)) { |
356 | 356 | foreach ($filters as $filter) { |
357 | - $filter = trim($filter); |
|
357 | + $filter=trim($filter); |
|
358 | 358 | if (function_exists($filter)) { |
359 | - $data = is_array($data) ? array_map_recursive($filter, $data) : $filter($data); // 参数过滤 |
|
359 | + $data=is_array($data) ? array_map_recursive($filter, $data) : $filter($data); // 参数过滤 |
|
360 | 360 | } else { |
361 | - $data = filter_var($data, is_int($filter) ? $filter : filter_id($filter)); |
|
361 | + $data=filter_var($data, is_int($filter) ? $filter : filter_id($filter)); |
|
362 | 362 | if (false === $data) { |
363 | 363 | return isset($default) ? $default : null; |
364 | 364 | } |
@@ -369,34 +369,34 @@ discard block |
||
369 | 369 | if (!empty($type)) { |
370 | 370 | switch (strtolower($type)) { |
371 | 371 | case 'a': // 数组 |
372 | - $data = (array) $data; |
|
372 | + $data=(array) $data; |
|
373 | 373 | break; |
374 | 374 | case 'd': // 数字 |
375 | - $data = (int) $data; |
|
375 | + $data=(int) $data; |
|
376 | 376 | break; |
377 | 377 | case 'f': // 浮点 |
378 | - $data = (float) $data; |
|
378 | + $data=(float) $data; |
|
379 | 379 | break; |
380 | 380 | case 'b': // 布尔 |
381 | - $data = (boolean) $data; |
|
381 | + $data=(boolean) $data; |
|
382 | 382 | break; |
383 | 383 | case 's':// 字符串 |
384 | 384 | default: |
385 | - $data = (string) $data; |
|
385 | + $data=(string) $data; |
|
386 | 386 | } |
387 | 387 | } |
388 | 388 | } else { |
389 | 389 | // 变量默认值 |
390 | - $data = isset($default) ? $default : null; |
|
390 | + $data=isset($default) ? $default : null; |
|
391 | 391 | } |
392 | 392 | is_array($data) && array_walk_recursive($data, 'think_filter'); |
393 | 393 | return $data; |
394 | 394 | } |
395 | 395 | function array_map_recursive($filter, $data) |
396 | 396 | { |
397 | - $result = array(); |
|
397 | + $result=array(); |
|
398 | 398 | foreach ($data as $key => $val) { |
399 | - $result[$key] = is_array($val) |
|
399 | + $result[$key]=is_array($val) |
|
400 | 400 | ? array_map_recursive($filter, $val) |
401 | 401 | : call_user_func($filter, $val); |
402 | 402 | } |
@@ -408,18 +408,18 @@ discard block |
||
408 | 408 | |
409 | 409 | // 过滤查询特殊字符 |
410 | 410 | if (preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i', $value)) { |
411 | - $value .= ' '; |
|
411 | + $value.=' '; |
|
412 | 412 | } |
413 | 413 | } |
414 | -function config($name=null,$value=null,$default=null){ |
|
414 | +function config($name=null, $value=null, $default=null) { |
|
415 | 415 | $config=\puck\Conf::load(); |
416 | - if ($name===null){ |
|
416 | + if ($name === null) { |
|
417 | 417 | return $config->all(); |
418 | 418 | } |
419 | - if ($value===null){ |
|
420 | - return $config->get($name,$default); |
|
419 | + if ($value === null) { |
|
420 | + return $config->get($name, $default); |
|
421 | 421 | } |
422 | - $config->set($name,$value); |
|
422 | + $config->set($name, $value); |
|
423 | 423 | } |
424 | 424 | /** |
425 | 425 | * 字符串命名风格转换 |
@@ -428,9 +428,9 @@ discard block |
||
428 | 428 | * @param integer $type 转换类型 |
429 | 429 | * @return string |
430 | 430 | */ |
431 | -function parse_name($name, $type = 0) { |
|
431 | +function parse_name($name, $type=0) { |
|
432 | 432 | if ($type) { |
433 | - return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) {return strtoupper($match[1]);}, $name)); |
|
433 | + return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function($match) {return strtoupper($match[1]); }, $name)); |
|
434 | 434 | } else { |
435 | 435 | return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); |
436 | 436 | } |
@@ -39,8 +39,7 @@ discard block |
||
39 | 39 | { |
40 | 40 | if(isset($arr['status']) && $type==2){ |
41 | 41 | $ret=$arr; |
42 | - } |
|
43 | - else{ |
|
42 | + } else{ |
|
44 | 43 | $ret['status'] = $type; |
45 | 44 | $ret['data'] = $arr; |
46 | 45 | } |
@@ -157,7 +156,7 @@ discard block |
||
157 | 156 | // 重新生成id |
158 | 157 | session_regenerate_id(); |
159 | 158 | } |
160 | - }else { |
|
159 | + } else { |
|
161 | 160 | if (strpos($name, '.')) { |
162 | 161 | list($name1, $name2) = explode('.', $name); |
163 | 162 | return isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; |
@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | 2 | @ini_set('date.timezone', 'Asia/Shanghai'); |
3 | 3 | @header('content-type:text/html;charset=utf-8'); |
4 | -define('EXPORT_PATH',__DIR__); |
|
5 | -define('PUCK_VER','1.1.0'); |
|
6 | -define('IS_CLI',php_sapi_name()=='cli'); |
|
7 | -if(DEBUG){ |
|
4 | +define('EXPORT_PATH', __DIR__); |
|
5 | +define('PUCK_VER', '1.1.0'); |
|
6 | +define('IS_CLI', php_sapi_name() == 'cli'); |
|
7 | +if (DEBUG) { |
|
8 | 8 | error_reporting(E_ALL); |
9 | 9 | @ini_set('display_errors', 'On'); |
10 | 10 | //@ob_start(); |
11 | - $whoops = new \Whoops\Run; |
|
12 | - $handle=IS_CLI?"PlainTextHandler":"PrettyPageHandler"; |
|
11 | + $whoops=new \Whoops\Run; |
|
12 | + $handle=IS_CLI ? "PlainTextHandler" : "PrettyPageHandler"; |
|
13 | 13 | $handle="\\Whoops\\Handler\\".$handle; |
14 | 14 | $whoops->pushHandler(new $handle); |
15 | 15 | $whoops->register(); |