@@ -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 | //数据类型检测 |
@@ -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; |
@@ -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){ |
@@ -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 | } |
@@ -28,6 +28,10 @@ |
||
28 | 28 | $function = new \Twig_SimpleFunction('I','I'); |
29 | 29 | $this->twig->addFunction($function); |
30 | 30 | } |
31 | + |
|
32 | + /** |
|
33 | + * @param string $name |
|
34 | + */ |
|
31 | 35 | protected function assign($name, $value = '') |
32 | 36 | { |
33 | 37 | if (is_array($name)) { |
@@ -4,44 +4,44 @@ discard block |
||
4 | 4 | class Controller |
5 | 5 | { |
6 | 6 | |
7 | - protected $viewPath = ''; |
|
7 | + protected $viewPath=''; |
|
8 | 8 | private $twig; |
9 | - private $tVar = array(); |
|
9 | + private $tVar=array(); |
|
10 | 10 | protected $title=''; |
11 | 11 | public function __construct() |
12 | 12 | { |
13 | - $loader = new \Twig_Loader_Filesystem(BASE_PATH . $this->viewPath); |
|
14 | - $twig = new \Twig_Environment($loader, array( |
|
13 | + $loader=new \Twig_Loader_Filesystem(BASE_PATH.$this->viewPath); |
|
14 | + $twig=new \Twig_Environment($loader, array( |
|
15 | 15 | 'debug' => DEBUG, |
16 | - 'cache' => BASE_PATH . '/cache', |
|
16 | + 'cache' => BASE_PATH.'/cache', |
|
17 | 17 | )); |
18 | - $this->twig = $twig; |
|
18 | + $this->twig=$twig; |
|
19 | 19 | $this->initTwigFilter(); |
20 | 20 | $this->initTwigFunction(); |
21 | - $this->db = \MysqliDb::getInstance(); |
|
21 | + $this->db=\MysqliDb::getInstance(); |
|
22 | 22 | } |
23 | - private function initTwigFilter(){ |
|
24 | - $filter = new \Twig_SimpleFilter('long2ip', 'long2ip'); |
|
23 | + private function initTwigFilter() { |
|
24 | + $filter=new \Twig_SimpleFilter('long2ip', 'long2ip'); |
|
25 | 25 | $this->twig->addFilter($filter); |
26 | 26 | } |
27 | - private function initTwigFunction(){ |
|
28 | - $function = new \Twig_SimpleFunction('I','I'); |
|
27 | + private function initTwigFunction() { |
|
28 | + $function=new \Twig_SimpleFunction('I', 'I'); |
|
29 | 29 | $this->twig->addFunction($function); |
30 | 30 | } |
31 | - protected function assign($name, $value = '') |
|
31 | + protected function assign($name, $value='') |
|
32 | 32 | { |
33 | 33 | if (is_array($name)) { |
34 | - $this->tVar = array_merge($this->tVar, $name); |
|
34 | + $this->tVar=array_merge($this->tVar, $name); |
|
35 | 35 | } else { |
36 | - $this->tVar[$name] = $value; |
|
36 | + $this->tVar[$name]=$value; |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - protected function show($tmpPath = '') |
|
40 | + protected function show($tmpPath='') |
|
41 | 41 | { |
42 | 42 | if ($tmpPath == '') { |
43 | 43 | if (defined("CONTROLLER_NAME") && defined("ACTION_NAME")) { |
44 | - $tmpPath = CONTROLLER_NAME . '/' . ACTION_NAME; |
|
44 | + $tmpPath=CONTROLLER_NAME.'/'.ACTION_NAME; |
|
45 | 45 | } else { |
46 | 46 | show_json($this->tVar); |
47 | 47 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | header('Content-Type:text/html; charset=utf-8'); |
50 | 50 | header('Cache-control: private'); // 页面缓存控制 |
51 | 51 | header('X-Powered-By:ViviAnAuthSystem'); |
52 | - $this->assign('title',$this->title); |
|
53 | - echo $this->twig->render($tmpPath . '.' . TempExt, $this->tVar); |
|
52 | + $this->assign('title', $this->title); |
|
53 | + echo $this->twig->render($tmpPath.'.'.TempExt, $this->tVar); |
|
54 | 54 | die(); |
55 | 55 | } |
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -62,6 +62,10 @@ |
||
62 | 62 | self::param(); |
63 | 63 | self::exec($class,ACTION_NAME); |
64 | 64 | } |
65 | + |
|
66 | + /** |
|
67 | + * @param string $function |
|
68 | + */ |
|
65 | 69 | static public function exec($class,$function){ |
66 | 70 | $method = new \ReflectionMethod($class, $function); |
67 | 71 | if ($method->isPublic() && !$method->isStatic()) { |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | self::init(); |
21 | 21 | if($path==''){ |
22 | 22 | $path=array(); |
23 | - }else{ |
|
23 | + } else{ |
|
24 | 24 | $path=str_replace('-','_',$path); |
25 | 25 | $path = explode('/',$path); |
26 | 26 | } |
@@ -28,8 +28,7 @@ discard block |
||
28 | 28 | if(count($path)==0){ |
29 | 29 | array_push($path,'home'); |
30 | 30 | array_push($path,'index'); |
31 | - } |
|
32 | - elseif (count($path)==1){ |
|
31 | + } elseif (count($path)==1){ |
|
33 | 32 | array_push($path,'index'); |
34 | 33 | } |
35 | 34 | if(!empty($path)){ |
@@ -6,50 +6,50 @@ discard block |
||
6 | 6 | |
7 | 7 | class Dispatch |
8 | 8 | { |
9 | - static public function init(){ |
|
10 | - if(!IS_CLI){ |
|
9 | + static public function init() { |
|
10 | + if (!IS_CLI) { |
|
11 | 11 | define('NOW_TIME', $_SERVER['REQUEST_TIME']); |
12 | 12 | define('REQUEST_METHOD', $_SERVER['REQUEST_METHOD']); |
13 | 13 | define('IS_GET', REQUEST_METHOD == 'GET' ? true : false); |
14 | 14 | define('IS_POST', REQUEST_METHOD == 'POST' ? true : false); |
15 | 15 | define('IS_PUT', REQUEST_METHOD == 'PUT' ? true : false); |
16 | 16 | define('IS_DELETE', REQUEST_METHOD == 'DELETE' ? true : false); |
17 | - define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ) ? true : false); |
|
17 | + define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')) ? true : false); |
|
18 | 18 | define('__SELF__', strip_tags($_SERVER['REQUEST_URI'])); |
19 | 19 | } |
20 | 20 | } |
21 | - static public function dispatch($path='',$app='\\admin') { |
|
21 | + static public function dispatch($path='', $app='\\admin') { |
|
22 | 22 | self::init(); |
23 | - if($path==''){ |
|
23 | + if ($path == '') { |
|
24 | 24 | $path=array(); |
25 | - }else{ |
|
26 | - $path=str_replace('-','_',$path); |
|
27 | - $path = explode('/',$path); |
|
25 | + } else { |
|
26 | + $path=str_replace('-', '_', $path); |
|
27 | + $path=explode('/', $path); |
|
28 | 28 | } |
29 | 29 | |
30 | - if(count($path)==0){ |
|
31 | - array_push($path,'home'); |
|
32 | - array_push($path,'index'); |
|
30 | + if (count($path) == 0) { |
|
31 | + array_push($path, 'home'); |
|
32 | + array_push($path, 'index'); |
|
33 | 33 | } |
34 | - elseif (count($path)==1){ |
|
35 | - array_push($path,'index'); |
|
34 | + elseif (count($path) == 1) { |
|
35 | + array_push($path, 'index'); |
|
36 | 36 | } |
37 | - if(!empty($path)){ |
|
37 | + if (!empty($path)) { |
|
38 | 38 | $tmpAction=array_pop($path); |
39 | 39 | $tmpAction=preg_replace('/\.(html|aspx|do|php|htm|h5|api)$/i', '', $tmpAction); |
40 | - $tmpAction=parse_name($tmpAction,1); |
|
40 | + $tmpAction=parse_name($tmpAction, 1); |
|
41 | 41 | $var['a']=$tmpAction; |
42 | 42 | } |
43 | - define('ACTION_NAME',$var['a']); |
|
43 | + define('ACTION_NAME', $var['a']); |
|
44 | 44 | if (!preg_match('/^[A-Za-z](\w)*$/', ACTION_NAME)) { |
45 | 45 | die("error action"); |
46 | 46 | } |
47 | - if(!empty($path)){ |
|
47 | + if (!empty($path)) { |
|
48 | 48 | $tmpController=array_pop($path); |
49 | - $tmpController=parse_name($tmpController,1); |
|
49 | + $tmpController=parse_name($tmpController, 1); |
|
50 | 50 | $var['c']=$tmpController; |
51 | 51 | } |
52 | - define('CONTROLLER_NAME',$var['c']); |
|
52 | + define('CONTROLLER_NAME', $var['c']); |
|
53 | 53 | if (!preg_match('/^[A-Za-z](\/|\w)*$/', CONTROLLER_NAME)) { |
54 | 54 | die("error controller"); |
55 | 55 | } |
@@ -57,20 +57,20 @@ discard block |
||
57 | 57 | if (!class_exists($class)) { |
58 | 58 | not_found('this controller is can not work now!'); |
59 | 59 | } |
60 | - $class= new $class(); |
|
61 | - if (!method_exists($class,ACTION_NAME)) { |
|
60 | + $class=new $class(); |
|
61 | + if (!method_exists($class, ACTION_NAME)) { |
|
62 | 62 | not_found(); |
63 | 63 | } |
64 | 64 | self::param(); |
65 | - self::exec($class,ACTION_NAME); |
|
65 | + self::exec($class, ACTION_NAME); |
|
66 | 66 | } |
67 | - static public function exec($class,$function){ |
|
68 | - $method = new \ReflectionMethod($class, $function); |
|
67 | + static public function exec($class, $function) { |
|
68 | + $method=new \ReflectionMethod($class, $function); |
|
69 | 69 | if ($method->isPublic() && !$method->isStatic()) { |
70 | - $refClass = new \ReflectionClass($class); |
|
70 | + $refClass=new \ReflectionClass($class); |
|
71 | 71 | //前置方法 |
72 | - if ($refClass->hasMethod('_before_' . $function)) { |
|
73 | - $before = $refClass->getMethod('_before_' . $function); |
|
72 | + if ($refClass->hasMethod('_before_'.$function)) { |
|
73 | + $before=$refClass->getMethod('_before_'.$function); |
|
74 | 74 | if ($before->isPublic()) { |
75 | 75 | $before->invoke($class); |
76 | 76 | } |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | //方法本身 |
79 | 79 | $response=$method->invoke($class); |
80 | 80 | //后置方法 |
81 | - if ($refClass->hasMethod('_after_' . $function)) { |
|
82 | - $after = $refClass->getMethod('_after_' . $function); |
|
81 | + if ($refClass->hasMethod('_after_'.$function)) { |
|
82 | + $after=$refClass->getMethod('_after_'.$function); |
|
83 | 83 | if ($after->isPublic()) { |
84 | 84 | $after->invoke($class); |
85 | 85 | } |
@@ -87,17 +87,17 @@ discard block |
||
87 | 87 | self::render($response); |
88 | 88 | } |
89 | 89 | } |
90 | - static public function param(){ |
|
91 | - if(!IS_CLI){ |
|
90 | + static public function param() { |
|
91 | + if (!IS_CLI) { |
|
92 | 92 | $vars=array(); |
93 | - parse_str(parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY),$vars); |
|
93 | + parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $vars); |
|
94 | 94 | $_GET=$vars; |
95 | 95 | } |
96 | 96 | |
97 | 97 | } |
98 | - static public function render($res){ |
|
98 | + static public function render($res) { |
|
99 | 99 | $response=$res; |
100 | - if(is_array($res)){ |
|
100 | + if (is_array($res)) { |
|
101 | 101 | $response=json($res); |
102 | 102 | } |
103 | 103 | echo $response; |
@@ -46,8 +46,8 @@ |
||
46 | 46 | * |
47 | 47 | * pass values when class is istantiated |
48 | 48 | * |
49 | - * @param numeric $_perPage sets the number of iteems per page |
|
50 | - * @param numeric $_instance sets the instance for the GET parameter |
|
49 | + * @param numeric $perPage sets the number of iteems per page |
|
50 | + * @param numeric $instance sets the instance for the GET parameter |
|
51 | 51 | */ |
52 | 52 | public function __construct($perPage,$instance){ |
53 | 53 | $this->_instance = $instance; |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | |
4 | 4 | namespace puck\helpers; |
5 | 5 | |
6 | -class Page{ |
|
6 | +class Page { |
|
7 | 7 | /** |
8 | 8 | * set the number of items per page. |
9 | 9 | * |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @var numeric |
39 | 39 | */ |
40 | - private $_totalRows = 0; |
|
40 | + private $_totalRows=0; |
|
41 | 41 | |
42 | 42 | |
43 | 43 | |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | * @param numeric $_perPage sets the number of iteems per page |
50 | 50 | * @param numeric $_instance sets the instance for the GET parameter |
51 | 51 | */ |
52 | - public function __construct($perPage,$instance){ |
|
53 | - $this->_instance = $instance; |
|
54 | - $this->_perPage = $perPage; |
|
52 | + public function __construct($perPage, $instance) { |
|
53 | + $this->_instance=$instance; |
|
54 | + $this->_perPage=$perPage; |
|
55 | 55 | $this->set_instance(); |
56 | 56 | } |
57 | 57 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * creates the starting point for limiting the dataset |
62 | 62 | * @return numeric |
63 | 63 | */ |
64 | - public function get_start(){ |
|
64 | + public function get_start() { |
|
65 | 65 | return ($this->_page * $this->_perPage) - $this->_perPage; |
66 | 66 | } |
67 | 67 | |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @var numeric |
74 | 74 | */ |
75 | - private function set_instance(){ |
|
76 | - $this->_page = (int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); |
|
77 | - $this->_page = ($this->_page == 0 ? 1 : $this->_page); |
|
75 | + private function set_instance() { |
|
76 | + $this->_page=(int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); |
|
77 | + $this->_page=($this->_page == 0 ? 1 : $this->_page); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @var numeric |
86 | 86 | */ |
87 | - public function set_total($_totalRows){ |
|
88 | - $this->_totalRows = $_totalRows; |
|
87 | + public function set_total($_totalRows) { |
|
88 | + $this->_totalRows=$_totalRows; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return string |
97 | 97 | */ |
98 | - public function get_limit(){ |
|
98 | + public function get_limit() { |
|
99 | 99 | return "LIMIT ".$this->get_start().",$this->_perPage"; |
100 | 100 | } |
101 | 101 | |
102 | 102 | |
103 | - private function getParam(){ |
|
103 | + private function getParam() { |
|
104 | 104 | $vars=$_GET; |
105 | - if(isset($vars[$this->_instance])){ |
|
105 | + if (isset($vars[$this->_instance])) { |
|
106 | 106 | unset($vars[$this->_instance]); |
107 | 107 | } |
108 | 108 | $str=http_build_query($vars); |
109 | - $str ='&'.$str; |
|
109 | + $str='&'.$str; |
|
110 | 110 | return $str; |
111 | 111 | } |
112 | 112 | |
@@ -119,86 +119,86 @@ discard block |
||
119 | 119 | * @var sting $ext optionally pass in extra parameters to the GET |
120 | 120 | * @return string returns the html menu |
121 | 121 | */ |
122 | - public function page_links($path='?',$ext=null) |
|
122 | + public function page_links($path='?', $ext=null) |
|
123 | 123 | { |
124 | - $adjacents = "2"; |
|
125 | - $prev = $this->_page - 1; |
|
126 | - $next = $this->_page + 1; |
|
127 | - $lastpage = ceil($this->_totalRows/$this->_perPage); |
|
128 | - $lpm1 = $lastpage - 1; |
|
129 | - $pagination = ""; |
|
130 | - if($lastpage > 1) |
|
124 | + $adjacents="2"; |
|
125 | + $prev=$this->_page - 1; |
|
126 | + $next=$this->_page + 1; |
|
127 | + $lastpage=ceil($this->_totalRows / $this->_perPage); |
|
128 | + $lpm1=$lastpage - 1; |
|
129 | + $pagination=""; |
|
130 | + if ($lastpage > 1) |
|
131 | 131 | { |
132 | - if($ext==null){ |
|
132 | + if ($ext == null) { |
|
133 | 133 | $ext=$this->getParam(); |
134 | 134 | } |
135 | - $pagination .= "<ul class='pager'>"; |
|
135 | + $pagination.="<ul class='pager'>"; |
|
136 | 136 | if ($this->_page > 1) |
137 | - $pagination.= "<li class='previous'><a href='".$path."$this->_instance=$prev"."$ext'><<</a></li>"; |
|
137 | + $pagination.="<li class='previous'><a href='".$path."$this->_instance=$prev"."$ext'><<</a></li>"; |
|
138 | 138 | else |
139 | - $pagination.= "<li class='disabled previous'><span class='disabled'><<</span></li>"; |
|
139 | + $pagination.="<li class='disabled previous'><span class='disabled'><<</span></li>"; |
|
140 | 140 | |
141 | 141 | if ($lastpage < 7 + ($adjacents * 2)) |
142 | 142 | { |
143 | - for ($counter = 1; $counter <= $lastpage; $counter++) |
|
143 | + for ($counter=1; $counter <= $lastpage; $counter++) |
|
144 | 144 | { |
145 | 145 | if ($counter == $this->_page) |
146 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
146 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
147 | 147 | else |
148 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
148 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
149 | 149 | } |
150 | 150 | } |
151 | - elseif($lastpage > 5 + ($adjacents * 2)) |
|
151 | + elseif ($lastpage > 5 + ($adjacents * 2)) |
|
152 | 152 | { |
153 | - if($this->_page < 1 + ($adjacents * 2)) |
|
153 | + if ($this->_page < 1 + ($adjacents * 2)) |
|
154 | 154 | { |
155 | - for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) |
|
155 | + for ($counter=1; $counter < 4 + ($adjacents * 2); $counter++) |
|
156 | 156 | { |
157 | 157 | if ($counter == $this->_page) |
158 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
158 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
159 | 159 | else |
160 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
160 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
161 | 161 | } |
162 | - $pagination.= "..."; |
|
163 | - $pagination.= "<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
|
164 | - $pagination.= "<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
|
162 | + $pagination.="..."; |
|
163 | + $pagination.="<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
|
164 | + $pagination.="<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
|
165 | 165 | } |
166 | - elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) |
|
166 | + elseif ($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) |
|
167 | 167 | { |
168 | - $pagination.= "<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
|
169 | - $pagination.= "<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
|
170 | - $pagination.= "..."; |
|
171 | - for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++) |
|
168 | + $pagination.="<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
|
169 | + $pagination.="<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
|
170 | + $pagination.="..."; |
|
171 | + for ($counter=$this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++) |
|
172 | 172 | { |
173 | 173 | if ($counter == $this->_page) |
174 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
174 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
175 | 175 | else |
176 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
176 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
177 | 177 | } |
178 | - $pagination.= ".."; |
|
179 | - $pagination.= "<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
|
180 | - $pagination.= "<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
|
178 | + $pagination.=".."; |
|
179 | + $pagination.="<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
|
180 | + $pagination.="<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
|
181 | 181 | } |
182 | 182 | else |
183 | 183 | { |
184 | - $pagination.= "<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
|
185 | - $pagination.= "<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
|
186 | - $pagination.= ".."; |
|
187 | - for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) |
|
184 | + $pagination.="<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
|
185 | + $pagination.="<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
|
186 | + $pagination.=".."; |
|
187 | + for ($counter=$lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) |
|
188 | 188 | { |
189 | 189 | if ($counter == $this->_page) |
190 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
190 | + $pagination.="<li class='current'><span>$counter</span></li>"; |
|
191 | 191 | else |
192 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
192 | + $pagination.="<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | 197 | if ($this->_page < $counter - 1) |
198 | - $pagination.= "<li class='next'><a href='".$path."$this->_instance=$next"."$ext'>>></a></li>"; |
|
198 | + $pagination.="<li class='next'><a href='".$path."$this->_instance=$next"."$ext'>>></a></li>"; |
|
199 | 199 | else |
200 | - $pagination.= "<li class='next disabled'><span class='disabled'>>></span></li>"; |
|
201 | - $pagination.= "</ul>\n"; |
|
200 | + $pagination.="<li class='next disabled'><span class='disabled'>>></span></li>"; |
|
201 | + $pagination.="</ul>\n"; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 |
@@ -133,71 +133,74 @@ |
||
133 | 133 | $ext=$this->getParam(); |
134 | 134 | } |
135 | 135 | $pagination .= "<ul class='pager'>"; |
136 | - if ($this->_page > 1) |
|
137 | - $pagination.= "<li class='previous'><a href='".$path."$this->_instance=$prev"."$ext'><<</a></li>"; |
|
138 | - else |
|
139 | - $pagination.= "<li class='disabled previous'><span class='disabled'><<</span></li>"; |
|
136 | + if ($this->_page > 1) { |
|
137 | + $pagination.= "<li class='previous'><a href='".$path."$this->_instance=$prev"."$ext'><<</a></li>"; |
|
138 | + } else { |
|
139 | + $pagination.= "<li class='disabled previous'><span class='disabled'><<</span></li>"; |
|
140 | + } |
|
140 | 141 | |
141 | 142 | if ($lastpage < 7 + ($adjacents * 2)) |
142 | 143 | { |
143 | 144 | for ($counter = 1; $counter <= $lastpage; $counter++) |
144 | 145 | { |
145 | - if ($counter == $this->_page) |
|
146 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
147 | - else |
|
148 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
146 | + if ($counter == $this->_page) { |
|
147 | + $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
148 | + } else { |
|
149 | + $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
150 | + } |
|
149 | 151 | } |
150 | - } |
|
151 | - elseif($lastpage > 5 + ($adjacents * 2)) |
|
152 | + } elseif($lastpage > 5 + ($adjacents * 2)) |
|
152 | 153 | { |
153 | 154 | if($this->_page < 1 + ($adjacents * 2)) |
154 | 155 | { |
155 | 156 | for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) |
156 | 157 | { |
157 | - if ($counter == $this->_page) |
|
158 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
159 | - else |
|
160 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
158 | + if ($counter == $this->_page) { |
|
159 | + $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
160 | + } else { |
|
161 | + $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
162 | + } |
|
161 | 163 | } |
162 | 164 | $pagination.= "..."; |
163 | 165 | $pagination.= "<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
164 | 166 | $pagination.= "<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
165 | - } |
|
166 | - elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) |
|
167 | + } elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) |
|
167 | 168 | { |
168 | 169 | $pagination.= "<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
169 | 170 | $pagination.= "<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
170 | 171 | $pagination.= "..."; |
171 | 172 | for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++) |
172 | 173 | { |
173 | - if ($counter == $this->_page) |
|
174 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
175 | - else |
|
176 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
174 | + if ($counter == $this->_page) { |
|
175 | + $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
176 | + } else { |
|
177 | + $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
178 | + } |
|
177 | 179 | } |
178 | 180 | $pagination.= ".."; |
179 | 181 | $pagination.= "<li><a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a></li>"; |
180 | 182 | $pagination.= "<li><a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a></li>"; |
181 | - } |
|
182 | - else |
|
183 | + } else |
|
183 | 184 | { |
184 | 185 | $pagination.= "<li><a href='".$path."$this->_instance=1"."$ext'>1</a></li>"; |
185 | 186 | $pagination.= "<li><a href='".$path."$this->_instance=2"."$ext'>2</a></li>"; |
186 | 187 | $pagination.= ".."; |
187 | 188 | for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) |
188 | 189 | { |
189 | - if ($counter == $this->_page) |
|
190 | - $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
191 | - else |
|
192 | - $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
190 | + if ($counter == $this->_page) { |
|
191 | + $pagination.= "<li class='current'><span>$counter</span></li>"; |
|
192 | + } else { |
|
193 | + $pagination.= "<li><a href='".$path."$this->_instance=$counter"."$ext'>$counter</a></li>"; |
|
194 | + } |
|
193 | 195 | } |
194 | 196 | } |
195 | 197 | } |
196 | 198 | |
197 | - if ($this->_page < $counter - 1) |
|
198 | - $pagination.= "<li class='next'><a href='".$path."$this->_instance=$next"."$ext'>>></a></li>"; |
|
199 | - else |
|
200 | - $pagination.= "<li class='next disabled'><span class='disabled'>>></span></li>"; |
|
199 | + if ($this->_page < $counter - 1) { |
|
200 | + $pagination.= "<li class='next'><a href='".$path."$this->_instance=$next"."$ext'>>></a></li>"; |
|
201 | + } else { |
|
202 | + $pagination.= "<li class='next disabled'><span class='disabled'>>></span></li>"; |
|
203 | + } |
|
201 | 204 | $pagination.= "</ul>\n"; |
202 | 205 | } |
203 | 206 |
@@ -1098,7 +1098,7 @@ discard block |
||
1098 | 1098 | * @access protected |
1099 | 1099 | * @param string $value 字段值 |
1100 | 1100 | * @param mixed $rule 验证规则 |
1101 | - * @return mixed |
|
1101 | + * @return boolean |
|
1102 | 1102 | */ |
1103 | 1103 | protected function allowIp($value, $rule) |
1104 | 1104 | { |
@@ -1110,7 +1110,7 @@ discard block |
||
1110 | 1110 | * @access protected |
1111 | 1111 | * @param string $value 字段值 |
1112 | 1112 | * @param mixed $rule 验证规则 |
1113 | - * @return mixed |
|
1113 | + * @return boolean |
|
1114 | 1114 | */ |
1115 | 1115 | protected function denyIp($value, $rule) |
1116 | 1116 | { |
@@ -1121,8 +1121,8 @@ discard block |
||
1121 | 1121 | * 使用正则验证数据 |
1122 | 1122 | * @access protected |
1123 | 1123 | * @param mixed $value 字段值 |
1124 | - * @param mixed $rule 验证规则 正则规则或者预定义正则名 |
|
1125 | - * @return mixed |
|
1124 | + * @param string $rule 验证规则 正则规则或者预定义正则名 |
|
1125 | + * @return boolean |
|
1126 | 1126 | */ |
1127 | 1127 | protected function regex($value, $rule) |
1128 | 1128 | { |
@@ -1140,7 +1140,7 @@ discard block |
||
1140 | 1140 | * 验证表单令牌 |
1141 | 1141 | * @access protected |
1142 | 1142 | * @param mixed $value 字段值 |
1143 | - * @param mixed $rule 验证规则 |
|
1143 | + * @param string $rule 验证规则 |
|
1144 | 1144 | * @param array $data 数据 |
1145 | 1145 | * @return bool |
1146 | 1146 | */ |
@@ -11,23 +11,23 @@ discard block |
||
11 | 11 | protected static $instance; |
12 | 12 | |
13 | 13 | // 自定义的验证类型 |
14 | - protected static $type = []; |
|
14 | + protected static $type=[]; |
|
15 | 15 | |
16 | 16 | // 验证类型别名 |
17 | - protected $alias = [ |
|
17 | + protected $alias=[ |
|
18 | 18 | '>' => 'gt', '>=' => 'egt', '<' => 'lt', '<=' => 'elt', '=' => 'eq', 'same' => 'eq', |
19 | 19 | ]; |
20 | 20 | |
21 | 21 | // 当前验证的规则 |
22 | - protected $rule = []; |
|
22 | + protected $rule=[]; |
|
23 | 23 | |
24 | 24 | // 验证提示信息 |
25 | - protected $message = []; |
|
25 | + protected $message=[]; |
|
26 | 26 | // 验证字段描述 |
27 | - protected $field = []; |
|
27 | + protected $field=[]; |
|
28 | 28 | |
29 | 29 | // 验证规则默认提示信息 |
30 | - protected static $typeMsg = [ |
|
30 | + protected static $typeMsg=[ |
|
31 | 31 | 'require' => ':attribute不能为空', |
32 | 32 | 'number' => ':attribute必须是数字', |
33 | 33 | 'float' => ':attribute必须是浮点数', |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | ]; |
80 | 80 | |
81 | 81 | // 当前验证场景 |
82 | - protected $currentScene = null; |
|
82 | + protected $currentScene=null; |
|
83 | 83 | |
84 | 84 | // 正则表达式 regex = ['zip'=>'\d{6}',...] |
85 | - protected $regex = []; |
|
85 | + protected $regex=[]; |
|
86 | 86 | |
87 | 87 | // 验证场景 scene = ['edit'=>'name1,name2,...'] |
88 | - protected $scene = []; |
|
88 | + protected $scene=[]; |
|
89 | 89 | |
90 | 90 | // 验证失败错误信息 |
91 | - protected $error = []; |
|
91 | + protected $error=[]; |
|
92 | 92 | |
93 | 93 | // 批量验证 |
94 | - protected $batch = false; |
|
94 | + protected $batch=false; |
|
95 | 95 | |
96 | 96 | /** |
97 | 97 | * 构造函数 |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | * @param array $message 验证提示信息 |
101 | 101 | * @param array $field 验证字段描述信息 |
102 | 102 | */ |
103 | - public function __construct(array $rules = [], $message = [], $field = []) |
|
103 | + public function __construct(array $rules=[], $message=[], $field=[]) |
|
104 | 104 | { |
105 | - $this->rule = array_merge($this->rule, $rules); |
|
106 | - $this->message = array_merge($this->message, $message); |
|
107 | - $this->field = array_merge($this->field, $field); |
|
105 | + $this->rule=array_merge($this->rule, $rules); |
|
106 | + $this->message=array_merge($this->message, $message); |
|
107 | + $this->field=array_merge($this->field, $field); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | * @param array $field 验证字段描述信息 |
116 | 116 | * @return Validate |
117 | 117 | */ |
118 | - public static function make($rules = [], $message = [], $field = []) |
|
118 | + public static function make($rules=[], $message=[], $field=[]) |
|
119 | 119 | { |
120 | 120 | if (is_null(self::$instance)) { |
121 | - self::$instance = new self($rules, $message, $field); |
|
121 | + self::$instance=new self($rules, $message, $field); |
|
122 | 122 | } |
123 | 123 | return self::$instance; |
124 | 124 | } |
@@ -130,12 +130,12 @@ discard block |
||
130 | 130 | * @param mixed $rule 验证规则 |
131 | 131 | * @return Validate |
132 | 132 | */ |
133 | - public function rule($name, $rule = '') |
|
133 | + public function rule($name, $rule='') |
|
134 | 134 | { |
135 | 135 | if (is_array($name)) { |
136 | - $this->rule = array_merge($this->rule, $name); |
|
136 | + $this->rule=array_merge($this->rule, $name); |
|
137 | 137 | } else { |
138 | - $this->rule[$name] = $rule; |
|
138 | + $this->rule[$name]=$rule; |
|
139 | 139 | } |
140 | 140 | return $this; |
141 | 141 | } |
@@ -147,12 +147,12 @@ discard block |
||
147 | 147 | * @param mixed $callback callback方法(或闭包) |
148 | 148 | * @return void |
149 | 149 | */ |
150 | - public static function extend($type, $callback = null) |
|
150 | + public static function extend($type, $callback=null) |
|
151 | 151 | { |
152 | 152 | if (is_array($type)) { |
153 | - self::$type = array_merge(self::$type, $type); |
|
153 | + self::$type=array_merge(self::$type, $type); |
|
154 | 154 | } else { |
155 | - self::$type[$type] = $callback; |
|
155 | + self::$type[$type]=$callback; |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | * @param string $msg 验证提示信息 |
164 | 164 | * @return void |
165 | 165 | */ |
166 | - public static function setTypeMsg($type, $msg = null) |
|
166 | + public static function setTypeMsg($type, $msg=null) |
|
167 | 167 | { |
168 | 168 | if (is_array($type)) { |
169 | - self::$typeMsg = array_merge(self::$typeMsg, $type); |
|
169 | + self::$typeMsg=array_merge(self::$typeMsg, $type); |
|
170 | 170 | } else { |
171 | - self::$typeMsg[$type] = $msg; |
|
171 | + self::$typeMsg[$type]=$msg; |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | * @param string $message 提示信息 |
180 | 180 | * @return Validate |
181 | 181 | */ |
182 | - public function message($name, $message = '') |
|
182 | + public function message($name, $message='') |
|
183 | 183 | { |
184 | 184 | if (is_array($name)) { |
185 | - $this->message = array_merge($this->message, $name); |
|
185 | + $this->message=array_merge($this->message, $name); |
|
186 | 186 | } else { |
187 | - $this->message[$name] = $message; |
|
187 | + $this->message[$name]=$message; |
|
188 | 188 | } |
189 | 189 | return $this; |
190 | 190 | } |
@@ -196,16 +196,16 @@ discard block |
||
196 | 196 | * @param mixed $fields 要验证的字段 |
197 | 197 | * @return Validate |
198 | 198 | */ |
199 | - public function scene($name, $fields = null) |
|
199 | + public function scene($name, $fields=null) |
|
200 | 200 | { |
201 | 201 | if (is_array($name)) { |
202 | - $this->scene = array_merge($this->scene, $name); |
|
202 | + $this->scene=array_merge($this->scene, $name); |
|
203 | 203 | }if (is_null($fields)) { |
204 | 204 | // 设置当前场景 |
205 | - $this->currentScene = $name; |
|
205 | + $this->currentScene=$name; |
|
206 | 206 | } else { |
207 | 207 | // 设置验证场景 |
208 | - $this->scene[$name] = $fields; |
|
208 | + $this->scene[$name]=$fields; |
|
209 | 209 | } |
210 | 210 | return $this; |
211 | 211 | } |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | * @param bool $batch 是否批量验证 |
228 | 228 | * @return Validate |
229 | 229 | */ |
230 | - public function batch($batch = true) |
|
230 | + public function batch($batch=true) |
|
231 | 231 | { |
232 | - $this->batch = $batch; |
|
232 | + $this->batch=$batch; |
|
233 | 233 | return $this; |
234 | 234 | } |
235 | 235 | |
@@ -241,27 +241,27 @@ discard block |
||
241 | 241 | * @param string $scene 验证场景 |
242 | 242 | * @return bool |
243 | 243 | */ |
244 | - public function check($data, $rules = [], $scene = '') |
|
244 | + public function check($data, $rules=[], $scene='') |
|
245 | 245 | { |
246 | - $this->error = []; |
|
246 | + $this->error=[]; |
|
247 | 247 | |
248 | 248 | if (empty($rules)) { |
249 | 249 | // 读取验证规则 |
250 | - $rules = $this->rule; |
|
250 | + $rules=$this->rule; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | // 分析验证规则 |
254 | - $scene = $this->getScene($scene); |
|
254 | + $scene=$this->getScene($scene); |
|
255 | 255 | if (is_array($scene)) { |
256 | 256 | // 处理场景验证字段 |
257 | - $change = []; |
|
258 | - $array = []; |
|
257 | + $change=[]; |
|
258 | + $array=[]; |
|
259 | 259 | foreach ($scene as $k => $val) { |
260 | 260 | if (is_numeric($k)) { |
261 | - $array[] = $val; |
|
261 | + $array[]=$val; |
|
262 | 262 | } else { |
263 | - $array[] = $k; |
|
264 | - $change[$k] = $val; |
|
263 | + $array[]=$k; |
|
264 | + $change[$k]=$val; |
|
265 | 265 | } |
266 | 266 | } |
267 | 267 | } |
@@ -270,22 +270,22 @@ discard block |
||
270 | 270 | // field => rule1|rule2... field=>['rule1','rule2',...] |
271 | 271 | if (is_numeric($key)) { |
272 | 272 | // [field,rule1|rule2,msg1|msg2] |
273 | - $key = $item[0]; |
|
274 | - $rule = $item[1]; |
|
273 | + $key=$item[0]; |
|
274 | + $rule=$item[1]; |
|
275 | 275 | if (isset($item[2])) { |
276 | - $msg = is_string($item[2]) ? explode('|', $item[2]) : $item[2]; |
|
276 | + $msg=is_string($item[2]) ? explode('|', $item[2]) : $item[2]; |
|
277 | 277 | } else { |
278 | - $msg = []; |
|
278 | + $msg=[]; |
|
279 | 279 | } |
280 | 280 | } else { |
281 | - $rule = $item; |
|
282 | - $msg = []; |
|
281 | + $rule=$item; |
|
282 | + $msg=[]; |
|
283 | 283 | } |
284 | 284 | if (strpos($key, '|')) { |
285 | 285 | // 字段|描述 用于指定属性名称 |
286 | - list($key, $title) = explode('|', $key); |
|
286 | + list($key, $title)=explode('|', $key); |
|
287 | 287 | } else { |
288 | - $title = isset($this->field[$key]) ? $this->field[$key] : $key; |
|
288 | + $title=isset($this->field[$key]) ? $this->field[$key] : $key; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | // 场景检测 |
@@ -297,20 +297,20 @@ discard block |
||
297 | 297 | continue; |
298 | 298 | } elseif (isset($change[$key])) { |
299 | 299 | // 重载某个验证规则 |
300 | - $rule = $change[$key]; |
|
300 | + $rule=$change[$key]; |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | 305 | // 获取数据 支持二维数组 |
306 | - $value = $this->getDataValue($data, $key); |
|
306 | + $value=$this->getDataValue($data, $key); |
|
307 | 307 | |
308 | 308 | // 字段验证 |
309 | 309 | if ($rule instanceof \Closure) { |
310 | 310 | // 匿名函数验证 支持传入当前字段和所有字段两个数据 |
311 | - $result = call_user_func_array($rule, [$value, $data]); |
|
311 | + $result=call_user_func_array($rule, [$value, $data]); |
|
312 | 312 | } else { |
313 | - $result = $this->checkItem($key, $value, $rule, $data, $title, $msg); |
|
313 | + $result=$this->checkItem($key, $value, $rule, $data, $title, $msg); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | if (true !== $result) { |
@@ -318,12 +318,12 @@ discard block |
||
318 | 318 | if (!empty($this->batch)) { |
319 | 319 | // 批量验证 |
320 | 320 | if (is_array($result)) { |
321 | - $this->error = array_merge($this->error, $result); |
|
321 | + $this->error=array_merge($this->error, $result); |
|
322 | 322 | } else { |
323 | - $this->error[$key] = $result; |
|
323 | + $this->error[$key]=$result; |
|
324 | 324 | } |
325 | 325 | } else { |
326 | - $this->error = $result; |
|
326 | + $this->error=$result; |
|
327 | 327 | return false; |
328 | 328 | } |
329 | 329 | } |
@@ -342,65 +342,65 @@ discard block |
||
342 | 342 | * @param array $msg 提示信息 |
343 | 343 | * @return mixed |
344 | 344 | */ |
345 | - protected function checkItem($field, $value, $rules, $data, $title = '', $msg = []) |
|
345 | + protected function checkItem($field, $value, $rules, $data, $title='', $msg=[]) |
|
346 | 346 | { |
347 | 347 | // 支持多规则验证 require|in:a,b,c|... 或者 ['require','in'=>'a,b,c',...] |
348 | 348 | if (is_string($rules)) { |
349 | - $rules = explode('|', $rules); |
|
349 | + $rules=explode('|', $rules); |
|
350 | 350 | } |
351 | - $i = 0; |
|
351 | + $i=0; |
|
352 | 352 | foreach ($rules as $key => $rule) { |
353 | 353 | if ($rule instanceof \Closure) { |
354 | - $result = call_user_func_array($rule, [$value, $data]); |
|
355 | - $info = is_numeric($key) ? '' : $key; |
|
354 | + $result=call_user_func_array($rule, [$value, $data]); |
|
355 | + $info=is_numeric($key) ? '' : $key; |
|
356 | 356 | } else { |
357 | 357 | // 判断验证类型 |
358 | 358 | if (is_numeric($key)) { |
359 | 359 | if (strpos($rule, ':')) { |
360 | - list($type, $rule) = explode(':', $rule, 2); |
|
360 | + list($type, $rule)=explode(':', $rule, 2); |
|
361 | 361 | if (isset($this->alias[$type])) { |
362 | 362 | // 判断别名 |
363 | - $type = $this->alias[$type]; |
|
363 | + $type=$this->alias[$type]; |
|
364 | 364 | } |
365 | - $info = $type; |
|
365 | + $info=$type; |
|
366 | 366 | } elseif (method_exists($this, $rule)) { |
367 | - $type = $rule; |
|
368 | - $info = $rule; |
|
369 | - $rule = ''; |
|
367 | + $type=$rule; |
|
368 | + $info=$rule; |
|
369 | + $rule=''; |
|
370 | 370 | } else { |
371 | - $type = 'is'; |
|
372 | - $info = $rule; |
|
371 | + $type='is'; |
|
372 | + $info=$rule; |
|
373 | 373 | } |
374 | 374 | } else { |
375 | - $info = $type = $key; |
|
375 | + $info=$type=$key; |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | // 如果不是require 有数据才会行验证 |
379 | 379 | if (0 === strpos($info, 'require') || (!is_null($value) && '' !== $value)) { |
380 | 380 | // 验证类型 |
381 | - $callback = isset(self::$type[$type]) ? self::$type[$type] : [$this, $type]; |
|
381 | + $callback=isset(self::$type[$type]) ? self::$type[$type] : [$this, $type]; |
|
382 | 382 | // 验证数据 |
383 | - $result = call_user_func_array($callback, [$value, $rule, $data, $field, $title]); |
|
383 | + $result=call_user_func_array($callback, [$value, $rule, $data, $field, $title]); |
|
384 | 384 | } else { |
385 | - $result = true; |
|
385 | + $result=true; |
|
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
389 | 389 | if (false === $result) { |
390 | 390 | // 验证失败 返回错误信息 |
391 | 391 | if (isset($msg[$i])) { |
392 | - $message = $msg[$i]; |
|
392 | + $message=$msg[$i]; |
|
393 | 393 | if (is_string($message) && strpos($message, '{%') === 0) { |
394 | - $message = Lang::get(substr($message, 2, -1)); |
|
394 | + $message=Lang::get(substr($message, 2, -1)); |
|
395 | 395 | } |
396 | 396 | } else { |
397 | - $message = $this->getRuleMsg($field, $title, $info, $rule); |
|
397 | + $message=$this->getRuleMsg($field, $title, $info, $rule); |
|
398 | 398 | } |
399 | 399 | return $message; |
400 | 400 | } elseif (true !== $result) { |
401 | 401 | // 返回自定义错误信息 |
402 | 402 | if (is_string($result) && false !== strpos($result, ':')) { |
403 | - $result = str_replace([':attribute', ':rule'], [$title, (string) $rule], $result); |
|
403 | + $result=str_replace([':attribute', ':rule'], [$title, (string) $rule], $result); |
|
404 | 404 | } |
405 | 405 | return $result; |
406 | 406 | } |
@@ -418,13 +418,13 @@ discard block |
||
418 | 418 | * @param string $field 字段名 |
419 | 419 | * @return bool |
420 | 420 | */ |
421 | - protected function confirm($value, $rule, $data, $field = '') |
|
421 | + protected function confirm($value, $rule, $data, $field='') |
|
422 | 422 | { |
423 | 423 | if ('' == $rule) { |
424 | 424 | if (strpos($field, '_confirm')) { |
425 | - $rule = strstr($field, '_confirm', true); |
|
425 | + $rule=strstr($field, '_confirm', true); |
|
426 | 426 | } else { |
427 | - $rule = $field . '_confirm'; |
|
427 | + $rule=$field.'_confirm'; |
|
428 | 428 | } |
429 | 429 | } |
430 | 430 | return $this->getDataValue($data, $rule) === $value; |
@@ -511,100 +511,100 @@ discard block |
||
511 | 511 | * @param array $data 验证数据 |
512 | 512 | * @return bool |
513 | 513 | */ |
514 | - protected function is($value, $rule, $data = []) |
|
514 | + protected function is($value, $rule, $data=[]) |
|
515 | 515 | { |
516 | 516 | switch ($rule) { |
517 | 517 | case 'require': |
518 | 518 | // 必须 |
519 | - $result = !empty($value) || '0' == $value; |
|
519 | + $result=!empty($value) || '0' == $value; |
|
520 | 520 | break; |
521 | 521 | case 'accepted': |
522 | 522 | // 接受 |
523 | - $result = in_array($value, ['1', 'on', 'yes']); |
|
523 | + $result=in_array($value, ['1', 'on', 'yes']); |
|
524 | 524 | break; |
525 | 525 | case 'date': |
526 | 526 | // 是否是一个有效日期 |
527 | - $result = false !== strtotime($value); |
|
527 | + $result=false !== strtotime($value); |
|
528 | 528 | break; |
529 | 529 | case 'alpha': |
530 | 530 | // 只允许字母 |
531 | - $result = $this->regex($value, '/^[A-Za-z]+$/'); |
|
531 | + $result=$this->regex($value, '/^[A-Za-z]+$/'); |
|
532 | 532 | break; |
533 | 533 | case 'alphaNum': |
534 | 534 | // 只允许字母和数字 |
535 | - $result = $this->regex($value, '/^[A-Za-z0-9]+$/'); |
|
535 | + $result=$this->regex($value, '/^[A-Za-z0-9]+$/'); |
|
536 | 536 | break; |
537 | 537 | case 'alphaDash': |
538 | 538 | // 只允许字母、数字和下划线 破折号 |
539 | - $result = $this->regex($value, '/^[A-Za-z0-9\-\_]+$/'); |
|
539 | + $result=$this->regex($value, '/^[A-Za-z0-9\-\_]+$/'); |
|
540 | 540 | break; |
541 | 541 | case 'chs': |
542 | 542 | // 只允许汉字 |
543 | - $result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}]+$/u'); |
|
543 | + $result=$this->regex($value, '/^[\x{4e00}-\x{9fa5}]+$/u'); |
|
544 | 544 | break; |
545 | 545 | case 'chsAlpha': |
546 | 546 | // 只允许汉字、字母 |
547 | - $result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z]+$/u'); |
|
547 | + $result=$this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z]+$/u'); |
|
548 | 548 | break; |
549 | 549 | case 'chsAlphaNum': |
550 | 550 | // 只允许汉字、字母和数字 |
551 | - $result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9]+$/u'); |
|
551 | + $result=$this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9]+$/u'); |
|
552 | 552 | break; |
553 | 553 | case 'chsDash': |
554 | 554 | // 只允许汉字、字母、数字和下划线_及破折号- |
555 | - $result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-]+$/u'); |
|
555 | + $result=$this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-]+$/u'); |
|
556 | 556 | break; |
557 | 557 | case 'activeUrl': |
558 | 558 | // 是否为有效的网址 |
559 | - $result = checkdnsrr($value); |
|
559 | + $result=checkdnsrr($value); |
|
560 | 560 | break; |
561 | 561 | case 'ip': |
562 | 562 | // 是否为IP地址 |
563 | - $result = $this->filter($value, [FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6]); |
|
563 | + $result=$this->filter($value, [FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6]); |
|
564 | 564 | break; |
565 | 565 | case 'url': |
566 | 566 | // 是否为一个URL地址 |
567 | - $result = $this->filter($value, FILTER_VALIDATE_URL); |
|
567 | + $result=$this->filter($value, FILTER_VALIDATE_URL); |
|
568 | 568 | break; |
569 | 569 | case 'float': |
570 | 570 | // 是否为float |
571 | - $result = $this->filter($value, FILTER_VALIDATE_FLOAT); |
|
571 | + $result=$this->filter($value, FILTER_VALIDATE_FLOAT); |
|
572 | 572 | break; |
573 | 573 | case 'number': |
574 | - $result = is_numeric($value); |
|
574 | + $result=is_numeric($value); |
|
575 | 575 | break; |
576 | 576 | case 'integer': |
577 | 577 | // 是否为整型 |
578 | - $result = $this->filter($value, FILTER_VALIDATE_INT); |
|
578 | + $result=$this->filter($value, FILTER_VALIDATE_INT); |
|
579 | 579 | break; |
580 | 580 | case 'email': |
581 | 581 | // 是否为邮箱地址 |
582 | - $result = $this->filter($value, FILTER_VALIDATE_EMAIL); |
|
582 | + $result=$this->filter($value, FILTER_VALIDATE_EMAIL); |
|
583 | 583 | break; |
584 | 584 | case 'boolean': |
585 | 585 | // 是否为布尔值 |
586 | - $result = in_array($value, [true, false, 0, 1, '0', '1'], true); |
|
586 | + $result=in_array($value, [true, false, 0, 1, '0', '1'], true); |
|
587 | 587 | break; |
588 | 588 | case 'array': |
589 | 589 | // 是否为数组 |
590 | - $result = is_array($value); |
|
590 | + $result=is_array($value); |
|
591 | 591 | break; |
592 | 592 | case 'file': |
593 | - $result = $value instanceof File; |
|
593 | + $result=$value instanceof File; |
|
594 | 594 | break; |
595 | 595 | case 'image': |
596 | - $result = $value instanceof File && in_array($this->getImageType($value->getRealPath()), [1, 2, 3, 6]); |
|
596 | + $result=$value instanceof File && in_array($this->getImageType($value->getRealPath()), [1, 2, 3, 6]); |
|
597 | 597 | break; |
598 | 598 | case 'token': |
599 | - $result = $this->token($value, '__token__', $data); |
|
599 | + $result=$this->token($value, '__token__', $data); |
|
600 | 600 | break; |
601 | 601 | default: |
602 | 602 | if (isset(self::$type[$rule])) { |
603 | 603 | // 注册的验证规则 |
604 | - $result = call_user_func_array(self::$type[$rule], [$value]); |
|
604 | + $result=call_user_func_array(self::$type[$rule], [$value]); |
|
605 | 605 | } else { |
606 | 606 | // 正则验证 |
607 | - $result = $this->regex($value, $rule); |
|
607 | + $result=$this->regex($value, $rule); |
|
608 | 608 | } |
609 | 609 | } |
610 | 610 | return $result; |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | if (function_exists('exif_imagetype')) { |
617 | 617 | return exif_imagetype($image); |
618 | 618 | } else { |
619 | - $info = getimagesize($image); |
|
619 | + $info=getimagesize($image); |
|
620 | 620 | return $info[2]; |
621 | 621 | } |
622 | 622 | } |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | protected function activeUrl($value, $rule) |
632 | 632 | { |
633 | 633 | if (!in_array($rule, ['A', 'MX', 'NS', 'SOA', 'PTR', 'CNAME', 'AAAA', 'A6', 'SRV', 'NAPTR', 'TXT', 'ANY'])) { |
634 | - $rule = 'MX'; |
|
634 | + $rule='MX'; |
|
635 | 635 | } |
636 | 636 | return checkdnsrr($value, $rule); |
637 | 637 | } |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | protected function ip($value, $rule) |
647 | 647 | { |
648 | 648 | if (!in_array($rule, ['ipv4', 'ipv6'])) { |
649 | - $rule = 'ipv4'; |
|
649 | + $rule='ipv4'; |
|
650 | 650 | } |
651 | 651 | return $this->filter($value, [FILTER_VALIDATE_IP, 'ipv6' == $rule ? FILTER_FLAG_IPV6 : FILTER_FLAG_IPV4]); |
652 | 652 | } |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | return false; |
665 | 665 | } |
666 | 666 | if (is_string($rule)) { |
667 | - $rule = explode(',', $rule); |
|
667 | + $rule=explode(',', $rule); |
|
668 | 668 | } |
669 | 669 | if (is_array($file)) { |
670 | 670 | foreach ($file as $item) { |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | return false; |
692 | 692 | } |
693 | 693 | if (is_string($rule)) { |
694 | - $rule = explode(',', $rule); |
|
694 | + $rule=explode(',', $rule); |
|
695 | 695 | } |
696 | 696 | if (is_array($file)) { |
697 | 697 | foreach ($file as $item) { |
@@ -742,19 +742,19 @@ discard block |
||
742 | 742 | return false; |
743 | 743 | } |
744 | 744 | if ($rule) { |
745 | - $rule = explode(',', $rule); |
|
746 | - list($width, $height, $type) = getimagesize($file->getRealPath()); |
|
745 | + $rule=explode(',', $rule); |
|
746 | + list($width, $height, $type)=getimagesize($file->getRealPath()); |
|
747 | 747 | if (isset($rule[2])) { |
748 | - $imageType = strtolower($rule[2]); |
|
748 | + $imageType=strtolower($rule[2]); |
|
749 | 749 | if ('jpeg' == $imageType) { |
750 | - $imageType = 'jpg'; |
|
750 | + $imageType='jpg'; |
|
751 | 751 | } |
752 | 752 | if (image_type_to_extension($type, false) != $imageType) { |
753 | 753 | return false; |
754 | 754 | } |
755 | 755 | } |
756 | 756 | |
757 | - list($w, $h) = $rule; |
|
757 | + list($w, $h)=$rule; |
|
758 | 758 | return $w == $width && $h == $height; |
759 | 759 | } else { |
760 | 760 | return in_array($this->getImageType($file->getRealPath()), [1, 2, 3, 6]); |
@@ -770,7 +770,7 @@ discard block |
||
770 | 770 | */ |
771 | 771 | protected function method($value, $rule) |
772 | 772 | { |
773 | - $method = Request::instance()->method(); |
|
773 | + $method=Request::instance()->method(); |
|
774 | 774 | return strtoupper($rule) == $method; |
775 | 775 | } |
776 | 776 | |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | */ |
784 | 784 | protected function dateFormat($value, $rule) |
785 | 785 | { |
786 | - $info = date_parse_from_format($rule, $value); |
|
786 | + $info=date_parse_from_format($rule, $value); |
|
787 | 787 | return 0 == $info['warning_count'] && 0 == $info['error_count']; |
788 | 788 | } |
789 | 789 | |
@@ -799,37 +799,37 @@ discard block |
||
799 | 799 | protected function unique($value, $rule, $data, $field) |
800 | 800 | { |
801 | 801 | if (is_string($rule)) { |
802 | - $rule = explode(',', $rule); |
|
802 | + $rule=explode(',', $rule); |
|
803 | 803 | } |
804 | 804 | if (false !== strpos($rule[0], '\\')) { |
805 | 805 | // 指定模型类 |
806 | - $db = new $rule[0]; |
|
806 | + $db=new $rule[0]; |
|
807 | 807 | } else { |
808 | 808 | try { |
809 | - $db = Loader::model($rule[0]); |
|
809 | + $db=Loader::model($rule[0]); |
|
810 | 810 | } catch (ClassNotFoundException $e) { |
811 | - $db = Db::name($rule[0]); |
|
811 | + $db=Db::name($rule[0]); |
|
812 | 812 | } |
813 | 813 | } |
814 | - $key = isset($rule[1]) ? $rule[1] : $field; |
|
814 | + $key=isset($rule[1]) ? $rule[1] : $field; |
|
815 | 815 | |
816 | 816 | if (strpos($key, '^')) { |
817 | 817 | // 支持多个字段验证 |
818 | - $fields = explode('^', $key); |
|
818 | + $fields=explode('^', $key); |
|
819 | 819 | foreach ($fields as $key) { |
820 | - $map[$key] = $data[$key]; |
|
820 | + $map[$key]=$data[$key]; |
|
821 | 821 | } |
822 | 822 | } elseif (strpos($key, '=')) { |
823 | 823 | parse_str($key, $map); |
824 | 824 | } else { |
825 | - $map[$key] = $data[$field]; |
|
825 | + $map[$key]=$data[$field]; |
|
826 | 826 | } |
827 | 827 | |
828 | - $pk = strval(isset($rule[3]) ? $rule[3] : $db->getPk()); |
|
828 | + $pk=strval(isset($rule[3]) ? $rule[3] : $db->getPk()); |
|
829 | 829 | if (isset($rule[2])) { |
830 | - $map[$pk] = ['neq', $rule[2]]; |
|
830 | + $map[$pk]=['neq', $rule[2]]; |
|
831 | 831 | } elseif (isset($data[$pk])) { |
832 | - $map[$pk] = ['neq', $data[$pk]]; |
|
832 | + $map[$pk]=['neq', $data[$pk]]; |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | if ($db->where($map)->field($pk)->find()) { |
@@ -861,12 +861,12 @@ discard block |
||
861 | 861 | protected function filter($value, $rule) |
862 | 862 | { |
863 | 863 | if (is_string($rule) && strpos($rule, ',')) { |
864 | - list($rule, $param) = explode(',', $rule); |
|
864 | + list($rule, $param)=explode(',', $rule); |
|
865 | 865 | } elseif (is_array($rule)) { |
866 | - $param = isset($rule[1]) ? $rule[1] : null; |
|
867 | - $rule = $rule[0]; |
|
866 | + $param=isset($rule[1]) ? $rule[1] : null; |
|
867 | + $rule=$rule[0]; |
|
868 | 868 | } else { |
869 | - $param = null; |
|
869 | + $param=null; |
|
870 | 870 | } |
871 | 871 | return false !== filter_var($value, is_int($rule) ? $rule : filter_id($rule), $param); |
872 | 872 | } |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | */ |
882 | 882 | protected function requireIf($value, $rule, $data) |
883 | 883 | { |
884 | - list($field, $val) = explode(',', $rule); |
|
884 | + list($field, $val)=explode(',', $rule); |
|
885 | 885 | if ($this->getDataValue($data, $field) == $val) { |
886 | 886 | return !empty($value); |
887 | 887 | } else { |
@@ -899,7 +899,7 @@ discard block |
||
899 | 899 | */ |
900 | 900 | protected function requireCallback($value, $rule, $data) |
901 | 901 | { |
902 | - $result = call_user_func_array($rule, [$value, $data]); |
|
902 | + $result=call_user_func_array($rule, [$value, $data]); |
|
903 | 903 | if ($result) { |
904 | 904 | return !empty($value); |
905 | 905 | } else { |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | */ |
918 | 918 | protected function requireWith($value, $rule, $data) |
919 | 919 | { |
920 | - $val = $this->getDataValue($data, $rule); |
|
920 | + $val=$this->getDataValue($data, $rule); |
|
921 | 921 | if (!empty($val)) { |
922 | 922 | return !empty($value); |
923 | 923 | } else { |
@@ -959,9 +959,9 @@ discard block |
||
959 | 959 | protected function between($value, $rule) |
960 | 960 | { |
961 | 961 | if (is_string($rule)) { |
962 | - $rule = explode(',', $rule); |
|
962 | + $rule=explode(',', $rule); |
|
963 | 963 | } |
964 | - list($min, $max) = $rule; |
|
964 | + list($min, $max)=$rule; |
|
965 | 965 | return $value >= $min && $value <= $max; |
966 | 966 | } |
967 | 967 | |
@@ -975,9 +975,9 @@ discard block |
||
975 | 975 | protected function notBetween($value, $rule) |
976 | 976 | { |
977 | 977 | if (is_string($rule)) { |
978 | - $rule = explode(',', $rule); |
|
978 | + $rule=explode(',', $rule); |
|
979 | 979 | } |
980 | - list($min, $max) = $rule; |
|
980 | + list($min, $max)=$rule; |
|
981 | 981 | return $value < $min || $value > $max; |
982 | 982 | } |
983 | 983 | |
@@ -991,16 +991,16 @@ discard block |
||
991 | 991 | protected function length($value, $rule) |
992 | 992 | { |
993 | 993 | if (is_array($value)) { |
994 | - $length = count($value); |
|
994 | + $length=count($value); |
|
995 | 995 | } elseif ($value instanceof File) { |
996 | - $length = $value->getSize(); |
|
996 | + $length=$value->getSize(); |
|
997 | 997 | } else { |
998 | - $length = mb_strlen((string) $value); |
|
998 | + $length=mb_strlen((string) $value); |
|
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | if (strpos($rule, ',')) { |
1002 | 1002 | // 长度区间 |
1003 | - list($min, $max) = explode(',', $rule); |
|
1003 | + list($min, $max)=explode(',', $rule); |
|
1004 | 1004 | return $length >= $min && $length <= $max; |
1005 | 1005 | } else { |
1006 | 1006 | // 指定长度 |
@@ -1018,11 +1018,11 @@ discard block |
||
1018 | 1018 | protected function max($value, $rule) |
1019 | 1019 | { |
1020 | 1020 | if (is_array($value)) { |
1021 | - $length = count($value); |
|
1021 | + $length=count($value); |
|
1022 | 1022 | } elseif ($value instanceof File) { |
1023 | - $length = $value->getSize(); |
|
1023 | + $length=$value->getSize(); |
|
1024 | 1024 | } else { |
1025 | - $length = mb_strlen((string) $value); |
|
1025 | + $length=mb_strlen((string) $value); |
|
1026 | 1026 | } |
1027 | 1027 | return $length <= $rule; |
1028 | 1028 | } |
@@ -1037,11 +1037,11 @@ discard block |
||
1037 | 1037 | protected function min($value, $rule) |
1038 | 1038 | { |
1039 | 1039 | if (is_array($value)) { |
1040 | - $length = count($value); |
|
1040 | + $length=count($value); |
|
1041 | 1041 | } elseif ($value instanceof File) { |
1042 | - $length = $value->getSize(); |
|
1042 | + $length=$value->getSize(); |
|
1043 | 1043 | } else { |
1044 | - $length = mb_strlen((string) $value); |
|
1044 | + $length=mb_strlen((string) $value); |
|
1045 | 1045 | } |
1046 | 1046 | return $length >= $rule; |
1047 | 1047 | } |
@@ -1080,15 +1080,15 @@ discard block |
||
1080 | 1080 | protected function expire($value, $rule) |
1081 | 1081 | { |
1082 | 1082 | if (is_string($rule)) { |
1083 | - $rule = explode(',', $rule); |
|
1083 | + $rule=explode(',', $rule); |
|
1084 | 1084 | } |
1085 | - list($start, $end) = $rule; |
|
1085 | + list($start, $end)=$rule; |
|
1086 | 1086 | if (!is_numeric($start)) { |
1087 | - $start = strtotime($start); |
|
1087 | + $start=strtotime($start); |
|
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | if (!is_numeric($end)) { |
1091 | - $end = strtotime($end); |
|
1091 | + $end=strtotime($end); |
|
1092 | 1092 | } |
1093 | 1093 | return $_SERVER['REQUEST_TIME'] >= $start && $_SERVER['REQUEST_TIME'] <= $end; |
1094 | 1094 | } |
@@ -1127,11 +1127,11 @@ discard block |
||
1127 | 1127 | protected function regex($value, $rule) |
1128 | 1128 | { |
1129 | 1129 | if (isset($this->regex[$rule])) { |
1130 | - $rule = $this->regex[$rule]; |
|
1130 | + $rule=$this->regex[$rule]; |
|
1131 | 1131 | } |
1132 | 1132 | if (0 !== strpos($rule, '/') && !preg_match('/\/[imsU]{0,4}$/', $rule)) { |
1133 | 1133 | // 不是正则表达式则两端补上/ |
1134 | - $rule = '/^' . $rule . '$/'; |
|
1134 | + $rule='/^'.$rule.'$/'; |
|
1135 | 1135 | } |
1136 | 1136 | return 1 === preg_match($rule, (string) $value); |
1137 | 1137 | } |
@@ -1146,7 +1146,7 @@ discard block |
||
1146 | 1146 | */ |
1147 | 1147 | protected function token($value, $rule, $data) |
1148 | 1148 | { |
1149 | - $rule = !empty($rule) ? $rule : '__token__'; |
|
1149 | + $rule=!empty($rule) ? $rule : '__token__'; |
|
1150 | 1150 | if (!isset($data[$rule]) || !Session::has($rule)) { |
1151 | 1151 | // 令牌数据无效 |
1152 | 1152 | return false; |
@@ -1180,10 +1180,10 @@ discard block |
||
1180 | 1180 | { |
1181 | 1181 | if (strpos($key, '.')) { |
1182 | 1182 | // 支持二维数组验证 |
1183 | - list($name1, $name2) = explode('.', $key); |
|
1184 | - $value = isset($data[$name1][$name2]) ? $data[$name1][$name2] : null; |
|
1183 | + list($name1, $name2)=explode('.', $key); |
|
1184 | + $value=isset($data[$name1][$name2]) ? $data[$name1][$name2] : null; |
|
1185 | 1185 | } else { |
1186 | - $value = isset($data[$key]) ? $data[$key] : null; |
|
1186 | + $value=isset($data[$key]) ? $data[$key] : null; |
|
1187 | 1187 | } |
1188 | 1188 | return $value; |
1189 | 1189 | } |
@@ -1199,30 +1199,30 @@ discard block |
||
1199 | 1199 | */ |
1200 | 1200 | protected function getRuleMsg($attribute, $title, $type, $rule) |
1201 | 1201 | { |
1202 | - if (isset($this->message[$attribute . '.' . $type])) { |
|
1203 | - $msg = $this->message[$attribute . '.' . $type]; |
|
1202 | + if (isset($this->message[$attribute.'.'.$type])) { |
|
1203 | + $msg=$this->message[$attribute.'.'.$type]; |
|
1204 | 1204 | } elseif (isset($this->message[$attribute][$type])) { |
1205 | - $msg = $this->message[$attribute][$type]; |
|
1205 | + $msg=$this->message[$attribute][$type]; |
|
1206 | 1206 | } elseif (isset($this->message[$attribute])) { |
1207 | - $msg = $this->message[$attribute]; |
|
1207 | + $msg=$this->message[$attribute]; |
|
1208 | 1208 | } elseif (isset(self::$typeMsg[$type])) { |
1209 | - $msg = self::$typeMsg[$type]; |
|
1209 | + $msg=self::$typeMsg[$type]; |
|
1210 | 1210 | } else { |
1211 | - $msg = $title . '规则错误'; |
|
1211 | + $msg=$title.'规则错误'; |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | if (is_string($msg) && 0 === strpos($msg, '{%')) { |
1215 | - $msg = Lang::get(substr($msg, 2, -1)); |
|
1215 | + $msg=Lang::get(substr($msg, 2, -1)); |
|
1216 | 1216 | } |
1217 | 1217 | |
1218 | 1218 | if (is_string($msg) && is_scalar($rule) && false !== strpos($msg, ':')) { |
1219 | 1219 | // 变量替换 |
1220 | 1220 | if (is_string($rule) && strpos($rule, ',')) { |
1221 | - $array = array_pad(explode(',', $rule), 3, ''); |
|
1221 | + $array=array_pad(explode(',', $rule), 3, ''); |
|
1222 | 1222 | } else { |
1223 | - $array = array_pad([], 3, ''); |
|
1223 | + $array=array_pad([], 3, ''); |
|
1224 | 1224 | } |
1225 | - $msg = str_replace( |
|
1225 | + $msg=str_replace( |
|
1226 | 1226 | [':attribute', ':rule', ':1', ':2', ':3'], |
1227 | 1227 | [$title, (string) $rule, $array[0], $array[1], $array[2]], |
1228 | 1228 | $msg); |
@@ -1236,32 +1236,32 @@ discard block |
||
1236 | 1236 | * @param string $scene 验证场景 |
1237 | 1237 | * @return array |
1238 | 1238 | */ |
1239 | - protected function getScene($scene = '') |
|
1239 | + protected function getScene($scene='') |
|
1240 | 1240 | { |
1241 | 1241 | if (empty($scene)) { |
1242 | 1242 | // 读取指定场景 |
1243 | - $scene = $this->currentScene; |
|
1243 | + $scene=$this->currentScene; |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | 1246 | if (!empty($scene) && isset($this->scene[$scene])) { |
1247 | 1247 | // 如果设置了验证适用场景 |
1248 | - $scene = $this->scene[$scene]; |
|
1248 | + $scene=$this->scene[$scene]; |
|
1249 | 1249 | if (is_string($scene)) { |
1250 | - $scene = explode(',', $scene); |
|
1250 | + $scene=explode(',', $scene); |
|
1251 | 1251 | } |
1252 | 1252 | } else { |
1253 | - $scene = []; |
|
1253 | + $scene=[]; |
|
1254 | 1254 | } |
1255 | 1255 | return $scene; |
1256 | 1256 | } |
1257 | 1257 | |
1258 | 1258 | public static function __callStatic($method, $params) |
1259 | 1259 | { |
1260 | - $class = self::make(); |
|
1260 | + $class=self::make(); |
|
1261 | 1261 | if (method_exists($class, $method)) { |
1262 | 1262 | return call_user_func_array([$class, $method], $params); |
1263 | 1263 | } else { |
1264 | - throw new \Exception('method not exists:' . __CLASS__ . '->' . $method); |
|
1264 | + throw new \Exception('method not exists:'.__CLASS__.'->'.$method); |
|
1265 | 1265 | } |
1266 | 1266 | } |
1267 | 1267 | } |
1268 | 1268 | \ No newline at end of file |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | namespace puck\helpers; |
10 | 10 | |
11 | 11 | use Overtrue\Pinyin\Pinyin as VendorPinyin; |
12 | -class PinYin extends VendorPinyin{ |
|
12 | +class PinYin extends VendorPinyin { |
|
13 | 13 | |
14 | 14 | public function noun($str) { |
15 | 15 | $pinyinArr=$this->convert($str); |
@@ -17,6 +17,6 @@ discard block |
||
17 | 17 | //首字母转大写 |
18 | 18 | $pinyin[0]=strtoupper($pinyin[0]); |
19 | 19 | } |
20 | - return implode('',$pinyinArr); |
|
20 | + return implode('', $pinyinArr); |
|
21 | 21 | } |
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -11,8 +11,8 @@ |
||
11 | 11 | |
12 | 12 | class Conf { |
13 | 13 | static $config=false; |
14 | - static public function load(){ |
|
15 | - if(!self::$config){ |
|
14 | + static public function load() { |
|
15 | + if (!self::$config) { |
|
16 | 16 | self::$config=Config::load(BASE_PATH.'/app/conf'); |
17 | 17 | } |
18 | 18 | return self::$config; |
@@ -9,11 +9,11 @@ |
||
9 | 9 | namespace puck; |
10 | 10 | |
11 | 11 | |
12 | -class Mysql extends \MysqliDb{ |
|
12 | +class Mysql extends \MysqliDb { |
|
13 | 13 | |
14 | - static public function getDb($db){ |
|
14 | + static public function getDb($db) { |
|
15 | 15 | static $dbList; |
16 | - if(!isset($dbList[$db])){ |
|
16 | + if (!isset($dbList[$db])) { |
|
17 | 17 | $dbList[$db]=new \MysqliDb(config('db.'.$db)); |
18 | 18 | } |
19 | 19 | return $dbList[$db]; |
@@ -58,6 +58,10 @@ |
||
58 | 58 | public function update($data){ |
59 | 59 | return $this->db->update($this->table,$data); |
60 | 60 | } |
61 | + |
|
62 | + /** |
|
63 | + * @param string $field |
|
64 | + */ |
|
61 | 65 | public function field($field){ |
62 | 66 | $this->field=$field; |
63 | 67 | return $this; |
@@ -17,57 +17,57 @@ |
||
17 | 17 | protected $limitCount=null; |
18 | 18 | public function __construct() |
19 | 19 | { |
20 | - if(!$this->dbConn){ |
|
20 | + if (!$this->dbConn) { |
|
21 | 21 | $this->dbConn='main'; |
22 | 22 | } |
23 | - $this->db = Mysql::getDb($this->dbConn); |
|
23 | + $this->db=Mysql::getDb($this->dbConn); |
|
24 | 24 | } |
25 | - public function __call($method,$arg){ |
|
25 | + public function __call($method, $arg) { |
|
26 | 26 | $ret=$this; |
27 | - if(method_exists ($this->db, $method)){ |
|
28 | - $ret=call_user_func_array(array($this->db,$method),$arg); |
|
27 | + if (method_exists($this->db, $method)) { |
|
28 | + $ret=call_user_func_array(array($this->db, $method), $arg); |
|
29 | 29 | } |
30 | - return $ret==$this->db? $this: $ret; |
|
30 | + return $ret == $this->db ? $this : $ret; |
|
31 | 31 | } |
32 | - public function __get($name){ |
|
33 | - if(property_exists($this->db, $name)){ |
|
32 | + public function __get($name) { |
|
33 | + if (property_exists($this->db, $name)) { |
|
34 | 34 | return $this->db->$name; |
35 | 35 | } |
36 | - throw new MemberAccessException('model Property ' . $name . ' not exists'); |
|
36 | + throw new MemberAccessException('model Property '.$name.' not exists'); |
|
37 | 37 | } |
38 | - public function limit($limit){ |
|
38 | + public function limit($limit) { |
|
39 | 39 | $this->limitCount=$limit; |
40 | 40 | return $this; |
41 | 41 | } |
42 | - public function find(){ |
|
43 | - return $this->db->getOne($this->table,$this->field); |
|
42 | + public function find() { |
|
43 | + return $this->db->getOne($this->table, $this->field); |
|
44 | 44 | } |
45 | - public function select(){ |
|
46 | - return $this->db->get($this->table,$this->limitCount?$this->limitCount:null,$this->field); |
|
45 | + public function select() { |
|
46 | + return $this->db->get($this->table, $this->limitCount ? $this->limitCount : null, $this->field); |
|
47 | 47 | } |
48 | - public function count(){ |
|
48 | + public function count() { |
|
49 | 49 | return $this->field("count(*) as count")->find()['count']; |
50 | 50 | } |
51 | - public function table($table){ |
|
51 | + public function table($table) { |
|
52 | 52 | $this->table=$table; |
53 | 53 | return $this; |
54 | 54 | } |
55 | - public function add($data){ |
|
56 | - return $this->db->insert($this->table,$data); |
|
55 | + public function add($data) { |
|
56 | + return $this->db->insert($this->table, $data); |
|
57 | 57 | } |
58 | - public function update($data){ |
|
59 | - return $this->db->update($this->table,$data); |
|
58 | + public function update($data) { |
|
59 | + return $this->db->update($this->table, $data); |
|
60 | 60 | } |
61 | - public function field($field){ |
|
61 | + public function field($field) { |
|
62 | 62 | $this->field=$field; |
63 | 63 | return $this; |
64 | 64 | } |
65 | - public function delete(){ |
|
65 | + public function delete() { |
|
66 | 66 | return $this->db->delete($this->table); |
67 | 67 | } |
68 | - public function page($page,$pageLimit='10'){ |
|
68 | + public function page($page, $pageLimit='10') { |
|
69 | 69 | $this->db->pageLimit=$pageLimit; |
70 | - $info= $this->db->paginate($this->table,$page); |
|
70 | + $info=$this->db->paginate($this->table, $page); |
|
71 | 71 | return $info; |
72 | 72 | } |
73 | 73 | } |
74 | 74 | \ No newline at end of file |