@@ -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 | } |
@@ -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; |
@@ -2,15 +2,15 @@ |
||
| 2 | 2 | @ini_set('date.timezone', 'Asia/Shanghai'); |
| 3 | 3 | @header('content-type:text/html;charset=utf-8'); |
| 4 | 4 | |
| 5 | -define('EXPORT_PATH',__DIR__); |
|
| 6 | -define('PUCK_VER','1.0.17'); |
|
| 7 | -define('IS_CLI',php_sapi_name()=='cli'); |
|
| 8 | -if(DEBUG){ |
|
| 5 | +define('EXPORT_PATH', __DIR__); |
|
| 6 | +define('PUCK_VER', '1.0.17'); |
|
| 7 | +define('IS_CLI', php_sapi_name() == 'cli'); |
|
| 8 | +if (DEBUG) { |
|
| 9 | 9 | error_reporting(E_ALL); |
| 10 | 10 | @ini_set('display_errors', 'On'); |
| 11 | 11 | @ob_start(); |
| 12 | - $whoops = new \Whoops\Run; |
|
| 13 | - $handle=IS_CLI?"PlainTextHandler":"PrettyPageHandler"; |
|
| 12 | + $whoops=new \Whoops\Run; |
|
| 13 | + $handle=IS_CLI ? "PlainTextHandler" : "PrettyPageHandler"; |
|
| 14 | 14 | $handle="\\Whoops\\Handler\\".$handle; |
| 15 | 15 | $whoops->pushHandler(new $handle); |
| 16 | 16 | $whoops->register(); |