@@ -40,8 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | if (isset($arr['status']) && $type == 2) { |
| 42 | 42 | $ret=$arr; |
| 43 | - } |
|
| 44 | - else { |
|
| 43 | + } else { |
|
| 45 | 44 | $ret['status']=$type; |
| 46 | 45 | $ret['data']=$arr; |
| 47 | 46 | } |
@@ -323,8 +322,7 @@ discard block |
||
| 323 | 322 | if ($filters) { |
| 324 | 323 | if (is_string($filters)) { |
| 325 | 324 | $filters=explode(',', $filters); |
| 326 | - } |
|
| 327 | - else if (is_array($filters)) { |
|
| 325 | + } else if (is_array($filters)) { |
|
| 328 | 326 | foreach ($filters as $filter) { |
| 329 | 327 | $data=array_map_recursive($filter, $data); // 参数过滤 |
| 330 | 328 | } |
@@ -462,7 +462,7 @@ |
||
| 462 | 462 | * 获取环境变量 |
| 463 | 463 | * |
| 464 | 464 | * @param string $key |
| 465 | - * @param mixed $default |
|
| 465 | + * @param string|false $default |
|
| 466 | 466 | * @return mixed |
| 467 | 467 | */ |
| 468 | 468 | function env($key, $default = null) |
@@ -408,7 +408,7 @@ 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 | 414 | /** |
@@ -416,15 +416,15 @@ discard block |
||
| 416 | 416 | * |
| 417 | 417 | * @return string|null |
| 418 | 418 | */ |
| 419 | -function config($name=null,$value=null,$default=null){ |
|
| 419 | +function config($name=null, $value=null, $default=null) { |
|
| 420 | 420 | $config=\puck\Conf::load(); |
| 421 | - if ($name===null){ |
|
| 421 | + if ($name === null) { |
|
| 422 | 422 | return $config->all(); |
| 423 | 423 | } |
| 424 | - if ($value===null){ |
|
| 425 | - return $config->get($name,$default); |
|
| 424 | + if ($value === null) { |
|
| 425 | + return $config->get($name, $default); |
|
| 426 | 426 | } |
| 427 | - $config->set($name,$value); |
|
| 427 | + $config->set($name, $value); |
|
| 428 | 428 | } |
| 429 | 429 | /** |
| 430 | 430 | * 字符串命名风格转换 |
@@ -441,14 +441,14 @@ discard block |
||
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | -if (! function_exists('app')) { |
|
| 444 | +if (!function_exists('app')) { |
|
| 445 | 445 | /** |
| 446 | 446 | * 获取容器实例 |
| 447 | 447 | * |
| 448 | 448 | * @param string $make |
| 449 | 449 | * @return mixed|\puck\App |
| 450 | 450 | */ |
| 451 | - function app($make = null) |
|
| 451 | + function app($make=null) |
|
| 452 | 452 | { |
| 453 | 453 | if (is_null($make)) { |
| 454 | 454 | return Container::getInstance(); |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | -if (! function_exists('env')) { |
|
| 460 | +if (!function_exists('env')) { |
|
| 461 | 461 | /** |
| 462 | 462 | * 获取环境变量 |
| 463 | 463 | * |
@@ -465,9 +465,9 @@ discard block |
||
| 465 | 465 | * @param mixed $default |
| 466 | 466 | * @return mixed |
| 467 | 467 | */ |
| 468 | - function env($key, $default = null) |
|
| 468 | + function env($key, $default=null) |
|
| 469 | 469 | { |
| 470 | - $value = getenv($key); |
|
| 470 | + $value=getenv($key); |
|
| 471 | 471 | if ($value === false) { |
| 472 | 472 | return value($default); |
| 473 | 473 | } |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | return $value; |
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | -if (! function_exists('value')) { |
|
| 494 | +if (!function_exists('value')) { |
|
| 495 | 495 | /** |
| 496 | 496 | * 返回给定的表达式的结果 |
| 497 | 497 | * |
@@ -1,199 +1,199 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace puck\helpers; |
| 3 | 3 | class Chaos { |
| 4 | - public $GbToBigArray; |
|
| 5 | - public $_pinyin; |
|
| 6 | - public $string; |
|
| 7 | - public $url=''; |
|
| 8 | - public $msg=''; |
|
| 9 | - public $action; |
|
| 10 | - private $prefix; |
|
| 4 | + public $GbToBigArray; |
|
| 5 | + public $_pinyin; |
|
| 6 | + public $string; |
|
| 7 | + public $url=''; |
|
| 8 | + public $msg=''; |
|
| 9 | + public $action; |
|
| 10 | + private $prefix; |
|
| 11 | 11 | |
| 12 | 12 | function __construct() { |
| 13 | - $this->_pinyin=new PinYin(); |
|
| 14 | - } |
|
| 13 | + $this->_pinyin=new PinYin(); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * @param array $prefix |
| 18 | 18 | */ |
| 19 | 19 | public function addPrefix(array $prefix) { |
| 20 | 20 | $this->prefix=$prefix[array_rand($prefix)]; |
| 21 | - } |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | public function clearPrefix() { |
| 24 | 24 | $this->prefix=''; |
| 25 | - } |
|
| 25 | + } |
|
| 26 | 26 | public function get($str) { |
| 27 | 27 | $this->cutting($str); |
| 28 | 28 | $this->convert(); |
| 29 | 29 | $this->clearPrefix(); |
| 30 | 30 | return $this->msg; |
| 31 | - } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - //分离URL |
|
| 34 | - private function cutting($str) { |
|
| 33 | + //分离URL |
|
| 34 | + private function cutting($str) { |
|
| 35 | 35 | |
| 36 | - if (preg_match("@(http://[^\\s]+)@i", $str, $result)) { |
|
| 37 | - $this->url=$result[1]; |
|
| 38 | - $this->msg=$str=str_replace($this->url, '%%%%', $str); |
|
| 39 | - } else { |
|
| 40 | - $this->msg=$str; |
|
| 41 | - } |
|
| 42 | - } |
|
| 36 | + if (preg_match("@(http://[^\\s]+)@i", $str, $result)) { |
|
| 37 | + $this->url=$result[1]; |
|
| 38 | + $this->msg=$str=str_replace($this->url, '%%%%', $str); |
|
| 39 | + } else { |
|
| 40 | + $this->msg=$str; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | |
| 46 | - private function convert($method='msg') { |
|
| 47 | - if ($method == 'msg' || $method == 'all') { |
|
| 48 | - $this->msg=$this->setPinyin($this->msg); |
|
| 49 | - $this->msg=$this->setRepeat($this->msg); |
|
| 50 | - //$this->msg = $this->GbToBig($this->msg); |
|
| 51 | - $this->msg=$this->setBlankness($this->msg); |
|
| 46 | + private function convert($method='msg') { |
|
| 47 | + if ($method == 'msg' || $method == 'all') { |
|
| 48 | + $this->msg=$this->setPinyin($this->msg); |
|
| 49 | + $this->msg=$this->setRepeat($this->msg); |
|
| 50 | + //$this->msg = $this->GbToBig($this->msg); |
|
| 51 | + $this->msg=$this->setBlankness($this->msg); |
|
| 52 | 52 | |
| 53 | - } |
|
| 54 | - if ($method == 'url' || $method == 'all') { |
|
| 55 | - $this->url=$this->setChacha($this->url); |
|
| 56 | - } |
|
| 57 | - $this->msg=$this->prefix.str_replace('%%%%', $this->url, $this->msg); |
|
| 58 | - } |
|
| 53 | + } |
|
| 54 | + if ($method == 'url' || $method == 'all') { |
|
| 55 | + $this->url=$this->setChacha($this->url); |
|
| 56 | + } |
|
| 57 | + $this->msg=$this->prefix.str_replace('%%%%', $this->url, $this->msg); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param string $url |
|
| 62 | - */ |
|
| 63 | - function setChacha($url) { |
|
| 64 | - $url=strtolower($url); |
|
| 65 | - $arr=array( |
|
| 66 | - 'a' => array('a', 'A', 'a', 'A', 'Α', 'А', 'α'), |
|
| 67 | - 'b' => array('b', 'B', 'b', 'B', 'Β', 'В', 'Ь'), |
|
| 68 | - 'c' => array('c', 'C', 'c', 'C', 'С', 'с'), |
|
| 69 | - 'd' => array('d', 'D', 'd', 'D'), |
|
| 70 | - 'e' => array('e', 'E', 'e', 'E', 'Ε', 'Е', 'е'), |
|
| 71 | - 'f' => array('f', 'F', 'f', 'F'), |
|
| 72 | - 'g' => array('g', 'G', 'g', 'G'), |
|
| 73 | - 'h' => array('h', 'H', 'h', 'H', 'Η', 'Н', 'н'), |
|
| 74 | - 'i' => array('i', 'I', 'i', 'I', 'Ι', 'Ⅰ'), |
|
| 75 | - 'j' => array('j', 'J', 'j', 'J'), |
|
| 76 | - 'k' => array('k', 'K', 'k', 'K', 'Κ', 'κ', 'к', 'К'), |
|
| 77 | - 'l' => array('l', 'L', 'l', 'L', '︱', '︳', '|'), |
|
| 78 | - 'm' => array('m', 'M', 'm', 'M', 'Μ', 'М', 'м'), |
|
| 79 | - 'n' => array('n', 'N', 'n', 'N', 'Ν', '∩'), |
|
| 80 | - 'o' => array('o', 'O', 'o', 'O', 'Ο', 'О'), |
|
| 81 | - 'p' => array('p', 'P', 'p', 'P', 'Ρ', 'Р', 'р'), |
|
| 82 | - 'q' => array('q', 'Q', 'q', 'Q'), |
|
| 83 | - 'r' => array('r', 'R', 'r', 'R'), |
|
| 84 | - 's' => array('s', 'S', 's', 'S'), |
|
| 85 | - 't' => array('t', 'T', 't', 'T', 'Τ', 'Т', 'ㄒ'), |
|
| 86 | - 'u' => array('u', 'U', 'u', 'U', '∪'), |
|
| 87 | - 'v' => array('v', 'V', 'v', 'V', '∨', 'ν'), |
|
| 88 | - 'w' => array('w', 'W', 'w', 'W'), |
|
| 89 | - 'x' => array('x', 'X', 'x', 'X', 'Χ', 'χ', 'Х', 'х', 'Ⅹ', '×'), |
|
| 90 | - 'y' => array('y', 'Y', 'y', 'Y', 'У'), |
|
| 91 | - 'z' => array('z', 'Z', 'z', 'Z', 'Ζ'), |
|
| 60 | + /** |
|
| 61 | + * @param string $url |
|
| 62 | + */ |
|
| 63 | + function setChacha($url) { |
|
| 64 | + $url=strtolower($url); |
|
| 65 | + $arr=array( |
|
| 66 | + 'a' => array('a', 'A', 'a', 'A', 'Α', 'А', 'α'), |
|
| 67 | + 'b' => array('b', 'B', 'b', 'B', 'Β', 'В', 'Ь'), |
|
| 68 | + 'c' => array('c', 'C', 'c', 'C', 'С', 'с'), |
|
| 69 | + 'd' => array('d', 'D', 'd', 'D'), |
|
| 70 | + 'e' => array('e', 'E', 'e', 'E', 'Ε', 'Е', 'е'), |
|
| 71 | + 'f' => array('f', 'F', 'f', 'F'), |
|
| 72 | + 'g' => array('g', 'G', 'g', 'G'), |
|
| 73 | + 'h' => array('h', 'H', 'h', 'H', 'Η', 'Н', 'н'), |
|
| 74 | + 'i' => array('i', 'I', 'i', 'I', 'Ι', 'Ⅰ'), |
|
| 75 | + 'j' => array('j', 'J', 'j', 'J'), |
|
| 76 | + 'k' => array('k', 'K', 'k', 'K', 'Κ', 'κ', 'к', 'К'), |
|
| 77 | + 'l' => array('l', 'L', 'l', 'L', '︱', '︳', '|'), |
|
| 78 | + 'm' => array('m', 'M', 'm', 'M', 'Μ', 'М', 'м'), |
|
| 79 | + 'n' => array('n', 'N', 'n', 'N', 'Ν', '∩'), |
|
| 80 | + 'o' => array('o', 'O', 'o', 'O', 'Ο', 'О'), |
|
| 81 | + 'p' => array('p', 'P', 'p', 'P', 'Ρ', 'Р', 'р'), |
|
| 82 | + 'q' => array('q', 'Q', 'q', 'Q'), |
|
| 83 | + 'r' => array('r', 'R', 'r', 'R'), |
|
| 84 | + 's' => array('s', 'S', 's', 'S'), |
|
| 85 | + 't' => array('t', 'T', 't', 'T', 'Τ', 'Т', 'ㄒ'), |
|
| 86 | + 'u' => array('u', 'U', 'u', 'U', '∪'), |
|
| 87 | + 'v' => array('v', 'V', 'v', 'V', '∨', 'ν'), |
|
| 88 | + 'w' => array('w', 'W', 'w', 'W'), |
|
| 89 | + 'x' => array('x', 'X', 'x', 'X', 'Χ', 'χ', 'Х', 'х', 'Ⅹ', '×'), |
|
| 90 | + 'y' => array('y', 'Y', 'y', 'Y', 'У'), |
|
| 91 | + 'z' => array('z', 'Z', 'z', 'Z', 'Ζ'), |
|
| 92 | 92 | |
| 93 | - '1' => array('1', '1'), |
|
| 94 | - '2' => array('2', '2'), |
|
| 95 | - '3' => array('3', '3'), |
|
| 96 | - '4' => array('4', '4'), |
|
| 97 | - '5' => array('5', '5'), |
|
| 98 | - '6' => array('6', '6'), |
|
| 99 | - '7' => array('7', '7'), |
|
| 100 | - '8' => array('8', '8'), |
|
| 101 | - '9' => array('9', '9'), |
|
| 102 | - '0' => array('0', '0'), |
|
| 93 | + '1' => array('1', '1'), |
|
| 94 | + '2' => array('2', '2'), |
|
| 95 | + '3' => array('3', '3'), |
|
| 96 | + '4' => array('4', '4'), |
|
| 97 | + '5' => array('5', '5'), |
|
| 98 | + '6' => array('6', '6'), |
|
| 99 | + '7' => array('7', '7'), |
|
| 100 | + '8' => array('8', '8'), |
|
| 101 | + '9' => array('9', '9'), |
|
| 102 | + '0' => array('0', '0'), |
|
| 103 | 103 | |
| 104 | - ':' => array(':', ':', '∶'), |
|
| 105 | - '/' => array('/', '/'), |
|
| 106 | - '.' => array('。', '·', '.', '、', '﹒', ',', '丶') |
|
| 104 | + ':' => array(':', ':', '∶'), |
|
| 105 | + '/' => array('/', '/'), |
|
| 106 | + '.' => array('。', '·', '.', '、', '﹒', ',', '丶') |
|
| 107 | 107 | |
| 108 | - ); |
|
| 109 | - $len=strlen($url); |
|
| 110 | - $temp="\n\n"; |
|
| 111 | - for ($i=0; $i < $len; $i++) { |
|
| 112 | - $t_str=substr($url, $i, 1); |
|
| 113 | - $sj=mt_rand(0, count($arr[$t_str]) - 1); |
|
| 114 | - $temp.=$arr[$t_str][$sj]; |
|
| 115 | - } |
|
| 116 | - return $temp; |
|
| 117 | - } |
|
| 108 | + ); |
|
| 109 | + $len=strlen($url); |
|
| 110 | + $temp="\n\n"; |
|
| 111 | + for ($i=0; $i < $len; $i++) { |
|
| 112 | + $t_str=substr($url, $i, 1); |
|
| 113 | + $sj=mt_rand(0, count($arr[$t_str]) - 1); |
|
| 114 | + $temp.=$arr[$t_str][$sj]; |
|
| 115 | + } |
|
| 116 | + return $temp; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - //随机把一个字符转为拼音 |
|
| 119 | + //随机把一个字符转为拼音 |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * @param string $str |
|
| 123 | - */ |
|
| 124 | - function setPinyin($str) { |
|
| 125 | - $py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1); |
|
| 126 | - $t_str = iconv_substr( $str, $py, 1, 'UTF-8'); |
|
| 127 | - if(mt_rand(0,10) > 5) { |
|
| 128 | - $pinyin = " "; |
|
| 129 | - } |
|
| 130 | - $pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE); |
|
| 121 | + /** |
|
| 122 | + * @param string $str |
|
| 123 | + */ |
|
| 124 | + function setPinyin($str) { |
|
| 125 | + $py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1); |
|
| 126 | + $t_str = iconv_substr( $str, $py, 1, 'UTF-8'); |
|
| 127 | + if(mt_rand(0,10) > 5) { |
|
| 128 | + $pinyin = " "; |
|
| 129 | + } |
|
| 130 | + $pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE); |
|
| 131 | 131 | $pinyin=implode(" ",$pinyin); |
| 132 | - if(mt_rand(0,10) > 5) { |
|
| 133 | - $pinyin .= " "; |
|
| 134 | - } |
|
| 135 | - if($t_str != "%"){ |
|
| 136 | - $str = preg_replace("'$t_str'", $pinyin, $str, 1); |
|
| 137 | - } |
|
| 138 | - return $str; |
|
| 139 | - } |
|
| 132 | + if(mt_rand(0,10) > 5) { |
|
| 133 | + $pinyin .= " "; |
|
| 134 | + } |
|
| 135 | + if($t_str != "%"){ |
|
| 136 | + $str = preg_replace("'$t_str'", $pinyin, $str, 1); |
|
| 137 | + } |
|
| 138 | + return $str; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - //随机重复一个字符 |
|
| 141 | + //随机重复一个字符 |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * @param string $str |
|
| 145 | - */ |
|
| 146 | - function setRepeat($str) { |
|
| 147 | - $len = iconv_strlen( $str, 'UTF-8' ); |
|
| 148 | - $action = 0; |
|
| 149 | - $temp = ''; |
|
| 150 | - for( $i=0; $i<$len; $i++ ){ |
|
| 151 | - $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
| 152 | - if( mt_rand( 1, 50 ) > 48 && $action == 0) { |
|
| 153 | - if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
| 154 | - $temp .= $t_str; |
|
| 155 | - $action = 1; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - $temp .= $t_str; |
|
| 159 | - } |
|
| 160 | - return $temp; |
|
| 161 | - } |
|
| 143 | + /** |
|
| 144 | + * @param string $str |
|
| 145 | + */ |
|
| 146 | + function setRepeat($str) { |
|
| 147 | + $len = iconv_strlen( $str, 'UTF-8' ); |
|
| 148 | + $action = 0; |
|
| 149 | + $temp = ''; |
|
| 150 | + for( $i=0; $i<$len; $i++ ){ |
|
| 151 | + $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
| 152 | + if( mt_rand( 1, 50 ) > 48 && $action == 0) { |
|
| 153 | + if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
| 154 | + $temp .= $t_str; |
|
| 155 | + $action = 1; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + $temp .= $t_str; |
|
| 159 | + } |
|
| 160 | + return $temp; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - //随机插入不影响阅读的字符 |
|
| 163 | + //随机插入不影响阅读的字符 |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * @param string $str |
|
| 167 | - */ |
|
| 168 | - function setBlankness($str) { |
|
| 169 | - $blankness=array(" ", ' ', '҉', '̅̅', '̲', '̲̲', '̅', '̲̲̅̅'); |
|
| 170 | - $len=iconv_strlen($str, 'UTF-8'); |
|
| 171 | - $temp=''; |
|
| 172 | - for ($i=0; $i < $len; $i++) { |
|
| 173 | - $t_str=iconv_substr($str, $i, 1, 'UTF-8'); |
|
| 174 | - if (mt_rand(1, 50) > 48) { |
|
| 175 | - if (!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
| 176 | - $temp.=$blankness[mt_rand(0, 7)]; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $temp.=$t_str; |
|
| 180 | - } |
|
| 181 | - return $temp; |
|
| 182 | - } |
|
| 165 | + /** |
|
| 166 | + * @param string $str |
|
| 167 | + */ |
|
| 168 | + function setBlankness($str) { |
|
| 169 | + $blankness=array(" ", ' ', '҉', '̅̅', '̲', '̲̲', '̅', '̲̲̅̅'); |
|
| 170 | + $len=iconv_strlen($str, 'UTF-8'); |
|
| 171 | + $temp=''; |
|
| 172 | + for ($i=0; $i < $len; $i++) { |
|
| 173 | + $t_str=iconv_substr($str, $i, 1, 'UTF-8'); |
|
| 174 | + if (mt_rand(1, 50) > 48) { |
|
| 175 | + if (!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
| 176 | + $temp.=$blankness[mt_rand(0, 7)]; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $temp.=$t_str; |
|
| 180 | + } |
|
| 181 | + return $temp; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - //随机进行繁体中文转换 |
|
| 185 | - function GbToBig($str) { |
|
| 186 | - $len=iconv_strlen($str, 'UTF-8'); |
|
| 187 | - $temp=''; |
|
| 188 | - for ($i=0; $i < $len; $i++) { |
|
| 189 | - $t_str=iconv_substr($str, $i, 1, 'UTF-8'); |
|
| 190 | - if (mt_rand(1, 50) > 48) { |
|
| 191 | - $t_str=strtr($t_str, $this->GbToBigArray); |
|
| 192 | - } |
|
| 193 | - $temp.=$t_str; |
|
| 194 | - } |
|
| 195 | - return $temp; |
|
| 196 | - } |
|
| 184 | + //随机进行繁体中文转换 |
|
| 185 | + function GbToBig($str) { |
|
| 186 | + $len=iconv_strlen($str, 'UTF-8'); |
|
| 187 | + $temp=''; |
|
| 188 | + for ($i=0; $i < $len; $i++) { |
|
| 189 | + $t_str=iconv_substr($str, $i, 1, 'UTF-8'); |
|
| 190 | + if (mt_rand(1, 50) > 48) { |
|
| 191 | + $t_str=strtr($t_str, $this->GbToBigArray); |
|
| 192 | + } |
|
| 193 | + $temp.=$t_str; |
|
| 194 | + } |
|
| 195 | + return $temp; |
|
| 196 | + } |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -122,18 +122,18 @@ discard block |
||
| 122 | 122 | * @param string $str |
| 123 | 123 | */ |
| 124 | 124 | function setPinyin($str) { |
| 125 | - $py = mt_rand(0, iconv_strlen( $str, 'UTF-8' )-1); |
|
| 126 | - $t_str = iconv_substr( $str, $py, 1, 'UTF-8'); |
|
| 127 | - if(mt_rand(0,10) > 5) { |
|
| 128 | - $pinyin = " "; |
|
| 125 | + $py=mt_rand(0, iconv_strlen($str, 'UTF-8') - 1); |
|
| 126 | + $t_str=iconv_substr($str, $py, 1, 'UTF-8'); |
|
| 127 | + if (mt_rand(0, 10) > 5) { |
|
| 128 | + $pinyin=" "; |
|
| 129 | 129 | } |
| 130 | - $pinyin = $this->_pinyin->convert($t_str,PINYIN_UNICODE); |
|
| 131 | - $pinyin=implode(" ",$pinyin); |
|
| 132 | - if(mt_rand(0,10) > 5) { |
|
| 133 | - $pinyin .= " "; |
|
| 130 | + $pinyin=$this->_pinyin->convert($t_str, PINYIN_UNICODE); |
|
| 131 | + $pinyin=implode(" ", $pinyin); |
|
| 132 | + if (mt_rand(0, 10) > 5) { |
|
| 133 | + $pinyin.=" "; |
|
| 134 | 134 | } |
| 135 | - if($t_str != "%"){ |
|
| 136 | - $str = preg_replace("'$t_str'", $pinyin, $str, 1); |
|
| 135 | + if ($t_str != "%") { |
|
| 136 | + $str=preg_replace("'$t_str'", $pinyin, $str, 1); |
|
| 137 | 137 | } |
| 138 | 138 | return $str; |
| 139 | 139 | } |
@@ -144,18 +144,18 @@ discard block |
||
| 144 | 144 | * @param string $str |
| 145 | 145 | */ |
| 146 | 146 | function setRepeat($str) { |
| 147 | - $len = iconv_strlen( $str, 'UTF-8' ); |
|
| 148 | - $action = 0; |
|
| 149 | - $temp = ''; |
|
| 150 | - for( $i=0; $i<$len; $i++ ){ |
|
| 151 | - $t_str = iconv_substr( $str, $i, 1 ,'UTF-8'); |
|
| 152 | - if( mt_rand( 1, 50 ) > 48 && $action == 0) { |
|
| 153 | - if(!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
| 154 | - $temp .= $t_str; |
|
| 155 | - $action = 1; |
|
| 147 | + $len=iconv_strlen($str, 'UTF-8'); |
|
| 148 | + $action=0; |
|
| 149 | + $temp=''; |
|
| 150 | + for ($i=0; $i < $len; $i++) { |
|
| 151 | + $t_str=iconv_substr($str, $i, 1, 'UTF-8'); |
|
| 152 | + if (mt_rand(1, 50) > 48 && $action == 0) { |
|
| 153 | + if (!preg_match("@[a-z0-9%\\s]+@i", $t_str)) { |
|
| 154 | + $temp.=$t_str; |
|
| 155 | + $action=1; |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | - $temp .= $t_str; |
|
| 158 | + $temp.=$t_str; |
|
| 159 | 159 | } |
| 160 | 160 | return $temp; |
| 161 | 161 | } |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | /** |
| 53 | 53 | * Set a given configuration value. |
| 54 | 54 | * |
| 55 | - * @param array|string $key |
|
| 55 | + * @param string $key |
|
| 56 | 56 | * @param mixed $value |
| 57 | 57 | * @return void |
| 58 | 58 | */ |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * |
| 14 | 14 | * @var array |
| 15 | 15 | */ |
| 16 | - protected $items = []; |
|
| 16 | + protected $items=[]; |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Create a new configuration repository. |
@@ -21,9 +21,9 @@ discard block |
||
| 21 | 21 | * @param array $items |
| 22 | 22 | * @return void |
| 23 | 23 | */ |
| 24 | - public function __construct(array $items = []) |
|
| 24 | + public function __construct(array $items=[]) |
|
| 25 | 25 | { |
| 26 | - $this->items = $items; |
|
| 26 | + $this->items=$items; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param mixed $default |
| 45 | 45 | * @return mixed |
| 46 | 46 | */ |
| 47 | - public function get($key, $default = null) |
|
| 47 | + public function get($key, $default=null) |
|
| 48 | 48 | { |
| 49 | 49 | return Arr::get($this->items, $key, $default); |
| 50 | 50 | } |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | * @param mixed $value |
| 57 | 57 | * @return void |
| 58 | 58 | */ |
| 59 | - public function set($key, $value = null) |
|
| 59 | + public function set($key, $value=null) |
|
| 60 | 60 | { |
| 61 | - $keys = is_array($key) ? $key : [$key => $value]; |
|
| 61 | + $keys=is_array($key) ? $key : [$key => $value]; |
|
| 62 | 62 | |
| 63 | 63 | foreach ($keys as $key => $value) { |
| 64 | 64 | Arr::set($this->items, $key, $value); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function prepend($key, $value) |
| 76 | 76 | { |
| 77 | - $array = $this->get($key); |
|
| 77 | + $array=$this->get($key); |
|
| 78 | 78 | |
| 79 | 79 | array_unshift($array, $value); |
| 80 | 80 | |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function push($key, $value) |
| 92 | 92 | { |
| 93 | - $array = $this->get($key); |
|
| 93 | + $array=$this->get($key); |
|
| 94 | 94 | |
| 95 | - $array[] = $value; |
|
| 95 | + $array[]=$value; |
|
| 96 | 96 | |
| 97 | 97 | $this->set($key, $array); |
| 98 | 98 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param array $files |
| 171 | 171 | * @param array $server |
| 172 | 172 | * @param string $content |
| 173 | - * @return \think\Request |
|
| 173 | + * @return Request |
|
| 174 | 174 | */ |
| 175 | 175 | public function create($uri, $method = 'GET', $params = [], $cookie = [], $files = [], $server = [], $content = null) |
| 176 | 176 | { |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | /** |
| 613 | 613 | * 设置获取获取路由参数 |
| 614 | 614 | * @access public |
| 615 | - * @param string|array $name 变量名 |
|
| 615 | + * @param boolean $name 变量名 |
|
| 616 | 616 | * @param mixed $default 默认值 |
| 617 | 617 | * @param string|array $filter 过滤方法 |
| 618 | 618 | * @return mixed |
@@ -629,7 +629,7 @@ discard block |
||
| 629 | 629 | /** |
| 630 | 630 | * 设置获取获取GET参数 |
| 631 | 631 | * @access public |
| 632 | - * @param string|array $name 变量名 |
|
| 632 | + * @param boolean $name 变量名 |
|
| 633 | 633 | * @param mixed $default 默认值 |
| 634 | 634 | * @param string|array $filter 过滤方法 |
| 635 | 635 | * @return mixed |
@@ -783,9 +783,9 @@ discard block |
||
| 783 | 783 | /** |
| 784 | 784 | * 获取server参数 |
| 785 | 785 | * @access public |
| 786 | - * @param string|array $name 数据名称 |
|
| 786 | + * @param string $name 数据名称 |
|
| 787 | 787 | * @param string $default 默认值 |
| 788 | - * @param string|array $filter 过滤方法 |
|
| 788 | + * @param string $filter 过滤方法 |
|
| 789 | 789 | * @return mixed |
| 790 | 790 | */ |
| 791 | 791 | public function server($name = '', $default = null, $filter = '') |
@@ -1086,7 +1086,7 @@ discard block |
||
| 1086 | 1086 | * @param string $name 变量名 |
| 1087 | 1087 | * @param string $type 变量类型 |
| 1088 | 1088 | * @param bool $checkEmpty 是否检测空值 |
| 1089 | - * @return mixed |
|
| 1089 | + * @return boolean |
|
| 1090 | 1090 | */ |
| 1091 | 1091 | public function has($name, $type = 'param', $checkEmpty = false) |
| 1092 | 1092 | { |
@@ -51,12 +51,12 @@ discard block |
||
| 51 | 51 | /** |
| 52 | 52 | * @var array 当前路由信息 |
| 53 | 53 | */ |
| 54 | - protected $routeInfo = []; |
|
| 54 | + protected $routeInfo=[]; |
|
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * @var array 当前调度信息 |
| 58 | 58 | */ |
| 59 | - protected $dispatch = []; |
|
| 59 | + protected $dispatch=[]; |
|
| 60 | 60 | protected $module; |
| 61 | 61 | protected $controller; |
| 62 | 62 | protected $action; |
@@ -66,22 +66,22 @@ discard block |
||
| 66 | 66 | /** |
| 67 | 67 | * @var array 请求参数 |
| 68 | 68 | */ |
| 69 | - protected $param = []; |
|
| 70 | - protected $get = []; |
|
| 71 | - protected $post = []; |
|
| 72 | - protected $request = []; |
|
| 73 | - protected $route = []; |
|
| 69 | + protected $param=[]; |
|
| 70 | + protected $get=[]; |
|
| 71 | + protected $post=[]; |
|
| 72 | + protected $request=[]; |
|
| 73 | + protected $route=[]; |
|
| 74 | 74 | protected $put; |
| 75 | - protected $session = []; |
|
| 76 | - protected $file = []; |
|
| 77 | - protected $cookie = []; |
|
| 78 | - protected $server = []; |
|
| 79 | - protected $header = []; |
|
| 75 | + protected $session=[]; |
|
| 76 | + protected $file=[]; |
|
| 77 | + protected $cookie=[]; |
|
| 78 | + protected $server=[]; |
|
| 79 | + protected $header=[]; |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * @var array 资源类型 |
| 83 | 83 | */ |
| 84 | - protected $mimeType = [ |
|
| 84 | + protected $mimeType=[ |
|
| 85 | 85 | 'xml' => 'application/xml,text/xml,application/x-xml', |
| 86 | 86 | 'json' => 'application/json,text/x-json,application/jsonrequest,text/json', |
| 87 | 87 | 'js' => 'text/javascript,application/javascript,application/x-javascript', |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | // 全局过滤规则 |
| 104 | 104 | protected $filter; |
| 105 | 105 | // Hook扩展方法 |
| 106 | - protected static $hook = []; |
|
| 106 | + protected static $hook=[]; |
|
| 107 | 107 | // 绑定的属性 |
| 108 | - protected $bind = []; |
|
| 108 | + protected $bind=[]; |
|
| 109 | 109 | // php://input |
| 110 | 110 | protected $input; |
| 111 | 111 | // 请求缓存 |
@@ -118,20 +118,20 @@ discard block |
||
| 118 | 118 | * @access public |
| 119 | 119 | * @param array $options 参数 |
| 120 | 120 | */ |
| 121 | - public function __construct(Config $config, $options = []) |
|
| 121 | + public function __construct(Config $config, $options=[]) |
|
| 122 | 122 | { |
| 123 | 123 | $this->server(); |
| 124 | 124 | foreach ($options as $name => $item) { |
| 125 | 125 | if (property_exists($this, $name)) { |
| 126 | - $this->$name = $item; |
|
| 126 | + $this->$name=$item; |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | - $this->config = $config; |
|
| 129 | + $this->config=$config; |
|
| 130 | 130 | if (is_null($this->filter)) { |
| 131 | - $this->filter = $this->config->get('default_filter'); |
|
| 131 | + $this->filter=$this->config->get('default_filter'); |
|
| 132 | 132 | } |
| 133 | 133 | // 保存 php://input |
| 134 | - $this->input = file_get_contents('php://input'); |
|
| 134 | + $this->input=file_get_contents('php://input'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | public function __call($method, $args) |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | array_unshift($args, $this); |
| 141 | 141 | return call_user_func_array($this->hook[$method], $args); |
| 142 | 142 | } else { |
| 143 | - throw new Exception('method not exists:' . __CLASS__ . '->' . $method); |
|
| 143 | + throw new Exception('method not exists:'.__CLASS__.'->'.$method); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
@@ -151,12 +151,12 @@ discard block |
||
| 151 | 151 | * @param mixed $callback callable |
| 152 | 152 | * @return void |
| 153 | 153 | */ |
| 154 | - public function hook($method, $callback = null) |
|
| 154 | + public function hook($method, $callback=null) |
|
| 155 | 155 | { |
| 156 | 156 | if (is_array($method)) { |
| 157 | - $this->hook = array_merge($this->hook, $method); |
|
| 157 | + $this->hook=array_merge($this->hook, $method); |
|
| 158 | 158 | } else { |
| 159 | - $this->hook[$method] = $callback; |
|
| 159 | + $this->hook[$method]=$callback; |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
@@ -172,72 +172,72 @@ discard block |
||
| 172 | 172 | * @param string $content |
| 173 | 173 | * @return \think\Request |
| 174 | 174 | */ |
| 175 | - public function create($uri, $method = 'GET', $params = [], $cookie = [], $files = [], $server = [], $content = null) |
|
| 175 | + public function create($uri, $method='GET', $params=[], $cookie=[], $files=[], $server=[], $content=null) |
|
| 176 | 176 | { |
| 177 | - $server['PATH_INFO'] = ''; |
|
| 178 | - $server['REQUEST_METHOD'] = strtoupper($method); |
|
| 179 | - $info = parse_url($uri); |
|
| 177 | + $server['PATH_INFO']=''; |
|
| 178 | + $server['REQUEST_METHOD']=strtoupper($method); |
|
| 179 | + $info=parse_url($uri); |
|
| 180 | 180 | if (isset($info['host'])) { |
| 181 | - $server['SERVER_NAME'] = $info['host']; |
|
| 182 | - $server['HTTP_HOST'] = $info['host']; |
|
| 181 | + $server['SERVER_NAME']=$info['host']; |
|
| 182 | + $server['HTTP_HOST']=$info['host']; |
|
| 183 | 183 | } |
| 184 | 184 | if (isset($info['scheme'])) { |
| 185 | 185 | if ('https' === $info['scheme']) { |
| 186 | - $server['HTTPS'] = 'on'; |
|
| 187 | - $server['SERVER_PORT'] = 443; |
|
| 186 | + $server['HTTPS']='on'; |
|
| 187 | + $server['SERVER_PORT']=443; |
|
| 188 | 188 | } else { |
| 189 | 189 | unset($server['HTTPS']); |
| 190 | - $server['SERVER_PORT'] = 80; |
|
| 190 | + $server['SERVER_PORT']=80; |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | if (isset($info['port'])) { |
| 194 | - $server['SERVER_PORT'] = $info['port']; |
|
| 195 | - $server['HTTP_HOST'] = $server['HTTP_HOST'] . ':' . $info['port']; |
|
| 194 | + $server['SERVER_PORT']=$info['port']; |
|
| 195 | + $server['HTTP_HOST']=$server['HTTP_HOST'].':'.$info['port']; |
|
| 196 | 196 | } |
| 197 | 197 | if (isset($info['user'])) { |
| 198 | - $server['PHP_AUTH_USER'] = $info['user']; |
|
| 198 | + $server['PHP_AUTH_USER']=$info['user']; |
|
| 199 | 199 | } |
| 200 | 200 | if (isset($info['pass'])) { |
| 201 | - $server['PHP_AUTH_PW'] = $info['pass']; |
|
| 201 | + $server['PHP_AUTH_PW']=$info['pass']; |
|
| 202 | 202 | } |
| 203 | 203 | if (!isset($info['path'])) { |
| 204 | - $info['path'] = '/'; |
|
| 204 | + $info['path']='/'; |
|
| 205 | 205 | } |
| 206 | - $options = []; |
|
| 207 | - $options[strtolower($method)] = $params; |
|
| 208 | - $queryString = ''; |
|
| 206 | + $options=[]; |
|
| 207 | + $options[strtolower($method)]=$params; |
|
| 208 | + $queryString=''; |
|
| 209 | 209 | if (isset($info['query'])) { |
| 210 | 210 | parse_str(html_entity_decode($info['query']), $query); |
| 211 | 211 | if (!empty($params)) { |
| 212 | - $params = array_replace($query, $params); |
|
| 213 | - $queryString = http_build_query($query, '', '&'); |
|
| 212 | + $params=array_replace($query, $params); |
|
| 213 | + $queryString=http_build_query($query, '', '&'); |
|
| 214 | 214 | } else { |
| 215 | - $params = $query; |
|
| 216 | - $queryString = $info['query']; |
|
| 215 | + $params=$query; |
|
| 216 | + $queryString=$info['query']; |
|
| 217 | 217 | } |
| 218 | 218 | } elseif (!empty($params)) { |
| 219 | - $queryString = http_build_query($params, '', '&'); |
|
| 219 | + $queryString=http_build_query($params, '', '&'); |
|
| 220 | 220 | } |
| 221 | 221 | if ($queryString) { |
| 222 | 222 | parse_str($queryString, $get); |
| 223 | - $options['get'] = isset($options['get']) ? array_merge($get, $options['get']) : $get; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $server['REQUEST_URI'] = $info['path'] . ('' !== $queryString ? '?' . $queryString : ''); |
|
| 227 | - $server['QUERY_STRING'] = $queryString; |
|
| 228 | - $options['cookie'] = $cookie; |
|
| 229 | - $options['param'] = $params; |
|
| 230 | - $options['file'] = $files; |
|
| 231 | - $options['server'] = $server; |
|
| 232 | - $options['url'] = $server['REQUEST_URI']; |
|
| 233 | - $options['baseUrl'] = $info['path']; |
|
| 234 | - $options['pathinfo'] = '/' == $info['path'] ? '/' : ltrim($info['path'], '/'); |
|
| 235 | - $options['method'] = $server['REQUEST_METHOD']; |
|
| 236 | - $options['domain'] = isset($info['scheme']) ? $info['scheme'] . '://' . $server['HTTP_HOST'] : ''; |
|
| 237 | - $options['content'] = $content; |
|
| 223 | + $options['get']=isset($options['get']) ? array_merge($get, $options['get']) : $get; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $server['REQUEST_URI']=$info['path'].('' !== $queryString ? '?'.$queryString : ''); |
|
| 227 | + $server['QUERY_STRING']=$queryString; |
|
| 228 | + $options['cookie']=$cookie; |
|
| 229 | + $options['param']=$params; |
|
| 230 | + $options['file']=$files; |
|
| 231 | + $options['server']=$server; |
|
| 232 | + $options['url']=$server['REQUEST_URI']; |
|
| 233 | + $options['baseUrl']=$info['path']; |
|
| 234 | + $options['pathinfo']='/' == $info['path'] ? '/' : ltrim($info['path'], '/'); |
|
| 235 | + $options['method']=$server['REQUEST_METHOD']; |
|
| 236 | + $options['domain']=isset($info['scheme']) ? $info['scheme'].'://'.$server['HTTP_HOST'] : ''; |
|
| 237 | + $options['content']=$content; |
|
| 238 | 238 | foreach ($options as $name => $item) { |
| 239 | 239 | if (property_exists($this, $name)) { |
| 240 | - $this->$name = $item; |
|
| 240 | + $this->$name=$item; |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | return $this; |
@@ -249,13 +249,13 @@ discard block |
||
| 249 | 249 | * @param string $domain 域名 |
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | - public function domain($domain = null) |
|
| 252 | + public function domain($domain=null) |
|
| 253 | 253 | { |
| 254 | 254 | if (!is_null($domain)) { |
| 255 | - $this->domain = $domain; |
|
| 255 | + $this->domain=$domain; |
|
| 256 | 256 | return $this; |
| 257 | 257 | } elseif (!$this->domain) { |
| 258 | - $this->domain = $this->scheme() . '://' . $this->host(); |
|
| 258 | + $this->domain=$this->scheme().'://'.$this->host(); |
|
| 259 | 259 | } |
| 260 | 260 | return $this->domain; |
| 261 | 261 | } |
@@ -266,25 +266,25 @@ discard block |
||
| 266 | 266 | * @param string|true $url URL地址 true 带域名获取 |
| 267 | 267 | * @return string |
| 268 | 268 | */ |
| 269 | - public function url($url = null) |
|
| 269 | + public function url($url=null) |
|
| 270 | 270 | { |
| 271 | 271 | if (!is_null($url) && true !== $url) { |
| 272 | - $this->url = $url; |
|
| 272 | + $this->url=$url; |
|
| 273 | 273 | return $this; |
| 274 | 274 | } elseif (!$this->url) { |
| 275 | 275 | if ($this->isCli()) { |
| 276 | - $this->url = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; |
|
| 276 | + $this->url=isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; |
|
| 277 | 277 | } elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) { |
| 278 | - $this->url = $_SERVER['HTTP_X_REWRITE_URL']; |
|
| 278 | + $this->url=$_SERVER['HTTP_X_REWRITE_URL']; |
|
| 279 | 279 | } elseif (isset($_SERVER['REQUEST_URI'])) { |
| 280 | - $this->url = $_SERVER['REQUEST_URI']; |
|
| 280 | + $this->url=$_SERVER['REQUEST_URI']; |
|
| 281 | 281 | } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { |
| 282 | - $this->url = $_SERVER['ORIG_PATH_INFO'] . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''); |
|
| 282 | + $this->url=$_SERVER['ORIG_PATH_INFO'].(!empty($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : ''); |
|
| 283 | 283 | } else { |
| 284 | - $this->url = ''; |
|
| 284 | + $this->url=''; |
|
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | - return true === $url ? $this->domain() . $this->url : $this->url; |
|
| 287 | + return true === $url ? $this->domain().$this->url : $this->url; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -293,16 +293,16 @@ discard block |
||
| 293 | 293 | * @param string $url URL地址 |
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | - public function baseUrl($url = null) |
|
| 296 | + public function baseUrl($url=null) |
|
| 297 | 297 | { |
| 298 | 298 | if (!is_null($url) && true !== $url) { |
| 299 | - $this->baseUrl = $url; |
|
| 299 | + $this->baseUrl=$url; |
|
| 300 | 300 | return $this; |
| 301 | 301 | } elseif (!$this->baseUrl) { |
| 302 | - $str = $this->url(); |
|
| 303 | - $this->baseUrl = strpos($str, '?') ? strstr($str, '?', true) : $str; |
|
| 302 | + $str=$this->url(); |
|
| 303 | + $this->baseUrl=strpos($str, '?') ? strstr($str, '?', true) : $str; |
|
| 304 | 304 | } |
| 305 | - return true === $url ? $this->domain() . $this->baseUrl : $this->baseUrl; |
|
| 305 | + return true === $url ? $this->domain().$this->baseUrl : $this->baseUrl; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -311,30 +311,30 @@ discard block |
||
| 311 | 311 | * @param string $file 当前执行的文件 |
| 312 | 312 | * @return string |
| 313 | 313 | */ |
| 314 | - public function baseFile($file = null) |
|
| 314 | + public function baseFile($file=null) |
|
| 315 | 315 | { |
| 316 | 316 | if (!is_null($file) && true !== $file) { |
| 317 | - $this->baseFile = $file; |
|
| 317 | + $this->baseFile=$file; |
|
| 318 | 318 | return $this; |
| 319 | 319 | } elseif (!$this->baseFile) { |
| 320 | - $url = ''; |
|
| 320 | + $url=''; |
|
| 321 | 321 | if (!$this->isCli()) { |
| 322 | - $script_name = basename($_SERVER['SCRIPT_FILENAME']); |
|
| 322 | + $script_name=basename($_SERVER['SCRIPT_FILENAME']); |
|
| 323 | 323 | if (basename($_SERVER['SCRIPT_NAME']) === $script_name) { |
| 324 | - $url = $_SERVER['SCRIPT_NAME']; |
|
| 324 | + $url=$_SERVER['SCRIPT_NAME']; |
|
| 325 | 325 | } elseif (basename($_SERVER['PHP_SELF']) === $script_name) { |
| 326 | - $url = $_SERVER['PHP_SELF']; |
|
| 326 | + $url=$_SERVER['PHP_SELF']; |
|
| 327 | 327 | } elseif (isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME']) === $script_name) { |
| 328 | - $url = $_SERVER['ORIG_SCRIPT_NAME']; |
|
| 329 | - } elseif (($pos = strpos($_SERVER['PHP_SELF'], '/' . $script_name)) !== false) { |
|
| 330 | - $url = substr($_SERVER['SCRIPT_NAME'], 0, $pos) . '/' . $script_name; |
|
| 328 | + $url=$_SERVER['ORIG_SCRIPT_NAME']; |
|
| 329 | + } elseif (($pos=strpos($_SERVER['PHP_SELF'], '/'.$script_name)) !== false) { |
|
| 330 | + $url=substr($_SERVER['SCRIPT_NAME'], 0, $pos).'/'.$script_name; |
|
| 331 | 331 | } elseif (isset($_SERVER['DOCUMENT_ROOT']) && strpos($_SERVER['SCRIPT_FILENAME'], $_SERVER['DOCUMENT_ROOT']) === 0) { |
| 332 | - $url = str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $_SERVER['SCRIPT_FILENAME'])); |
|
| 332 | + $url=str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $_SERVER['SCRIPT_FILENAME'])); |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | - $this->baseFile = $url; |
|
| 335 | + $this->baseFile=$url; |
|
| 336 | 336 | } |
| 337 | - return true === $file ? $this->domain() . $this->baseFile : $this->baseFile; |
|
| 337 | + return true === $file ? $this->domain().$this->baseFile : $this->baseFile; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -343,19 +343,19 @@ discard block |
||
| 343 | 343 | * @param string $url URL地址 |
| 344 | 344 | * @return string |
| 345 | 345 | */ |
| 346 | - public function root($url = null) |
|
| 346 | + public function root($url=null) |
|
| 347 | 347 | { |
| 348 | 348 | if (!is_null($url) && true !== $url) { |
| 349 | - $this->root = $url; |
|
| 349 | + $this->root=$url; |
|
| 350 | 350 | return $this; |
| 351 | 351 | } elseif (!$this->root) { |
| 352 | - $file = $this->baseFile(); |
|
| 352 | + $file=$this->baseFile(); |
|
| 353 | 353 | if ($file && 0 !== strpos($this->url(), $file)) { |
| 354 | - $file = str_replace('\\', '/', dirname($file)); |
|
| 354 | + $file=str_replace('\\', '/', dirname($file)); |
|
| 355 | 355 | } |
| 356 | - $this->root = rtrim($file, '/'); |
|
| 356 | + $this->root=rtrim($file, '/'); |
|
| 357 | 357 | } |
| 358 | - return true === $url ? $this->domain() . $this->root : $this->root; |
|
| 358 | + return true === $url ? $this->domain().$this->root : $this->root; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -365,10 +365,10 @@ discard block |
||
| 365 | 365 | */ |
| 366 | 366 | public function rootUrl() |
| 367 | 367 | { |
| 368 | - $base = $this->root(); |
|
| 369 | - $root = strpos($base, '.') ? ltrim(dirname($base), DIRECTORY_SEPARATOR) : $base; |
|
| 368 | + $base=$this->root(); |
|
| 369 | + $root=strpos($base, '.') ? ltrim(dirname($base), DIRECTORY_SEPARATOR) : $base; |
|
| 370 | 370 | if ('' != $root) { |
| 371 | - $root = '/' . ltrim($root, '/'); |
|
| 371 | + $root='/'.ltrim($root, '/'); |
|
| 372 | 372 | } |
| 373 | 373 | return $root; |
| 374 | 374 | } |
@@ -382,17 +382,17 @@ discard block |
||
| 382 | 382 | public function path() |
| 383 | 383 | { |
| 384 | 384 | if (is_null($this->path)) { |
| 385 | - $suffix = $this->config->get('core.url_html_suffix'); |
|
| 386 | - $pathinfo = $this->baseUrl(); |
|
| 385 | + $suffix=$this->config->get('core.url_html_suffix'); |
|
| 386 | + $pathinfo=$this->baseUrl(); |
|
| 387 | 387 | if (false === $suffix) { |
| 388 | 388 | // 禁止伪静态访问 |
| 389 | - $this->path = $pathinfo; |
|
| 389 | + $this->path=$pathinfo; |
|
| 390 | 390 | } elseif ($suffix) { |
| 391 | 391 | // 去除正常的URL后缀 |
| 392 | - $this->path = preg_replace('/\.(' . ltrim($suffix, '.') . ')$/i', '', $pathinfo); |
|
| 392 | + $this->path=preg_replace('/\.('.ltrim($suffix, '.').')$/i', '', $pathinfo); |
|
| 393 | 393 | } else { |
| 394 | 394 | // 允许任何后缀访问 |
| 395 | - $this->path = preg_replace('/\.' . $this->ext() . '$/i', '', $pathinfo); |
|
| 395 | + $this->path=preg_replace('/\.'.$this->ext().'$/i', '', $pathinfo); |
|
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | return $this->path; |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | * @param bool $float 是否使用浮点类型 |
| 415 | 415 | * @return integer|float |
| 416 | 416 | */ |
| 417 | - public function time($float = false) |
|
| 417 | + public function time($float=false) |
|
| 418 | 418 | { |
| 419 | 419 | return $float ? $_SERVER['REQUEST_TIME_FLOAT'] : $_SERVER['REQUEST_TIME']; |
| 420 | 420 | } |
@@ -426,13 +426,13 @@ discard block |
||
| 426 | 426 | */ |
| 427 | 427 | public function type() |
| 428 | 428 | { |
| 429 | - $accept = $this->server('HTTP_ACCEPT'); |
|
| 429 | + $accept=$this->server('HTTP_ACCEPT'); |
|
| 430 | 430 | if (empty($accept)) { |
| 431 | 431 | return false; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | foreach ($this->mimeType as $key => $val) { |
| 435 | - $array = explode(',', $val); |
|
| 435 | + $array=explode(',', $val); |
|
| 436 | 436 | foreach ($array as $k => $v) { |
| 437 | 437 | if (stristr($accept, $v)) { |
| 438 | 438 | return $key; |
@@ -449,12 +449,12 @@ discard block |
||
| 449 | 449 | * @param string $val 资源类型 |
| 450 | 450 | * @return void |
| 451 | 451 | */ |
| 452 | - public function mimeType($type, $val = '') |
|
| 452 | + public function mimeType($type, $val='') |
|
| 453 | 453 | { |
| 454 | 454 | if (is_array($type)) { |
| 455 | - $this->mimeType = array_merge($this->mimeType, $type); |
|
| 455 | + $this->mimeType=array_merge($this->mimeType, $type); |
|
| 456 | 456 | } else { |
| 457 | - $this->mimeType[$type] = $val; |
|
| 457 | + $this->mimeType[$type]=$val; |
|
| 458 | 458 | } |
| 459 | 459 | } |
| 460 | 460 | |
@@ -464,19 +464,19 @@ discard block |
||
| 464 | 464 | * @param bool $method true 获取原始请求类型 |
| 465 | 465 | * @return string |
| 466 | 466 | */ |
| 467 | - public function method($method = false) |
|
| 467 | + public function method($method=false) |
|
| 468 | 468 | { |
| 469 | 469 | if (true === $method) { |
| 470 | 470 | // 获取原始请求类型 |
| 471 | 471 | return $this->isCli() ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']); |
| 472 | 472 | } elseif (!$this->method) { |
| 473 | 473 | if (isset($_POST[$this->config->get('var_method')])) { |
| 474 | - $this->method = strtoupper($_POST[$this->config->get('var_method')]); |
|
| 474 | + $this->method=strtoupper($_POST[$this->config->get('var_method')]); |
|
| 475 | 475 | $this->{$this->method}($_POST); |
| 476 | 476 | } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { |
| 477 | - $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); |
|
| 477 | + $this->method=strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); |
|
| 478 | 478 | } else { |
| 479 | - $this->method = $this->isCli() ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']); |
|
| 479 | + $this->method=$this->isCli() ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']); |
|
| 480 | 480 | } |
| 481 | 481 | } |
| 482 | 482 | return $this->method; |
@@ -580,30 +580,30 @@ discard block |
||
| 580 | 580 | * @param string|array $filter 过滤方法 |
| 581 | 581 | * @return mixed |
| 582 | 582 | */ |
| 583 | - public function param($name = '', $default = null, $filter = '') |
|
| 583 | + public function param($name='', $default=null, $filter='') |
|
| 584 | 584 | { |
| 585 | 585 | if (empty($this->param)) { |
| 586 | - $method = $this->method(true); |
|
| 586 | + $method=$this->method(true); |
|
| 587 | 587 | // 自动获取请求变量 |
| 588 | 588 | switch ($method) { |
| 589 | 589 | case 'POST': |
| 590 | - $vars = $this->post(false); |
|
| 590 | + $vars=$this->post(false); |
|
| 591 | 591 | break; |
| 592 | 592 | case 'PUT': |
| 593 | 593 | case 'DELETE': |
| 594 | 594 | case 'PATCH': |
| 595 | - $vars = $this->put(false); |
|
| 595 | + $vars=$this->put(false); |
|
| 596 | 596 | break; |
| 597 | 597 | default: |
| 598 | - $vars = []; |
|
| 598 | + $vars=[]; |
|
| 599 | 599 | } |
| 600 | 600 | // 当前请求参数和URL地址中的参数合并 |
| 601 | - $this->param = array_merge($this->get(false), $vars, $this->route(false)); |
|
| 601 | + $this->param=array_merge($this->get(false), $vars, $this->route(false)); |
|
| 602 | 602 | } |
| 603 | 603 | if (true === $name) { |
| 604 | 604 | // 获取包含文件上传信息的数组 |
| 605 | - $file = $this->file(); |
|
| 606 | - $data = is_array($file) ? array_merge($this->param, $file) : $this->param; |
|
| 605 | + $file=$this->file(); |
|
| 606 | + $data=is_array($file) ? array_merge($this->param, $file) : $this->param; |
|
| 607 | 607 | return $this->input($data, '', $default, $filter); |
| 608 | 608 | } |
| 609 | 609 | return $this->input($this->param, $name, $default, $filter); |
@@ -617,11 +617,11 @@ discard block |
||
| 617 | 617 | * @param string|array $filter 过滤方法 |
| 618 | 618 | * @return mixed |
| 619 | 619 | */ |
| 620 | - public function route($name = '', $default = null, $filter = '') |
|
| 620 | + public function route($name='', $default=null, $filter='') |
|
| 621 | 621 | { |
| 622 | 622 | if (is_array($name)) { |
| 623 | - $this->param = []; |
|
| 624 | - return $this->route = array_merge($this->route, $name); |
|
| 623 | + $this->param=[]; |
|
| 624 | + return $this->route=array_merge($this->route, $name); |
|
| 625 | 625 | } |
| 626 | 626 | return $this->input($this->route, $name, $default, $filter); |
| 627 | 627 | } |
@@ -634,14 +634,14 @@ discard block |
||
| 634 | 634 | * @param string|array $filter 过滤方法 |
| 635 | 635 | * @return mixed |
| 636 | 636 | */ |
| 637 | - public function get($name = '', $default = null, $filter = '') |
|
| 637 | + public function get($name='', $default=null, $filter='') |
|
| 638 | 638 | { |
| 639 | 639 | if (empty($this->get)) { |
| 640 | - $this->get = $_GET; |
|
| 640 | + $this->get=$_GET; |
|
| 641 | 641 | } |
| 642 | 642 | if (is_array($name)) { |
| 643 | - $this->param = []; |
|
| 644 | - return $this->get = array_merge($this->get, $name); |
|
| 643 | + $this->param=[]; |
|
| 644 | + return $this->get=array_merge($this->get, $name); |
|
| 645 | 645 | } |
| 646 | 646 | return $this->input($this->get, $name, $default, $filter); |
| 647 | 647 | } |
@@ -654,19 +654,19 @@ discard block |
||
| 654 | 654 | * @param string|array $filter 过滤方法 |
| 655 | 655 | * @return mixed |
| 656 | 656 | */ |
| 657 | - public function post($name = '', $default = null, $filter = '') |
|
| 657 | + public function post($name='', $default=null, $filter='') |
|
| 658 | 658 | { |
| 659 | 659 | if (empty($this->post)) { |
| 660 | - $content = $this->input; |
|
| 660 | + $content=$this->input; |
|
| 661 | 661 | if (empty($_POST) && false !== strpos($this->contentType(), 'application/json')) { |
| 662 | - $this->post = (array) json_decode($content, true); |
|
| 662 | + $this->post=(array) json_decode($content, true); |
|
| 663 | 663 | } else { |
| 664 | - $this->post = $_POST; |
|
| 664 | + $this->post=$_POST; |
|
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | 667 | if (is_array($name)) { |
| 668 | - $this->param = []; |
|
| 669 | - return $this->post = array_merge($this->post, $name); |
|
| 668 | + $this->param=[]; |
|
| 669 | + return $this->post=array_merge($this->post, $name); |
|
| 670 | 670 | } |
| 671 | 671 | return $this->input($this->post, $name, $default, $filter); |
| 672 | 672 | } |
@@ -679,19 +679,19 @@ discard block |
||
| 679 | 679 | * @param string|array $filter 过滤方法 |
| 680 | 680 | * @return mixed |
| 681 | 681 | */ |
| 682 | - public function put($name = '', $default = null, $filter = '') |
|
| 682 | + public function put($name='', $default=null, $filter='') |
|
| 683 | 683 | { |
| 684 | 684 | if (is_null($this->put)) { |
| 685 | - $content = $this->input; |
|
| 685 | + $content=$this->input; |
|
| 686 | 686 | if (false !== strpos($this->contentType(), 'application/json')) { |
| 687 | - $this->put = (array) json_decode($content, true); |
|
| 687 | + $this->put=(array) json_decode($content, true); |
|
| 688 | 688 | } else { |
| 689 | 689 | parse_str($content, $this->put); |
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | if (is_array($name)) { |
| 693 | - $this->param = []; |
|
| 694 | - return $this->put = is_null($this->put) ? $name : array_merge($this->put, $name); |
|
| 693 | + $this->param=[]; |
|
| 694 | + return $this->put=is_null($this->put) ? $name : array_merge($this->put, $name); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | return $this->input($this->put, $name, $default, $filter); |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | * @param string|array $filter 过滤方法 |
| 706 | 706 | * @return mixed |
| 707 | 707 | */ |
| 708 | - public function delete($name = '', $default = null, $filter = '') |
|
| 708 | + public function delete($name='', $default=null, $filter='') |
|
| 709 | 709 | { |
| 710 | 710 | return $this->put($name, $default, $filter); |
| 711 | 711 | } |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | * @param string|array $filter 过滤方法 |
| 719 | 719 | * @return mixed |
| 720 | 720 | */ |
| 721 | - public function patch($name = '', $default = null, $filter = '') |
|
| 721 | + public function patch($name='', $default=null, $filter='') |
|
| 722 | 722 | { |
| 723 | 723 | return $this->put($name, $default, $filter); |
| 724 | 724 | } |
@@ -730,14 +730,14 @@ discard block |
||
| 730 | 730 | * @param string|array $filter 过滤方法 |
| 731 | 731 | * @return mixed |
| 732 | 732 | */ |
| 733 | - public function request($name = '', $default = null, $filter = '') |
|
| 733 | + public function request($name='', $default=null, $filter='') |
|
| 734 | 734 | { |
| 735 | 735 | if (empty($this->request)) { |
| 736 | - $this->request = $_REQUEST; |
|
| 736 | + $this->request=$_REQUEST; |
|
| 737 | 737 | } |
| 738 | 738 | if (is_array($name)) { |
| 739 | - $this->param = []; |
|
| 740 | - return $this->request = array_merge($this->request, $name); |
|
| 739 | + $this->param=[]; |
|
| 740 | + return $this->request=array_merge($this->request, $name); |
|
| 741 | 741 | } |
| 742 | 742 | return $this->input($this->request, $name, $default, $filter); |
| 743 | 743 | } |
@@ -750,13 +750,13 @@ discard block |
||
| 750 | 750 | * @param string|array $filter 过滤方法 |
| 751 | 751 | * @return mixed |
| 752 | 752 | */ |
| 753 | - public function session($name = '', $default = null, $filter = '') |
|
| 753 | + public function session($name='', $default=null, $filter='') |
|
| 754 | 754 | { |
| 755 | 755 | if (empty($this->session)) { |
| 756 | - $this->session = Session::get(); |
|
| 756 | + $this->session=Session::get(); |
|
| 757 | 757 | } |
| 758 | 758 | if (is_array($name)) { |
| 759 | - return $this->session = array_merge($this->session, $name); |
|
| 759 | + return $this->session=array_merge($this->session, $name); |
|
| 760 | 760 | } |
| 761 | 761 | return $this->input($this->session, $name, $default, $filter); |
| 762 | 762 | } |
@@ -769,13 +769,13 @@ discard block |
||
| 769 | 769 | * @param string|array $filter 过滤方法 |
| 770 | 770 | * @return mixed |
| 771 | 771 | */ |
| 772 | - public function cookie($name = '', $default = null, $filter = '') |
|
| 772 | + public function cookie($name='', $default=null, $filter='') |
|
| 773 | 773 | { |
| 774 | 774 | if (empty($this->cookie)) { |
| 775 | - $this->cookie = $_COOKIE; |
|
| 775 | + $this->cookie=$_COOKIE; |
|
| 776 | 776 | } |
| 777 | 777 | if (is_array($name)) { |
| 778 | - return $this->cookie = array_merge($this->cookie, $name); |
|
| 778 | + return $this->cookie=array_merge($this->cookie, $name); |
|
| 779 | 779 | } |
| 780 | 780 | return $this->input($this->cookie, $name, $default, $filter); |
| 781 | 781 | } |
@@ -788,13 +788,13 @@ discard block |
||
| 788 | 788 | * @param string|array $filter 过滤方法 |
| 789 | 789 | * @return mixed |
| 790 | 790 | */ |
| 791 | - public function server($name = '', $default = null, $filter = '') |
|
| 791 | + public function server($name='', $default=null, $filter='') |
|
| 792 | 792 | { |
| 793 | 793 | if (empty($this->server)) { |
| 794 | - $this->server = $_SERVER; |
|
| 794 | + $this->server=$_SERVER; |
|
| 795 | 795 | } |
| 796 | 796 | if (is_array($name)) { |
| 797 | - return $this->server = array_merge($this->server, $name); |
|
| 797 | + return $this->server=array_merge($this->server, $name); |
|
| 798 | 798 | } |
| 799 | 799 | return $this->input($this->server, false === $name ? false : strtoupper($name), $default, $filter); |
| 800 | 800 | } |
@@ -805,47 +805,47 @@ discard block |
||
| 805 | 805 | * @param string|array $name 名称 |
| 806 | 806 | * @return null|array|\think\File |
| 807 | 807 | */ |
| 808 | - public function file($name = '') |
|
| 808 | + public function file($name='') |
|
| 809 | 809 | { |
| 810 | 810 | if (empty($this->file)) { |
| 811 | - $this->file = isset($_FILES) ? $_FILES : []; |
|
| 811 | + $this->file=isset($_FILES) ? $_FILES : []; |
|
| 812 | 812 | } |
| 813 | 813 | if (is_array($name)) { |
| 814 | - return $this->file = array_merge($this->file, $name); |
|
| 814 | + return $this->file=array_merge($this->file, $name); |
|
| 815 | 815 | } |
| 816 | - $files = $this->file; |
|
| 816 | + $files=$this->file; |
|
| 817 | 817 | if (!empty($files)) { |
| 818 | 818 | // 处理上传文件 |
| 819 | - $array = []; |
|
| 819 | + $array=[]; |
|
| 820 | 820 | foreach ($files as $key => $file) { |
| 821 | 821 | if (is_array($file['name'])) { |
| 822 | - $item = []; |
|
| 823 | - $keys = array_keys($file); |
|
| 824 | - $count = count($file['name']); |
|
| 825 | - for ($i = 0; $i < $count; $i++) { |
|
| 822 | + $item=[]; |
|
| 823 | + $keys=array_keys($file); |
|
| 824 | + $count=count($file['name']); |
|
| 825 | + for ($i=0; $i < $count; $i++) { |
|
| 826 | 826 | if (empty($file['tmp_name'][$i]) || !is_file($file['tmp_name'][$i])) { |
| 827 | 827 | continue; |
| 828 | 828 | } |
| 829 | - $temp['key'] = $key; |
|
| 829 | + $temp['key']=$key; |
|
| 830 | 830 | foreach ($keys as $_key) { |
| 831 | - $temp[$_key] = $file[$_key][$i]; |
|
| 831 | + $temp[$_key]=$file[$_key][$i]; |
|
| 832 | 832 | } |
| 833 | - $item[] = (new File($temp['tmp_name']))->setUploadInfo($temp); |
|
| 833 | + $item[]=(new File($temp['tmp_name']))->setUploadInfo($temp); |
|
| 834 | 834 | } |
| 835 | - $array[$key] = $item; |
|
| 835 | + $array[$key]=$item; |
|
| 836 | 836 | } else { |
| 837 | 837 | if ($file instanceof File) { |
| 838 | - $array[$key] = $file; |
|
| 838 | + $array[$key]=$file; |
|
| 839 | 839 | } else { |
| 840 | 840 | if (empty($file['tmp_name']) || !is_file($file['tmp_name'])) { |
| 841 | 841 | continue; |
| 842 | 842 | } |
| 843 | - $array[$key] = (new File($file['tmp_name']))->setUploadInfo($file); |
|
| 843 | + $array[$key]=(new File($file['tmp_name']))->setUploadInfo($file); |
|
| 844 | 844 | } |
| 845 | 845 | } |
| 846 | 846 | } |
| 847 | 847 | if (strpos($name, '.')) { |
| 848 | - list($name, $sub) = explode('.', $name); |
|
| 848 | + list($name, $sub)=explode('.', $name); |
|
| 849 | 849 | } |
| 850 | 850 | if ('' === $name) { |
| 851 | 851 | // 获取全部文件 |
@@ -866,13 +866,13 @@ discard block |
||
| 866 | 866 | * @param string|array $filter 过滤方法 |
| 867 | 867 | * @return mixed |
| 868 | 868 | */ |
| 869 | - public function env($name = '', $default = null, $filter = '') |
|
| 869 | + public function env($name='', $default=null, $filter='') |
|
| 870 | 870 | { |
| 871 | 871 | if (empty($this->env)) { |
| 872 | - $this->env = $_ENV; |
|
| 872 | + $this->env=$_ENV; |
|
| 873 | 873 | } |
| 874 | 874 | if (is_array($name)) { |
| 875 | - return $this->env = array_merge($this->env, $name); |
|
| 875 | + return $this->env=array_merge($this->env, $name); |
|
| 876 | 876 | } |
| 877 | 877 | return $this->input($this->env, false === $name ? false : strtoupper($name), $default, $filter); |
| 878 | 878 | } |
@@ -884,36 +884,36 @@ discard block |
||
| 884 | 884 | * @param string $default 默认值 |
| 885 | 885 | * @return string |
| 886 | 886 | */ |
| 887 | - public function header($name = '', $default = null) |
|
| 887 | + public function header($name='', $default=null) |
|
| 888 | 888 | { |
| 889 | 889 | if (empty($this->header)) { |
| 890 | - $header = []; |
|
| 891 | - if (function_exists('apache_request_headers') && $result = apache_request_headers()) { |
|
| 892 | - $header = $result; |
|
| 890 | + $header=[]; |
|
| 891 | + if (function_exists('apache_request_headers') && $result=apache_request_headers()) { |
|
| 892 | + $header=$result; |
|
| 893 | 893 | } else { |
| 894 | - $server = $this->server ?: $_SERVER; |
|
| 894 | + $server=$this->server ?: $_SERVER; |
|
| 895 | 895 | foreach ($server as $key => $val) { |
| 896 | 896 | if (0 === strpos($key, 'HTTP_')) { |
| 897 | - $key = str_replace('_', '-', strtolower(substr($key, 5))); |
|
| 898 | - $header[$key] = $val; |
|
| 897 | + $key=str_replace('_', '-', strtolower(substr($key, 5))); |
|
| 898 | + $header[$key]=$val; |
|
| 899 | 899 | } |
| 900 | 900 | } |
| 901 | 901 | if (isset($server['CONTENT_TYPE'])) { |
| 902 | - $header['content-type'] = $server['CONTENT_TYPE']; |
|
| 902 | + $header['content-type']=$server['CONTENT_TYPE']; |
|
| 903 | 903 | } |
| 904 | 904 | if (isset($server['CONTENT_LENGTH'])) { |
| 905 | - $header['content-length'] = $server['CONTENT_LENGTH']; |
|
| 905 | + $header['content-length']=$server['CONTENT_LENGTH']; |
|
| 906 | 906 | } |
| 907 | 907 | } |
| 908 | - $this->header = array_change_key_case($header); |
|
| 908 | + $this->header=array_change_key_case($header); |
|
| 909 | 909 | } |
| 910 | 910 | if (is_array($name)) { |
| 911 | - return $this->header = array_merge($this->header, $name); |
|
| 911 | + return $this->header=array_merge($this->header, $name); |
|
| 912 | 912 | } |
| 913 | 913 | if ('' === $name) { |
| 914 | 914 | return $this->header; |
| 915 | 915 | } |
| 916 | - $name = str_replace('_', '-', strtolower($name)); |
|
| 916 | + $name=str_replace('_', '-', strtolower($name)); |
|
| 917 | 917 | return isset($this->header[$name]) ? $this->header[$name] : $default; |
| 918 | 918 | } |
| 919 | 919 | |
@@ -925,24 +925,24 @@ discard block |
||
| 925 | 925 | * @param string|array $filter 过滤函数 |
| 926 | 926 | * @return mixed |
| 927 | 927 | */ |
| 928 | - public function input($data = [], $name = '', $default = null, $filter = '') |
|
| 928 | + public function input($data=[], $name='', $default=null, $filter='') |
|
| 929 | 929 | { |
| 930 | 930 | if (false === $name) { |
| 931 | 931 | // 获取原始数据 |
| 932 | 932 | return $data; |
| 933 | 933 | } |
| 934 | - $name = (string) $name; |
|
| 934 | + $name=(string) $name; |
|
| 935 | 935 | if ('' != $name) { |
| 936 | 936 | // 解析name |
| 937 | 937 | if (strpos($name, '/')) { |
| 938 | - list($name, $type) = explode('/', $name); |
|
| 938 | + list($name, $type)=explode('/', $name); |
|
| 939 | 939 | } else { |
| 940 | - $type = 's'; |
|
| 940 | + $type='s'; |
|
| 941 | 941 | } |
| 942 | 942 | // 按.拆分成多维数组进行判断 |
| 943 | 943 | foreach (explode('.', $name) as $val) { |
| 944 | 944 | if (isset($data[$val])) { |
| 945 | - $data = $data[$val]; |
|
| 945 | + $data=$data[$val]; |
|
| 946 | 946 | } else { |
| 947 | 947 | // 无输入数据,返回默认值 |
| 948 | 948 | return $default; |
@@ -955,17 +955,17 @@ discard block |
||
| 955 | 955 | |
| 956 | 956 | // 解析过滤器 |
| 957 | 957 | if (is_null($filter)) { |
| 958 | - $filter = []; |
|
| 958 | + $filter=[]; |
|
| 959 | 959 | } else { |
| 960 | - $filter = $filter ?: $this->filter; |
|
| 960 | + $filter=$filter ?: $this->filter; |
|
| 961 | 961 | if (is_string($filter)) { |
| 962 | - $filter = explode(',', $filter); |
|
| 962 | + $filter=explode(',', $filter); |
|
| 963 | 963 | } else { |
| 964 | - $filter = (array) $filter; |
|
| 964 | + $filter=(array) $filter; |
|
| 965 | 965 | } |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | - $filter[] = $default; |
|
| 968 | + $filter[]=$default; |
|
| 969 | 969 | if (is_array($data)) { |
| 970 | 970 | array_walk_recursive($data, [$this, 'filterValue'], $filter); |
| 971 | 971 | reset($data); |
@@ -985,12 +985,12 @@ discard block |
||
| 985 | 985 | * @param mixed $filter 过滤规则 |
| 986 | 986 | * @return mixed |
| 987 | 987 | */ |
| 988 | - public function filter($filter = null) |
|
| 988 | + public function filter($filter=null) |
|
| 989 | 989 | { |
| 990 | 990 | if (is_null($filter)) { |
| 991 | 991 | return $this->filter; |
| 992 | 992 | } else { |
| 993 | - $this->filter = $filter; |
|
| 993 | + $this->filter=$filter; |
|
| 994 | 994 | } |
| 995 | 995 | } |
| 996 | 996 | |
@@ -1003,25 +1003,25 @@ discard block |
||
| 1003 | 1003 | */ |
| 1004 | 1004 | private function filterValue(&$value, $key, $filters) |
| 1005 | 1005 | { |
| 1006 | - $default = array_pop($filters); |
|
| 1006 | + $default=array_pop($filters); |
|
| 1007 | 1007 | foreach ($filters as $filter) { |
| 1008 | 1008 | if (is_callable($filter)) { |
| 1009 | 1009 | // 调用函数或者方法过滤 |
| 1010 | - $value = call_user_func($filter, $value); |
|
| 1010 | + $value=call_user_func($filter, $value); |
|
| 1011 | 1011 | } elseif (is_scalar($value)) { |
| 1012 | 1012 | if (strpos($filter, '/')) { |
| 1013 | 1013 | // 正则过滤 |
| 1014 | 1014 | if (!preg_match($filter, $value)) { |
| 1015 | 1015 | // 匹配不成功返回默认值 |
| 1016 | - $value = $default; |
|
| 1016 | + $value=$default; |
|
| 1017 | 1017 | break; |
| 1018 | 1018 | } |
| 1019 | 1019 | } elseif (!empty($filter)) { |
| 1020 | 1020 | // filter函数不存在时, 则使用filter_var进行过滤 |
| 1021 | 1021 | // filter为非整形值时, 调用filter_id取得过滤id |
| 1022 | - $value = filter_var($value, is_int($filter) ? $filter : filter_id($filter)); |
|
| 1022 | + $value=filter_var($value, is_int($filter) ? $filter : filter_id($filter)); |
|
| 1023 | 1023 | if (false === $value) { |
| 1024 | - $value = $default; |
|
| 1024 | + $value=$default; |
|
| 1025 | 1025 | break; |
| 1026 | 1026 | } |
| 1027 | 1027 | } |
@@ -1039,7 +1039,7 @@ discard block |
||
| 1039 | 1039 | { |
| 1040 | 1040 | // 过滤查询特殊字符 |
| 1041 | 1041 | if (is_string($value) && preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i', $value)) { |
| 1042 | - $value .= ' '; |
|
| 1042 | + $value.=' '; |
|
| 1043 | 1043 | } |
| 1044 | 1044 | // TODO 其他安全过滤 |
| 1045 | 1045 | } |
@@ -1055,27 +1055,27 @@ discard block |
||
| 1055 | 1055 | switch (strtolower($type)) { |
| 1056 | 1056 | // 数组 |
| 1057 | 1057 | case 'a': |
| 1058 | - $data = (array) $data; |
|
| 1058 | + $data=(array) $data; |
|
| 1059 | 1059 | break; |
| 1060 | 1060 | // 数字 |
| 1061 | 1061 | case 'd': |
| 1062 | - $data = (int) $data; |
|
| 1062 | + $data=(int) $data; |
|
| 1063 | 1063 | break; |
| 1064 | 1064 | // 浮点 |
| 1065 | 1065 | case 'f': |
| 1066 | - $data = (float) $data; |
|
| 1066 | + $data=(float) $data; |
|
| 1067 | 1067 | break; |
| 1068 | 1068 | // 布尔 |
| 1069 | 1069 | case 'b': |
| 1070 | - $data = (boolean) $data; |
|
| 1070 | + $data=(boolean) $data; |
|
| 1071 | 1071 | break; |
| 1072 | 1072 | // 字符串 |
| 1073 | 1073 | case 's': |
| 1074 | 1074 | default: |
| 1075 | 1075 | if (is_scalar($data)) { |
| 1076 | - $data = (string) $data; |
|
| 1076 | + $data=(string) $data; |
|
| 1077 | 1077 | } else { |
| 1078 | - throw new \InvalidArgumentException('variable type error:' . gettype($data)); |
|
| 1078 | + throw new \InvalidArgumentException('variable type error:'.gettype($data)); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | } |
| 1081 | 1081 | } |
@@ -1088,17 +1088,17 @@ discard block |
||
| 1088 | 1088 | * @param bool $checkEmpty 是否检测空值 |
| 1089 | 1089 | * @return mixed |
| 1090 | 1090 | */ |
| 1091 | - public function has($name, $type = 'param', $checkEmpty = false) |
|
| 1091 | + public function has($name, $type='param', $checkEmpty=false) |
|
| 1092 | 1092 | { |
| 1093 | 1093 | if (empty($this->$type)) { |
| 1094 | - $param = $this->$type(); |
|
| 1094 | + $param=$this->$type(); |
|
| 1095 | 1095 | } else { |
| 1096 | - $param = $this->$type; |
|
| 1096 | + $param=$this->$type; |
|
| 1097 | 1097 | } |
| 1098 | 1098 | // 按.拆分成多维数组进行判断 |
| 1099 | 1099 | foreach (explode('.', $name) as $val) { |
| 1100 | 1100 | if (isset($param[$val])) { |
| 1101 | - $param = $param[$val]; |
|
| 1101 | + $param=$param[$val]; |
|
| 1102 | 1102 | } else { |
| 1103 | 1103 | return false; |
| 1104 | 1104 | } |
@@ -1113,16 +1113,16 @@ discard block |
||
| 1113 | 1113 | * @param string $type 变量类型 |
| 1114 | 1114 | * @return mixed |
| 1115 | 1115 | */ |
| 1116 | - public function only($name, $type = 'param') |
|
| 1116 | + public function only($name, $type='param') |
|
| 1117 | 1117 | { |
| 1118 | - $param = $this->$type(); |
|
| 1118 | + $param=$this->$type(); |
|
| 1119 | 1119 | if (is_string($name)) { |
| 1120 | - $name = explode(',', $name); |
|
| 1120 | + $name=explode(',', $name); |
|
| 1121 | 1121 | } |
| 1122 | - $item = []; |
|
| 1122 | + $item=[]; |
|
| 1123 | 1123 | foreach ($name as $key) { |
| 1124 | 1124 | if (isset($param[$key])) { |
| 1125 | - $item[$key] = $param[$key]; |
|
| 1125 | + $item[$key]=$param[$key]; |
|
| 1126 | 1126 | } |
| 1127 | 1127 | } |
| 1128 | 1128 | return $item; |
@@ -1135,11 +1135,11 @@ discard block |
||
| 1135 | 1135 | * @param string $type 变量类型 |
| 1136 | 1136 | * @return mixed |
| 1137 | 1137 | */ |
| 1138 | - public function except($name, $type = 'param') |
|
| 1138 | + public function except($name, $type='param') |
|
| 1139 | 1139 | { |
| 1140 | - $param = $this->$type(); |
|
| 1140 | + $param=$this->$type(); |
|
| 1141 | 1141 | if (is_string($name)) { |
| 1142 | - $name = explode(',', $name); |
|
| 1142 | + $name=explode(',', $name); |
|
| 1143 | 1143 | } |
| 1144 | 1144 | foreach ($name as $key) { |
| 1145 | 1145 | if (isset($param[$key])) { |
@@ -1156,7 +1156,7 @@ discard block |
||
| 1156 | 1156 | */ |
| 1157 | 1157 | public function isSsl() |
| 1158 | 1158 | { |
| 1159 | - $server = array_merge($_SERVER, $this->server); |
|
| 1159 | + $server=array_merge($_SERVER, $this->server); |
|
| 1160 | 1160 | if (isset($server['HTTPS']) && ('1' == $server['HTTPS'] || 'on' == strtolower($server['HTTPS']))) { |
| 1161 | 1161 | return true; |
| 1162 | 1162 | } elseif (isset($server['REQUEST_SCHEME']) && 'https' == $server['REQUEST_SCHEME']) { |
@@ -1175,10 +1175,10 @@ discard block |
||
| 1175 | 1175 | * @param bool $ajax true 获取原始ajax请求 |
| 1176 | 1176 | * @return bool |
| 1177 | 1177 | */ |
| 1178 | - public function isAjax($ajax = false) |
|
| 1178 | + public function isAjax($ajax=false) |
|
| 1179 | 1179 | { |
| 1180 | - $value = $this->server('HTTP_X_REQUESTED_WITH', '', 'strtolower'); |
|
| 1181 | - $result = ('xmlhttprequest' == $value) ? true : false; |
|
| 1180 | + $value=$this->server('HTTP_X_REQUESTED_WITH', '', 'strtolower'); |
|
| 1181 | + $result=('xmlhttprequest' == $value) ? true : false; |
|
| 1182 | 1182 | if (true === $ajax) { |
| 1183 | 1183 | return $result; |
| 1184 | 1184 | } else { |
@@ -1192,9 +1192,9 @@ discard block |
||
| 1192 | 1192 | * @param bool $pjax true 获取原始pjax请求 |
| 1193 | 1193 | * @return bool |
| 1194 | 1194 | */ |
| 1195 | - public function isPjax($pjax = false) |
|
| 1195 | + public function isPjax($pjax=false) |
|
| 1196 | 1196 | { |
| 1197 | - $result = !is_null($this->server('HTTP_X_PJAX')) ? true : false; |
|
| 1197 | + $result=!is_null($this->server('HTTP_X_PJAX')) ? true : false; |
|
| 1198 | 1198 | if (true === $pjax) { |
| 1199 | 1199 | return $result; |
| 1200 | 1200 | } else { |
@@ -1208,33 +1208,33 @@ discard block |
||
| 1208 | 1208 | * @param boolean $adv 是否进行高级模式获取(有可能被伪装) |
| 1209 | 1209 | * @return mixed |
| 1210 | 1210 | */ |
| 1211 | - public function ip($type = 0, $adv = false) |
|
| 1211 | + public function ip($type=0, $adv=false) |
|
| 1212 | 1212 | { |
| 1213 | - $type = $type ? 1 : 0; |
|
| 1214 | - static $ip = null; |
|
| 1213 | + $type=$type ? 1 : 0; |
|
| 1214 | + static $ip=null; |
|
| 1215 | 1215 | if (null !== $ip) { |
| 1216 | 1216 | return $ip[$type]; |
| 1217 | 1217 | } |
| 1218 | 1218 | |
| 1219 | 1219 | if ($adv) { |
| 1220 | 1220 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 1221 | - $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
|
| 1222 | - $pos = array_search('unknown', $arr); |
|
| 1221 | + $arr=explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
|
| 1222 | + $pos=array_search('unknown', $arr); |
|
| 1223 | 1223 | if (false !== $pos) { |
| 1224 | 1224 | unset($arr[$pos]); |
| 1225 | 1225 | } |
| 1226 | - $ip = trim(current($arr)); |
|
| 1226 | + $ip=trim(current($arr)); |
|
| 1227 | 1227 | } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { |
| 1228 | - $ip = $_SERVER['HTTP_CLIENT_IP']; |
|
| 1228 | + $ip=$_SERVER['HTTP_CLIENT_IP']; |
|
| 1229 | 1229 | } elseif (isset($_SERVER['REMOTE_ADDR'])) { |
| 1230 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 1230 | + $ip=$_SERVER['REMOTE_ADDR']; |
|
| 1231 | 1231 | } |
| 1232 | 1232 | } elseif (isset($_SERVER['REMOTE_ADDR'])) { |
| 1233 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 1233 | + $ip=$_SERVER['REMOTE_ADDR']; |
|
| 1234 | 1234 | } |
| 1235 | 1235 | // IP地址合法验证 |
| 1236 | - $long = sprintf("%u", ip2long($ip)); |
|
| 1237 | - $ip = $long ? [$ip, $long] : ['0.0.0.0', 0]; |
|
| 1236 | + $long=sprintf("%u", ip2long($ip)); |
|
| 1237 | + $ip=$long ? [$ip, $long] : ['0.0.0.0', 0]; |
|
| 1238 | 1238 | return $ip[$type]; |
| 1239 | 1239 | } |
| 1240 | 1240 | |
@@ -1325,12 +1325,12 @@ discard block |
||
| 1325 | 1325 | */ |
| 1326 | 1326 | public function contentType() |
| 1327 | 1327 | { |
| 1328 | - $contentType = $this->server('CONTENT_TYPE'); |
|
| 1328 | + $contentType=$this->server('CONTENT_TYPE'); |
|
| 1329 | 1329 | if ($contentType) { |
| 1330 | 1330 | if (strpos($contentType, ';')) { |
| 1331 | - list($type) = explode(';', $contentType); |
|
| 1331 | + list($type)=explode(';', $contentType); |
|
| 1332 | 1332 | } else { |
| 1333 | - $type = $contentType; |
|
| 1333 | + $type=$contentType; |
|
| 1334 | 1334 | } |
| 1335 | 1335 | return trim($type); |
| 1336 | 1336 | } |
@@ -1343,10 +1343,10 @@ discard block |
||
| 1343 | 1343 | * @param array $route 路由名称 |
| 1344 | 1344 | * @return array |
| 1345 | 1345 | */ |
| 1346 | - public function routeInfo($route = []) |
|
| 1346 | + public function routeInfo($route=[]) |
|
| 1347 | 1347 | { |
| 1348 | 1348 | if (!empty($route)) { |
| 1349 | - $this->routeInfo = $route; |
|
| 1349 | + $this->routeInfo=$route; |
|
| 1350 | 1350 | } else { |
| 1351 | 1351 | return $this->routeInfo; |
| 1352 | 1352 | } |
@@ -1358,10 +1358,10 @@ discard block |
||
| 1358 | 1358 | * @param array $dispatch 调度信息 |
| 1359 | 1359 | * @return array |
| 1360 | 1360 | */ |
| 1361 | - public function dispatch($dispatch = null) |
|
| 1361 | + public function dispatch($dispatch=null) |
|
| 1362 | 1362 | { |
| 1363 | 1363 | if (!is_null($dispatch)) { |
| 1364 | - $this->dispatch = $dispatch; |
|
| 1364 | + $this->dispatch=$dispatch; |
|
| 1365 | 1365 | } |
| 1366 | 1366 | return $this->dispatch; |
| 1367 | 1367 | } |
@@ -1372,10 +1372,10 @@ discard block |
||
| 1372 | 1372 | * @param string $module 模块名 |
| 1373 | 1373 | * @return string|Request |
| 1374 | 1374 | */ |
| 1375 | - public function module($module = null) |
|
| 1375 | + public function module($module=null) |
|
| 1376 | 1376 | { |
| 1377 | 1377 | if (!is_null($module)) { |
| 1378 | - $this->module = $module; |
|
| 1378 | + $this->module=$module; |
|
| 1379 | 1379 | return $this; |
| 1380 | 1380 | } else { |
| 1381 | 1381 | return $this->module ?: ''; |
@@ -1388,10 +1388,10 @@ discard block |
||
| 1388 | 1388 | * @param string $controller 控制器名 |
| 1389 | 1389 | * @return string|Request |
| 1390 | 1390 | */ |
| 1391 | - public function controller($controller = null) |
|
| 1391 | + public function controller($controller=null) |
|
| 1392 | 1392 | { |
| 1393 | 1393 | if (!is_null($controller)) { |
| 1394 | - $this->controller = $controller; |
|
| 1394 | + $this->controller=$controller; |
|
| 1395 | 1395 | return $this; |
| 1396 | 1396 | } else { |
| 1397 | 1397 | return $this->controller ?: ''; |
@@ -1404,10 +1404,10 @@ discard block |
||
| 1404 | 1404 | * @param string $action 操作名 |
| 1405 | 1405 | * @return string|Request |
| 1406 | 1406 | */ |
| 1407 | - public function action($action = null) |
|
| 1407 | + public function action($action=null) |
|
| 1408 | 1408 | { |
| 1409 | 1409 | if (!is_null($action)) { |
| 1410 | - $this->action = $action; |
|
| 1410 | + $this->action=$action; |
|
| 1411 | 1411 | return $this; |
| 1412 | 1412 | } else { |
| 1413 | 1413 | return $this->action ?: ''; |
@@ -1420,10 +1420,10 @@ discard block |
||
| 1420 | 1420 | * @param string $lang 语言名 |
| 1421 | 1421 | * @return string|Request |
| 1422 | 1422 | */ |
| 1423 | - public function langset($lang = null) |
|
| 1423 | + public function langset($lang=null) |
|
| 1424 | 1424 | { |
| 1425 | 1425 | if (!is_null($lang)) { |
| 1426 | - $this->langset = $lang; |
|
| 1426 | + $this->langset=$lang; |
|
| 1427 | 1427 | return $this; |
| 1428 | 1428 | } else { |
| 1429 | 1429 | return $this->langset ?: ''; |
@@ -1438,7 +1438,7 @@ discard block |
||
| 1438 | 1438 | public function getContent() |
| 1439 | 1439 | { |
| 1440 | 1440 | if (is_null($this->content)) { |
| 1441 | - $this->content = $this->input; |
|
| 1441 | + $this->content=$this->input; |
|
| 1442 | 1442 | } |
| 1443 | 1443 | return $this->content; |
| 1444 | 1444 | } |
@@ -1460,12 +1460,12 @@ discard block |
||
| 1460 | 1460 | * @param mixed $type 令牌生成方法 |
| 1461 | 1461 | * @return string |
| 1462 | 1462 | */ |
| 1463 | - public function token($name = '__token__', $type = 'md5') |
|
| 1463 | + public function token($name='__token__', $type='md5') |
|
| 1464 | 1464 | { |
| 1465 | - $type = is_callable($type) ? $type : 'md5'; |
|
| 1466 | - $token = call_user_func($type, $_SERVER['REQUEST_TIME_FLOAT']); |
|
| 1465 | + $type=is_callable($type) ? $type : 'md5'; |
|
| 1466 | + $token=call_user_func($type, $_SERVER['REQUEST_TIME_FLOAT']); |
|
| 1467 | 1467 | if ($this->isAjax()) { |
| 1468 | - header($name . ': ' . $token); |
|
| 1468 | + header($name.': '.$token); |
|
| 1469 | 1469 | } |
| 1470 | 1470 | Session::set($name, $token); |
| 1471 | 1471 | return $token; |
@@ -1479,17 +1479,17 @@ discard block |
||
| 1479 | 1479 | * @param array $except 缓存排除 |
| 1480 | 1480 | * @return void |
| 1481 | 1481 | */ |
| 1482 | - public function cache($key, $expire = null, $except = []) |
|
| 1482 | + public function cache($key, $expire=null, $except=[]) |
|
| 1483 | 1483 | { |
| 1484 | 1484 | if (false !== $key && $this->isGet() && !$this->isCheckCache) { |
| 1485 | 1485 | // 标记请求缓存检查 |
| 1486 | - $this->isCheckCache = true; |
|
| 1486 | + $this->isCheckCache=true; |
|
| 1487 | 1487 | if (false === $expire) { |
| 1488 | 1488 | // 关闭当前缓存 |
| 1489 | 1489 | return; |
| 1490 | 1490 | } |
| 1491 | 1491 | if ($key instanceof \Closure) { |
| 1492 | - $key = call_user_func_array($key, [$this]); |
|
| 1492 | + $key=call_user_func_array($key, [$this]); |
|
| 1493 | 1493 | } elseif (true === $key) { |
| 1494 | 1494 | foreach ($except as $rule) { |
| 1495 | 1495 | if (0 === strpos($this->url(), $rule)) { |
@@ -1497,44 +1497,44 @@ discard block |
||
| 1497 | 1497 | } |
| 1498 | 1498 | } |
| 1499 | 1499 | // 自动缓存功能 |
| 1500 | - $key = md5($this->host()) . '__URL__'; |
|
| 1500 | + $key=md5($this->host()).'__URL__'; |
|
| 1501 | 1501 | } elseif (strpos($key, '|')) { |
| 1502 | - list($key, $fun) = explode('|', $key); |
|
| 1502 | + list($key, $fun)=explode('|', $key); |
|
| 1503 | 1503 | } |
| 1504 | 1504 | // 特殊规则替换 |
| 1505 | 1505 | if (false !== strpos($key, '__')) { |
| 1506 | - $key = str_replace(['__MODULE__', '__CONTROLLER__', '__ACTION__', '__URL__', ''], [$this->module, $this->controller, $this->action, md5($this->url())], $key); |
|
| 1506 | + $key=str_replace(['__MODULE__', '__CONTROLLER__', '__ACTION__', '__URL__', ''], [$this->module, $this->controller, $this->action, md5($this->url())], $key); |
|
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | 1509 | if (false !== strpos($key, ':')) { |
| 1510 | - $param = $this->param(); |
|
| 1510 | + $param=$this->param(); |
|
| 1511 | 1511 | foreach ($param as $item => $val) { |
| 1512 | - if (is_string($val) && false !== strpos($key, ':' . $item)) { |
|
| 1513 | - $key = str_replace(':' . $item, $val, $key); |
|
| 1512 | + if (is_string($val) && false !== strpos($key, ':'.$item)) { |
|
| 1513 | + $key=str_replace(':'.$item, $val, $key); |
|
| 1514 | 1514 | } |
| 1515 | 1515 | } |
| 1516 | 1516 | } elseif (strpos($key, ']')) { |
| 1517 | - if ('[' . $this->ext() . ']' == $key) { |
|
| 1517 | + if ('['.$this->ext().']' == $key) { |
|
| 1518 | 1518 | // 缓存某个后缀的请求 |
| 1519 | - $key = md5($this->url()); |
|
| 1519 | + $key=md5($this->url()); |
|
| 1520 | 1520 | } else { |
| 1521 | 1521 | return; |
| 1522 | 1522 | } |
| 1523 | 1523 | } |
| 1524 | 1524 | if (isset($fun)) { |
| 1525 | - $key = $fun($key); |
|
| 1525 | + $key=$fun($key); |
|
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | 1528 | if (strtotime($this->server('HTTP_IF_MODIFIED_SINCE')) + $expire > $_SERVER['REQUEST_TIME']) { |
| 1529 | 1529 | // 读取缓存 |
| 1530 | - $response = Response::create()->code(304); |
|
| 1530 | + $response=Response::create()->code(304); |
|
| 1531 | 1531 | throw new \think\exception\HttpResponseException($response); |
| 1532 | 1532 | } elseif (Cache::has($key)) { |
| 1533 | - list($content, $header) = Cache::get($key); |
|
| 1534 | - $response = Response::create($content)->header($header); |
|
| 1533 | + list($content, $header)=Cache::get($key); |
|
| 1534 | + $response=Response::create($content)->header($header); |
|
| 1535 | 1535 | throw new \think\exception\HttpResponseException($response); |
| 1536 | 1536 | } else { |
| 1537 | - $this->cache = [$key, $expire]; |
|
| 1537 | + $this->cache=[$key, $expire]; |
|
| 1538 | 1538 | } |
| 1539 | 1539 | } |
| 1540 | 1540 | } |
@@ -1556,12 +1556,12 @@ discard block |
||
| 1556 | 1556 | * @param mixed $obj 绑定的对象实例 |
| 1557 | 1557 | * @return mixed |
| 1558 | 1558 | */ |
| 1559 | - public function bind($name, $obj = null) |
|
| 1559 | + public function bind($name, $obj=null) |
|
| 1560 | 1560 | { |
| 1561 | 1561 | if (is_array($name)) { |
| 1562 | - $this->bind = array_merge($this->bind, $name); |
|
| 1562 | + $this->bind=array_merge($this->bind, $name); |
|
| 1563 | 1563 | } else { |
| 1564 | - $this->bind[$name] = $obj; |
|
| 1564 | + $this->bind[$name]=$obj; |
|
| 1565 | 1565 | } |
| 1566 | 1566 | } |
| 1567 | 1567 | |
@@ -1572,7 +1572,7 @@ discard block |
||
| 1572 | 1572 | |
| 1573 | 1573 | public function __set($name, $value) |
| 1574 | 1574 | { |
| 1575 | - $this->bind[$name] = $value; |
|
| 1575 | + $this->bind[$name]=$value; |
|
| 1576 | 1576 | } |
| 1577 | 1577 | |
| 1578 | 1578 | public function __get($name) |
@@ -260,7 +260,7 @@ |
||
| 260 | 260 | * Check if an item or items exist in an array using "dot" notation. |
| 261 | 261 | * |
| 262 | 262 | * @param \ArrayAccess|array $array |
| 263 | - * @param string|array $keys |
|
| 263 | + * @param string $keys |
|
| 264 | 264 | * @return bool |
| 265 | 265 | */ |
| 266 | 266 | public static function has($array, $keys) { |
@@ -42,16 +42,16 @@ discard block |
||
| 42 | 42 | * @return array |
| 43 | 43 | */ |
| 44 | 44 | public static function collapse($array) { |
| 45 | - $results = []; |
|
| 45 | + $results=[]; |
|
| 46 | 46 | |
| 47 | 47 | foreach ($array as $values) { |
| 48 | 48 | if ($values instanceof Collection) { |
| 49 | - $values = $values->all(); |
|
| 49 | + $values=$values->all(); |
|
| 50 | 50 | } elseif (!is_array($values)) { |
| 51 | 51 | continue; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $results = array_merge($results, $values); |
|
| 54 | + $results=array_merge($results, $values); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | return $results; |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * @param string $prepend |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - public static function dot($array, $prepend = '') { |
|
| 78 | - $results = []; |
|
| 77 | + public static function dot($array, $prepend='') { |
|
| 78 | + $results=[]; |
|
| 79 | 79 | |
| 80 | 80 | foreach ($array as $key => $value) { |
| 81 | 81 | if (is_array($value) && !empty($value)) { |
| 82 | - $results = array_merge($results, static::dot($value, $prepend . $key . '.')); |
|
| 82 | + $results=array_merge($results, static::dot($value, $prepend.$key.'.')); |
|
| 83 | 83 | } else { |
| 84 | - $results[$prepend . $key] = $value; |
|
| 84 | + $results[$prepend.$key]=$value; |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @param mixed $default |
| 125 | 125 | * @return mixed |
| 126 | 126 | */ |
| 127 | - public static function first($array, callable $callback = null, $default = null) { |
|
| 127 | + public static function first($array, callable $callback=null, $default=null) { |
|
| 128 | 128 | if (is_null($callback)) { |
| 129 | 129 | if (empty($array)) { |
| 130 | 130 | return value($default); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @param mixed $default |
| 153 | 153 | * @return mixed |
| 154 | 154 | */ |
| 155 | - public static function last($array, callable $callback = null, $default = null) { |
|
| 155 | + public static function last($array, callable $callback=null, $default=null) { |
|
| 156 | 156 | if (is_null($callback)) { |
| 157 | 157 | return empty($array) ? value($default) : end($array); |
| 158 | 158 | } |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | * @param int $depth |
| 168 | 168 | * @return array |
| 169 | 169 | */ |
| 170 | - public static function flatten($array, $depth = INF) { |
|
| 171 | - return array_reduce($array, function ($result, $item) use ($depth) { |
|
| 172 | - $item = $item instanceof Collection ? $item->all() : $item; |
|
| 170 | + public static function flatten($array, $depth=INF) { |
|
| 171 | + return array_reduce($array, function($result, $item) use ($depth) { |
|
| 172 | + $item=$item instanceof Collection ? $item->all() : $item; |
|
| 173 | 173 | |
| 174 | 174 | if (!is_array($item)) { |
| 175 | 175 | return array_merge($result, [$item]); |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | * @return void |
| 190 | 190 | */ |
| 191 | 191 | public static function forget(&$array, $keys) { |
| 192 | - $original = &$array; |
|
| 192 | + $original=&$array; |
|
| 193 | 193 | |
| 194 | - $keys = (array)$keys; |
|
| 194 | + $keys=(array) $keys; |
|
| 195 | 195 | |
| 196 | 196 | if (count($keys) === 0) { |
| 197 | 197 | return; |
@@ -205,16 +205,16 @@ discard block |
||
| 205 | 205 | continue; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $parts = explode('.', $key); |
|
| 208 | + $parts=explode('.', $key); |
|
| 209 | 209 | |
| 210 | 210 | // clean up before each pass |
| 211 | - $array = &$original; |
|
| 211 | + $array=&$original; |
|
| 212 | 212 | |
| 213 | 213 | while (count($parts) > 1) { |
| 214 | - $part = array_shift($parts); |
|
| 214 | + $part=array_shift($parts); |
|
| 215 | 215 | |
| 216 | 216 | if (isset($array[$part]) && is_array($array[$part])) { |
| 217 | - $array = &$array[$part]; |
|
| 217 | + $array=&$array[$part]; |
|
| 218 | 218 | } else { |
| 219 | 219 | continue 2; |
| 220 | 220 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @param mixed $default |
| 233 | 233 | * @return mixed |
| 234 | 234 | */ |
| 235 | - public static function get($array, $key, $default = null) { |
|
| 235 | + public static function get($array, $key, $default=null) { |
|
| 236 | 236 | if (!static::accessible($array)) { |
| 237 | 237 | return value($default); |
| 238 | 238 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | foreach (explode('.', $key) as $segment) { |
| 249 | 249 | if (static::accessible($array) && static::exists($array, $segment)) { |
| 250 | - $array = $array[$segment]; |
|
| 250 | + $array=$array[$segment]; |
|
| 251 | 251 | } else { |
| 252 | 252 | return value($default); |
| 253 | 253 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | return false; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - $keys = (array)$keys; |
|
| 271 | + $keys=(array) $keys; |
|
| 272 | 272 | |
| 273 | 273 | if (!$array) { |
| 274 | 274 | return false; |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | foreach ($keys as $key) { |
| 282 | - $subKeyArray = $array; |
|
| 282 | + $subKeyArray=$array; |
|
| 283 | 283 | |
| 284 | 284 | if (static::exists($array, $key)) { |
| 285 | 285 | continue; |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | foreach (explode('.', $key) as $segment) { |
| 289 | 289 | if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) { |
| 290 | - $subKeyArray = $subKeyArray[$segment]; |
|
| 290 | + $subKeyArray=$subKeyArray[$segment]; |
|
| 291 | 291 | } else { |
| 292 | 292 | return false; |
| 293 | 293 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * @return bool |
| 307 | 307 | */ |
| 308 | 308 | public static function isAssoc(array $array) { |
| 309 | - $keys = array_keys($array); |
|
| 309 | + $keys=array_keys($array); |
|
| 310 | 310 | |
| 311 | 311 | return array_keys($keys) !== $keys; |
| 312 | 312 | } |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | return false; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - return (bool)count(array_filter($array, 'is_array')); |
|
| 327 | + return (bool) count(array_filter($array, 'is_array')); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | * @return array |
| 336 | 336 | */ |
| 337 | 337 | public static function only($array, $keys) { |
| 338 | - return array_intersect_key($array, array_flip((array)$keys)); |
|
| 338 | + return array_intersect_key($array, array_flip((array) $keys)); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -346,23 +346,23 @@ discard block |
||
| 346 | 346 | * @param string|array|null $key |
| 347 | 347 | * @return array |
| 348 | 348 | */ |
| 349 | - public static function pluck($array, $value, $key = null) { |
|
| 350 | - $results = []; |
|
| 349 | + public static function pluck($array, $value, $key=null) { |
|
| 350 | + $results=[]; |
|
| 351 | 351 | |
| 352 | - list($value, $key) = static::explodePluckParameters($value, $key); |
|
| 352 | + list($value, $key)=static::explodePluckParameters($value, $key); |
|
| 353 | 353 | |
| 354 | 354 | foreach ($array as $item) { |
| 355 | - $itemValue = data_get($item, $value); |
|
| 355 | + $itemValue=data_get($item, $value); |
|
| 356 | 356 | |
| 357 | 357 | // If the key is "null", we will just append the value to the array and keep |
| 358 | 358 | // looping. Otherwise we will key the array using the value of the key we |
| 359 | 359 | // received from the developer. Then we'll return the final array form. |
| 360 | 360 | if (is_null($key)) { |
| 361 | - $results[] = $itemValue; |
|
| 361 | + $results[]=$itemValue; |
|
| 362 | 362 | } else { |
| 363 | - $itemKey = data_get($item, $key); |
|
| 363 | + $itemKey=data_get($item, $key); |
|
| 364 | 364 | |
| 365 | - $results[$itemKey] = $itemValue; |
|
| 365 | + $results[$itemKey]=$itemValue; |
|
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | |
@@ -377,9 +377,9 @@ discard block |
||
| 377 | 377 | * @return array |
| 378 | 378 | */ |
| 379 | 379 | protected static function explodePluckParameters($value, $key) { |
| 380 | - $value = is_string($value) ? explode('.', $value) : $value; |
|
| 380 | + $value=is_string($value) ? explode('.', $value) : $value; |
|
| 381 | 381 | |
| 382 | - $key = is_null($key) || is_array($key) ? $key : explode('.', $key); |
|
| 382 | + $key=is_null($key) || is_array($key) ? $key : explode('.', $key); |
|
| 383 | 383 | |
| 384 | 384 | return [$value, $key]; |
| 385 | 385 | } |
@@ -392,11 +392,11 @@ discard block |
||
| 392 | 392 | * @param mixed $key |
| 393 | 393 | * @return array |
| 394 | 394 | */ |
| 395 | - public static function prepend($array, $value, $key = null) { |
|
| 395 | + public static function prepend($array, $value, $key=null) { |
|
| 396 | 396 | if (is_null($key)) { |
| 397 | 397 | array_unshift($array, $value); |
| 398 | 398 | } else { |
| 399 | - $array = [$key => $value] + $array; |
|
| 399 | + $array=[$key => $value] + $array; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | return $array; |
@@ -410,8 +410,8 @@ discard block |
||
| 410 | 410 | * @param mixed $default |
| 411 | 411 | * @return mixed |
| 412 | 412 | */ |
| 413 | - public static function pull(&$array, $key, $default = null) { |
|
| 414 | - $value = static::get($array, $key, $default); |
|
| 413 | + public static function pull(&$array, $key, $default=null) { |
|
| 414 | + $value=static::get($array, $key, $default); |
|
| 415 | 415 | |
| 416 | 416 | static::forget($array, $key); |
| 417 | 417 | |
@@ -430,25 +430,25 @@ discard block |
||
| 430 | 430 | */ |
| 431 | 431 | public static function set(&$array, $key, $value) { |
| 432 | 432 | if (is_null($key)) { |
| 433 | - return $array = $value; |
|
| 433 | + return $array=$value; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - $keys = explode('.', $key); |
|
| 436 | + $keys=explode('.', $key); |
|
| 437 | 437 | |
| 438 | 438 | while (count($keys) > 1) { |
| 439 | - $key = array_shift($keys); |
|
| 439 | + $key=array_shift($keys); |
|
| 440 | 440 | |
| 441 | 441 | // If the key doesn't exist at this depth, we will just create an empty array |
| 442 | 442 | // to hold the next value, allowing us to create the arrays to hold final |
| 443 | 443 | // values at the correct depth. Then we'll keep digging into the array. |
| 444 | 444 | if (!isset($array[$key]) || !is_array($array[$key])) { |
| 445 | - $array[$key] = []; |
|
| 445 | + $array[$key]=[]; |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | - $array = &$array[$key]; |
|
| 448 | + $array=&$array[$key]; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $array[array_shift($keys)] = $value; |
|
| 451 | + $array[array_shift($keys)]=$value; |
|
| 452 | 452 | |
| 453 | 453 | return $array; |
| 454 | 454 | } |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | public static function sortRecursive($array) { |
| 486 | 486 | foreach ($array as &$value) { |
| 487 | 487 | if (is_array($value)) { |
| 488 | - $value = static::sortRecursive($value); |
|
| 488 | + $value=static::sortRecursive($value); |
|
| 489 | 489 | } |
| 490 | 490 | } |
| 491 | 491 | |
@@ -98,8 +98,7 @@ |
||
| 98 | 98 | } |
| 99 | 99 | } catch (\ReflectionException $e) { |
| 100 | 100 | return false; |
| 101 | - } |
|
| 102 | - catch (\InvalidArgumentException $e) { |
|
| 101 | + } catch (\InvalidArgumentException $e) { |
|
| 103 | 102 | return false; |
| 104 | 103 | } |
| 105 | 104 | return true; |
@@ -9,18 +9,18 @@ discard block |
||
| 9 | 9 | private $request; |
| 10 | 10 | |
| 11 | 11 | public function __construct(Request $request) { |
| 12 | - $this->request = $request; |
|
| 13 | - $this->errorCallback=function (){ |
|
| 12 | + $this->request=$request; |
|
| 13 | + $this->errorCallback=function() { |
|
| 14 | 14 | die("404"); |
| 15 | 15 | }; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public static $halts = false; |
|
| 19 | - private $routes = array(); |
|
| 20 | - private $regexRoutes = []; |
|
| 21 | - public static $methods = array(); |
|
| 22 | - public static $callbacks = array(); |
|
| 23 | - private $patterns = array( |
|
| 18 | + public static $halts=false; |
|
| 19 | + private $routes=array(); |
|
| 20 | + private $regexRoutes=[]; |
|
| 21 | + public static $methods=array(); |
|
| 22 | + public static $callbacks=array(); |
|
| 23 | + private $patterns=array( |
|
| 24 | 24 | ':any' => '[^/]+', |
| 25 | 25 | ':num' => '[0-9]+', |
| 26 | 26 | ':all' => '.*' |
@@ -41,29 +41,29 @@ discard block |
||
| 41 | 41 | * @param mixed $callBack |
| 42 | 42 | */ |
| 43 | 43 | public function addRoute($method, $uri, $callBack) { |
| 44 | - $method = strtoupper($method); |
|
| 44 | + $method=strtoupper($method); |
|
| 45 | 45 | //预定义正则路由 |
| 46 | 46 | if (strpos($uri, ':') !== false) { |
| 47 | - $searches = array_keys($this->patterns); |
|
| 48 | - $replaces = array_values($this->patterns); |
|
| 49 | - $uri = str_replace($searches, $replaces, $uri); |
|
| 50 | - $this->regexRoutes[] = [ |
|
| 47 | + $searches=array_keys($this->patterns); |
|
| 48 | + $replaces=array_values($this->patterns); |
|
| 49 | + $uri=str_replace($searches, $replaces, $uri); |
|
| 50 | + $this->regexRoutes[]=[ |
|
| 51 | 51 | 'method' => $method, |
| 52 | - 'regex' => '#^' . $uri . '$#', |
|
| 52 | + 'regex' => '#^'.$uri.'$#', |
|
| 53 | 53 | 'callback' => $callBack |
| 54 | 54 | ]; |
| 55 | 55 | } //自定义正则路由 |
| 56 | 56 | elseif ($uri[0] == '#' |
| 57 | 57 | || (strlen($uri) > 2 && tools\Str::endsWith($uri, '/') && tools\Str::startsWith($uri, '/')) |
| 58 | 58 | ) { |
| 59 | - $this->regexRoutes[] = [ |
|
| 59 | + $this->regexRoutes[]=[ |
|
| 60 | 60 | 'method' => $method, |
| 61 | 61 | 'regex' => $uri, |
| 62 | 62 | 'callback' => $callBack |
| 63 | 63 | ]; |
| 64 | 64 | } //直接定义的路由 |
| 65 | 65 | else { |
| 66 | - $this->routes[$method . $uri] = [ |
|
| 66 | + $this->routes[$method.$uri]=[ |
|
| 67 | 67 | 'method' => $method, |
| 68 | 68 | 'uri' => $uri, |
| 69 | 69 | 'callback' => $callBack |
@@ -75,25 +75,25 @@ discard block |
||
| 75 | 75 | * Defines callback if route is not found |
| 76 | 76 | */ |
| 77 | 77 | public function error($callback) { |
| 78 | - $this->errorCallback = $callback; |
|
| 78 | + $this->errorCallback=$callback; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - public static function haltOnMatch($flag = true) { |
|
| 82 | - self::$halts = $flag; |
|
| 81 | + public static function haltOnMatch($flag=true) { |
|
| 82 | + self::$halts=$flag; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | |
| 86 | - private function foundRoute($route, $param = []) { |
|
| 86 | + private function foundRoute($route, $param=[]) { |
|
| 87 | 87 | try { |
| 88 | 88 | if ($route['callback'] instanceof \Closure) { |
| 89 | - app()->invokeFunction($route['callback'],$param); |
|
| 89 | + app()->invokeFunction($route['callback'], $param); |
|
| 90 | 90 | } else { |
| 91 | 91 | // Grab all parts based on a / separator |
| 92 | - $parts = explode('/', $route['callback']); |
|
| 92 | + $parts=explode('/', $route['callback']); |
|
| 93 | 93 | // Collect the last index of the array |
| 94 | - $last = end($parts); |
|
| 94 | + $last=end($parts); |
|
| 95 | 95 | // Grab the controller name and method call |
| 96 | - $segments = explode('@', $last); |
|
| 96 | + $segments=explode('@', $last); |
|
| 97 | 97 | app()->invokeMethod($segments, $param); |
| 98 | 98 | } |
| 99 | 99 | } catch (\ReflectionException $e) { |
@@ -125,20 +125,20 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function dispatch() { |
| 127 | 127 | $uri=$this->request->path(); |
| 128 | - $current['uri'] = $uri?$uri:'/'; |
|
| 129 | - $current['method'] = $this->request->method(); |
|
| 128 | + $current['uri']=$uri ? $uri : '/'; |
|
| 129 | + $current['method']=$this->request->method(); |
|
| 130 | 130 | # 第一种情况,直接命中 |
| 131 | - if (isset($this->routes[$current['method'] . $current['uri']])) { |
|
| 132 | - $this->foundRoute($this->routes[$current['method'] . $current['uri']]); |
|
| 131 | + if (isset($this->routes[$current['method'].$current['uri']])) { |
|
| 132 | + $this->foundRoute($this->routes[$current['method'].$current['uri']]); |
|
| 133 | 133 | } # 第二种情况,any命中 |
| 134 | - else if (isset($this->routes['ANY' . $current['uri']])) { |
|
| 135 | - $this->foundRoute($this->routes['ANY' . $current['method']]); |
|
| 134 | + else if (isset($this->routes['ANY'.$current['uri']])) { |
|
| 135 | + $this->foundRoute($this->routes['ANY'.$current['method']]); |
|
| 136 | 136 | } # 第三种情况,正则命中 |
| 137 | 137 | else { |
| 138 | 138 | if ($this->foundRegexRoute($current)) { |
| 139 | 139 | |
| 140 | 140 | } else { |
| 141 | - $route['callback'] = $this->errorCallback; |
|
| 141 | + $route['callback']=$this->errorCallback; |
|
| 142 | 142 | $this->foundRoute($route); |
| 143 | 143 | } |
| 144 | 144 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * Progress |
| 228 | 228 | * |
| 229 | 229 | * @access public |
| 230 | - * @param $callback |
|
| 230 | + * @param \Closure $callback |
|
| 231 | 231 | */ |
| 232 | 232 | public function progress($callback) |
| 233 | 233 | { |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * Download Complete |
| 264 | 264 | * |
| 265 | 265 | * @access private |
| 266 | - * @param $fh |
|
| 266 | + * @param resource $fh |
|
| 267 | 267 | */ |
| 268 | 268 | private function downloadComplete($fh) |
| 269 | 269 | { |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | * Get Info |
| 443 | 443 | * |
| 444 | 444 | * @access public |
| 445 | - * @param $opt |
|
| 445 | + * @param integer $opt |
|
| 446 | 446 | * |
| 447 | 447 | * @return mixed |
| 448 | 448 | */ |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | * Get Opt |
| 463 | 463 | * |
| 464 | 464 | * @access public |
| 465 | - * @param $option |
|
| 465 | + * @param integer $option |
|
| 466 | 466 | * |
| 467 | 467 | * @return mixed |
| 468 | 468 | */ |
@@ -1105,7 +1105,7 @@ discard block |
||
| 1105 | 1105 | * Set Timeout |
| 1106 | 1106 | * |
| 1107 | 1107 | * @access public |
| 1108 | - * @param $seconds |
|
| 1108 | + * @param integer $seconds |
|
| 1109 | 1109 | */ |
| 1110 | 1110 | public function setTimeout($seconds) |
| 1111 | 1111 | { |
@@ -1130,7 +1130,7 @@ discard block |
||
| 1130 | 1130 | * Set User Agent |
| 1131 | 1131 | * |
| 1132 | 1132 | * @access public |
| 1133 | - * @param $user_agent |
|
| 1133 | + * @param string $user_agent |
|
| 1134 | 1134 | */ |
| 1135 | 1135 | public function setUserAgent($user_agent) |
| 1136 | 1136 | { |
@@ -1173,7 +1173,7 @@ discard block |
||
| 1173 | 1173 | * Using `curl -H "Host:" ...' is equivalent to $curl->removeHeader('Host');. |
| 1174 | 1174 | * |
| 1175 | 1175 | * @access public |
| 1176 | - * @param $key |
|
| 1176 | + * @param string $key |
|
| 1177 | 1177 | */ |
| 1178 | 1178 | public function removeHeader($key) |
| 1179 | 1179 | { |
@@ -1360,7 +1360,7 @@ discard block |
||
| 1360 | 1360 | * Parse Response Headers |
| 1361 | 1361 | * |
| 1362 | 1362 | * @access private |
| 1363 | - * @param $raw_response_headers |
|
| 1363 | + * @param string $raw_response_headers |
|
| 1364 | 1364 | * |
| 1365 | 1365 | * @return array |
| 1366 | 1366 | */ |
@@ -9,53 +9,53 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | class Curl { |
| 11 | 11 | |
| 12 | - const VERSION = '7.2.0'; |
|
| 13 | - const DEFAULT_TIMEOUT = 20; |
|
| 12 | + const VERSION='7.2.0'; |
|
| 13 | + const DEFAULT_TIMEOUT=20; |
|
| 14 | 14 | |
| 15 | - public $retryCount = 3; |
|
| 15 | + public $retryCount=3; |
|
| 16 | 16 | |
| 17 | 17 | public $curl; |
| 18 | - public $id = null; |
|
| 19 | - |
|
| 20 | - public $error = false; |
|
| 21 | - public $errorCode = 0; |
|
| 22 | - public $errorMessage = null; |
|
| 23 | - |
|
| 24 | - public $curlError = false; |
|
| 25 | - public $curlErrorCode = 0; |
|
| 26 | - public $curlErrorMessage = null; |
|
| 27 | - |
|
| 28 | - public $httpError = false; |
|
| 29 | - public $httpStatusCode = 0; |
|
| 30 | - public $httpErrorMessage = null; |
|
| 31 | - |
|
| 32 | - public $baseUrl = null; |
|
| 33 | - public $url = null; |
|
| 34 | - public $requestHeaders = null; |
|
| 35 | - public $responseHeaders = null; |
|
| 36 | - public $rawResponseHeaders = ''; |
|
| 37 | - public $responseCookies = array(); |
|
| 38 | - public $response = null; |
|
| 39 | - public $rawResponse = null; |
|
| 40 | - |
|
| 41 | - public $beforeSendFunction = null; |
|
| 42 | - public $downloadCompleteFunction = null; |
|
| 43 | - public $successFunction = null; |
|
| 44 | - public $errorFunction = null; |
|
| 45 | - public $completeFunction = null; |
|
| 46 | - public $fileHandle = null; |
|
| 47 | - |
|
| 48 | - private $cookies = array(); |
|
| 49 | - private $headers = array(); |
|
| 50 | - private $options = array(); |
|
| 51 | - |
|
| 52 | - private $jsonDecoder = null; |
|
| 53 | - private $jsonPattern = '/^(?:application|text)\/(?:[a-z]+(?:[\.-][0-9a-z]+){0,}[\+\.]|x-)?json(?:-[a-z]+)?/i'; |
|
| 54 | - private $xmlDecoder = null; |
|
| 55 | - private $xmlPattern = '~^(?:text/|application/(?:atom\+|rss\+)?)xml~i'; |
|
| 56 | - private $defaultDecoder = null; |
|
| 57 | - |
|
| 58 | - public static $RFC2616 = array( |
|
| 18 | + public $id=null; |
|
| 19 | + |
|
| 20 | + public $error=false; |
|
| 21 | + public $errorCode=0; |
|
| 22 | + public $errorMessage=null; |
|
| 23 | + |
|
| 24 | + public $curlError=false; |
|
| 25 | + public $curlErrorCode=0; |
|
| 26 | + public $curlErrorMessage=null; |
|
| 27 | + |
|
| 28 | + public $httpError=false; |
|
| 29 | + public $httpStatusCode=0; |
|
| 30 | + public $httpErrorMessage=null; |
|
| 31 | + |
|
| 32 | + public $baseUrl=null; |
|
| 33 | + public $url=null; |
|
| 34 | + public $requestHeaders=null; |
|
| 35 | + public $responseHeaders=null; |
|
| 36 | + public $rawResponseHeaders=''; |
|
| 37 | + public $responseCookies=array(); |
|
| 38 | + public $response=null; |
|
| 39 | + public $rawResponse=null; |
|
| 40 | + |
|
| 41 | + public $beforeSendFunction=null; |
|
| 42 | + public $downloadCompleteFunction=null; |
|
| 43 | + public $successFunction=null; |
|
| 44 | + public $errorFunction=null; |
|
| 45 | + public $completeFunction=null; |
|
| 46 | + public $fileHandle=null; |
|
| 47 | + |
|
| 48 | + private $cookies=array(); |
|
| 49 | + private $headers=array(); |
|
| 50 | + private $options=array(); |
|
| 51 | + |
|
| 52 | + private $jsonDecoder=null; |
|
| 53 | + private $jsonPattern='/^(?:application|text)\/(?:[a-z]+(?:[\.-][0-9a-z]+){0,}[\+\.]|x-)?json(?:-[a-z]+)?/i'; |
|
| 54 | + private $xmlDecoder=null; |
|
| 55 | + private $xmlPattern='~^(?:text/|application/(?:atom\+|rss\+)?)xml~i'; |
|
| 56 | + private $defaultDecoder=null; |
|
| 57 | + |
|
| 58 | + public static $RFC2616=array( |
|
| 59 | 59 | // RFC2616: "any CHAR except CTLs or separators". |
| 60 | 60 | // CHAR = <any US-ASCII character (octets 0 - 127)> |
| 61 | 61 | // CTL = <any US-ASCII control character |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | 'Y', 'Z', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', |
| 73 | 73 | 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '|', '~', |
| 74 | 74 | ); |
| 75 | - public static $RFC6265 = array( |
|
| 75 | + public static $RFC6265=array( |
|
| 76 | 76 | // RFC6265: "US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash". |
| 77 | 77 | // %x21 |
| 78 | 78 | '!', |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', |
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | - private static $deferredProperties = array( |
|
| 91 | + private static $deferredProperties=array( |
|
| 92 | 92 | 'effectiveUrl', |
| 93 | 93 | 'rfc2616', |
| 94 | 94 | 'rfc6265', |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | * @param $base_url |
| 103 | 103 | * @throws \ErrorException |
| 104 | 104 | */ |
| 105 | - public function __construct($base_url = null) |
|
| 105 | + public function __construct($base_url=null) |
|
| 106 | 106 | { |
| 107 | 107 | if (!extension_loaded('curl')) { |
| 108 | 108 | throw new \ErrorException('cURL library is not loaded'); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $this->curl = curl_init(); |
|
| 112 | - $this->id = uniqid('', true); |
|
| 111 | + $this->curl=curl_init(); |
|
| 112 | + $this->id=uniqid('', true); |
|
| 113 | 113 | $this->setDefaultUserAgent(); |
| 114 | 114 | $this->setDefaultJsonDecoder(); |
| 115 | 115 | $this->setDefaultXmlDecoder(); |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $this->setOpt(CURLINFO_HEADER_OUT, true); |
| 118 | 118 | $this->setOpt(CURLOPT_HEADERFUNCTION, array($this, 'headerCallback')); |
| 119 | 119 | $this->setOpt(CURLOPT_RETURNTRANSFER, true); |
| 120 | - $this->headers = []; |
|
| 120 | + $this->headers=[]; |
|
| 121 | 121 | $this->setUrl($base_url); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function beforeSend($callback) |
| 131 | 131 | { |
| 132 | - $this->beforeSendFunction = $callback; |
|
| 132 | + $this->beforeSendFunction=$callback; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -142,21 +142,21 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function buildPostData($data) |
| 144 | 144 | { |
| 145 | - $binary_data = false; |
|
| 145 | + $binary_data=false; |
|
| 146 | 146 | if (is_array($data)) { |
| 147 | 147 | // Return JSON-encoded string when the request's content-type is JSON. |
| 148 | 148 | if (isset($this->headers['Content-Type']) && |
| 149 | 149 | preg_match($this->jsonPattern, $this->headers['Content-Type'])) { |
| 150 | - $json_str = json_encode($data); |
|
| 150 | + $json_str=json_encode($data); |
|
| 151 | 151 | if (!($json_str === false)) { |
| 152 | - $data = $json_str; |
|
| 152 | + $data=$json_str; |
|
| 153 | 153 | } |
| 154 | 154 | } else { |
| 155 | 155 | // Manually build a single-dimensional array from a multi-dimensional array as using curl_setopt($ch, |
| 156 | 156 | // CURLOPT_POSTFIELDS, $data) doesn't correctly handle multi-dimensional arrays when files are |
| 157 | 157 | // referenced. |
| 158 | 158 | if (Arr::isMultidim($data)) { |
| 159 | - $data = Arr::flatten($data); |
|
| 159 | + $data=Arr::flatten($data); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // Modify array values to ensure any referenced files are properly handled depending on the support of |
@@ -165,19 +165,19 @@ discard block |
||
| 165 | 165 | // non-file values prefixed with the @ character. |
| 166 | 166 | foreach ($data as $key => $value) { |
| 167 | 167 | if (is_string($value) && strpos($value, '@') === 0 && is_file(substr($value, 1))) { |
| 168 | - $binary_data = true; |
|
| 168 | + $binary_data=true; |
|
| 169 | 169 | if (class_exists('CURLFile')) { |
| 170 | - $data[$key] = new \CURLFile(substr($value, 1)); |
|
| 170 | + $data[$key]=new \CURLFile(substr($value, 1)); |
|
| 171 | 171 | } |
| 172 | 172 | } elseif ($value instanceof \CURLFile) { |
| 173 | - $binary_data = true; |
|
| 173 | + $binary_data=true; |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | if (!$binary_data && (is_array($data) || is_object($data))) { |
| 180 | - $data = http_build_query($data, '', '&'); |
|
| 180 | + $data=http_build_query($data, '', '&'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | return $data; |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | public function call() |
| 192 | 192 | { |
| 193 | - $args = func_get_args(); |
|
| 194 | - $function = array_shift($args); |
|
| 193 | + $args=func_get_args(); |
|
| 194 | + $function=array_shift($args); |
|
| 195 | 195 | if (is_callable($function)) { |
| 196 | 196 | array_unshift($args, $this); |
| 197 | 197 | call_user_func_array($function, $args); |
@@ -208,10 +208,10 @@ discard block |
||
| 208 | 208 | if (is_resource($this->curl)) { |
| 209 | 209 | curl_close($this->curl); |
| 210 | 210 | } |
| 211 | - $this->options = null; |
|
| 212 | - $this->jsonDecoder = null; |
|
| 213 | - $this->xmlDecoder = null; |
|
| 214 | - $this->defaultDecoder = null; |
|
| 211 | + $this->options=null; |
|
| 212 | + $this->jsonDecoder=null; |
|
| 213 | + $this->xmlDecoder=null; |
|
| 214 | + $this->defaultDecoder=null; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | public function complete($callback) |
| 224 | 224 | { |
| 225 | - $this->completeFunction = $callback; |
|
| 225 | + $this->completeFunction=$callback; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -247,12 +247,12 @@ discard block |
||
| 247 | 247 | * |
| 248 | 248 | * @return string |
| 249 | 249 | */ |
| 250 | - public function delete($url, $query_parameters = array(), $data = array()) |
|
| 250 | + public function delete($url, $query_parameters=array(), $data=array()) |
|
| 251 | 251 | { |
| 252 | 252 | if (is_array($url)) { |
| 253 | - $data = $query_parameters; |
|
| 254 | - $query_parameters = $url; |
|
| 255 | - $url = $this->baseUrl; |
|
| 253 | + $data=$query_parameters; |
|
| 254 | + $query_parameters=$url; |
|
| 255 | + $url=$this->baseUrl; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | $this->setUrl($url, $query_parameters); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | if (!$this->error && $this->downloadCompleteFunction) { |
| 273 | 273 | rewind($fh); |
| 274 | 274 | $this->call($this->downloadCompleteFunction, $fh); |
| 275 | - $this->downloadCompleteFunction = null; |
|
| 275 | + $this->downloadCompleteFunction=null; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | if (is_resource($fh)) { |
@@ -308,29 +308,29 @@ discard block |
||
| 308 | 308 | public function download($url, $mixed_filename) |
| 309 | 309 | { |
| 310 | 310 | if (is_callable($mixed_filename)) { |
| 311 | - $this->downloadCompleteFunction = $mixed_filename; |
|
| 312 | - $this->fileHandle = tmpfile(); |
|
| 311 | + $this->downloadCompleteFunction=$mixed_filename; |
|
| 312 | + $this->fileHandle=tmpfile(); |
|
| 313 | 313 | } else { |
| 314 | - $filename = $mixed_filename; |
|
| 314 | + $filename=$mixed_filename; |
|
| 315 | 315 | |
| 316 | 316 | // Use a temporary file when downloading. Not using a temporary file can cause an error when an existing |
| 317 | 317 | // file has already fully completed downloading and a new download is started with the same destination save |
| 318 | 318 | // path. The download request will include header "Range: bytes=$filesize-" which is syntactically valid, |
| 319 | 319 | // but unsatisfiable. |
| 320 | - $download_filename = $filename . '.pccdownload'; |
|
| 320 | + $download_filename=$filename.'.pccdownload'; |
|
| 321 | 321 | |
| 322 | - $mode = 'wb'; |
|
| 322 | + $mode='wb'; |
|
| 323 | 323 | // Attempt to resume download only when a temporary download file exists and is not empty. |
| 324 | - if (file_exists($download_filename) && $filesize = filesize($download_filename)) { |
|
| 325 | - $mode = 'ab'; |
|
| 326 | - $first_byte_position = $filesize; |
|
| 327 | - $range = $first_byte_position . '-'; |
|
| 324 | + if (file_exists($download_filename) && $filesize=filesize($download_filename)) { |
|
| 325 | + $mode='ab'; |
|
| 326 | + $first_byte_position=$filesize; |
|
| 327 | + $range=$first_byte_position.'-'; |
|
| 328 | 328 | $this->setOpt(CURLOPT_RANGE, $range); |
| 329 | 329 | } |
| 330 | - $this->fileHandle = fopen($download_filename, $mode); |
|
| 330 | + $this->fileHandle=fopen($download_filename, $mode); |
|
| 331 | 331 | |
| 332 | 332 | // Move the downloaded temporary file to the destination save path. |
| 333 | - $this->downloadCompleteFunction = function ($fh) use ($download_filename, $filename) { |
|
| 333 | + $this->downloadCompleteFunction=function($fh) use ($download_filename, $filename) { |
|
| 334 | 334 | rename($download_filename, $filename); |
| 335 | 335 | }; |
| 336 | 336 | } |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | $this->setOpt(CURLOPT_FILE, $this->fileHandle); |
| 339 | 339 | $this->get($url); |
| 340 | 340 | |
| 341 | - return ! $this->error; |
|
| 341 | + return !$this->error; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | */ |
| 350 | 350 | public function error($callback) |
| 351 | 351 | { |
| 352 | - $this->errorFunction = $callback; |
|
| 352 | + $this->errorFunction=$callback; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -360,56 +360,56 @@ discard block |
||
| 360 | 360 | * |
| 361 | 361 | * @return mixed Returns the value provided by parseResponse. |
| 362 | 362 | */ |
| 363 | - public function exec($ch = null) |
|
| 363 | + public function exec($ch=null) |
|
| 364 | 364 | { |
| 365 | 365 | if ($ch === null) { |
| 366 | - $this->responseCookies = array(); |
|
| 366 | + $this->responseCookies=array(); |
|
| 367 | 367 | $this->call($this->beforeSendFunction); |
| 368 | 368 | $i=0; |
| 369 | - while(1){ |
|
| 370 | - $this->rawResponse = curl_exec($this->curl); |
|
| 371 | - $this->curlErrorCode = curl_errno($this->curl); |
|
| 372 | - if(($this->curlErrorCode==28 ||$this->curlErrorCode==7) |
|
| 373 | - && $i++ < $this->retryCount){ |
|
| 369 | + while (1) { |
|
| 370 | + $this->rawResponse=curl_exec($this->curl); |
|
| 371 | + $this->curlErrorCode=curl_errno($this->curl); |
|
| 372 | + if (($this->curlErrorCode == 28 || $this->curlErrorCode == 7) |
|
| 373 | + && $i++ < $this->retryCount) { |
|
| 374 | 374 | continue; |
| 375 | 375 | } |
| 376 | 376 | break; |
| 377 | 377 | } |
| 378 | - $this->curlErrorMessage = curl_error($this->curl); |
|
| 378 | + $this->curlErrorMessage=curl_error($this->curl); |
|
| 379 | 379 | } else { |
| 380 | - $this->rawResponse = curl_multi_getcontent($ch); |
|
| 381 | - $this->curlErrorMessage = curl_error($ch); |
|
| 380 | + $this->rawResponse=curl_multi_getcontent($ch); |
|
| 381 | + $this->curlErrorMessage=curl_error($ch); |
|
| 382 | 382 | } |
| 383 | - $this->curlError = !($this->curlErrorCode === 0); |
|
| 383 | + $this->curlError=!($this->curlErrorCode === 0); |
|
| 384 | 384 | // Include additional error code information in error message when possible. |
| 385 | 385 | if ($this->curlError && function_exists('curl_strerror')) { |
| 386 | - $this->curlErrorMessage = |
|
| 387 | - curl_strerror($this->curlErrorCode) . ( |
|
| 388 | - empty($this->curlErrorMessage) ? '' : ': ' . $this->curlErrorMessage |
|
| 386 | + $this->curlErrorMessage= |
|
| 387 | + curl_strerror($this->curlErrorCode).( |
|
| 388 | + empty($this->curlErrorMessage) ? '' : ': '.$this->curlErrorMessage |
|
| 389 | 389 | ); |
| 390 | 390 | print_r($this->rawResponse); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - $this->httpStatusCode = $this->getInfo(CURLINFO_HTTP_CODE); |
|
| 394 | - $this->httpError = in_array(floor($this->httpStatusCode / 100), array(4, 5)); |
|
| 395 | - $this->error = $this->curlError || $this->httpError; |
|
| 396 | - $this->errorCode = $this->error ? ($this->curlError ? $this->curlErrorCode : $this->httpStatusCode) : 0; |
|
| 393 | + $this->httpStatusCode=$this->getInfo(CURLINFO_HTTP_CODE); |
|
| 394 | + $this->httpError=in_array(floor($this->httpStatusCode / 100), array(4, 5)); |
|
| 395 | + $this->error=$this->curlError || $this->httpError; |
|
| 396 | + $this->errorCode=$this->error ? ($this->curlError ? $this->curlErrorCode : $this->httpStatusCode) : 0; |
|
| 397 | 397 | |
| 398 | 398 | // NOTE: CURLINFO_HEADER_OUT set to true is required for requestHeaders |
| 399 | 399 | // to not be empty (e.g. $curl->setOpt(CURLINFO_HEADER_OUT, true);). |
| 400 | 400 | if ($this->getOpt(CURLINFO_HEADER_OUT) === true) { |
| 401 | - $this->requestHeaders = $this->parseRequestHeaders($this->getInfo(CURLINFO_HEADER_OUT)); |
|
| 401 | + $this->requestHeaders=$this->parseRequestHeaders($this->getInfo(CURLINFO_HEADER_OUT)); |
|
| 402 | 402 | } |
| 403 | - $this->responseHeaders = $this->parseResponseHeaders($this->rawResponseHeaders); |
|
| 404 | - $this->response = $this->parseResponse($this->responseHeaders, $this->rawResponse); |
|
| 403 | + $this->responseHeaders=$this->parseResponseHeaders($this->rawResponseHeaders); |
|
| 404 | + $this->response=$this->parseResponse($this->responseHeaders, $this->rawResponse); |
|
| 405 | 405 | |
| 406 | - $this->httpErrorMessage = ''; |
|
| 406 | + $this->httpErrorMessage=''; |
|
| 407 | 407 | if ($this->error) { |
| 408 | 408 | if (isset($this->responseHeaders['Status-Line'])) { |
| 409 | - $this->httpErrorMessage = $this->responseHeaders['Status-Line']; |
|
| 409 | + $this->httpErrorMessage=$this->responseHeaders['Status-Line']; |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | - $this->errorMessage = $this->curlError ? $this->curlErrorMessage : $this->httpErrorMessage; |
|
| 412 | + $this->errorMessage=$this->curlError ? $this->curlErrorMessage : $this->httpErrorMessage; |
|
| 413 | 413 | |
| 414 | 414 | if (!$this->error) { |
| 415 | 415 | $this->call($this->successFunction); |
@@ -436,11 +436,11 @@ discard block |
||
| 436 | 436 | * |
| 437 | 437 | * @return mixed Returns the value provided by exec. |
| 438 | 438 | */ |
| 439 | - public function get($url, $data = array()) |
|
| 439 | + public function get($url, $data=array()) |
|
| 440 | 440 | { |
| 441 | 441 | if (is_array($url)) { |
| 442 | - $data = $url; |
|
| 443 | - $url = $this->baseUrl; |
|
| 442 | + $data=$url; |
|
| 443 | + $url=$this->baseUrl; |
|
| 444 | 444 | } |
| 445 | 445 | $this->setUrl($url, $data); |
| 446 | 446 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET'); |
@@ -456,13 +456,13 @@ discard block |
||
| 456 | 456 | * |
| 457 | 457 | * @return mixed |
| 458 | 458 | */ |
| 459 | - public function getInfo($opt = null) |
|
| 459 | + public function getInfo($opt=null) |
|
| 460 | 460 | { |
| 461 | - $args = array(); |
|
| 462 | - $args[] = $this->curl; |
|
| 461 | + $args=array(); |
|
| 462 | + $args[]=$this->curl; |
|
| 463 | 463 | |
| 464 | 464 | if (func_num_args()) { |
| 465 | - $args[] = $opt; |
|
| 465 | + $args[]=$opt; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | return call_user_func_array('curl_getinfo', $args); |
@@ -490,11 +490,11 @@ discard block |
||
| 490 | 490 | * |
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | - public function head($url, $data = array()) |
|
| 493 | + public function head($url, $data=array()) |
|
| 494 | 494 | { |
| 495 | 495 | if (is_array($url)) { |
| 496 | - $data = $url; |
|
| 497 | - $url = $this->baseUrl; |
|
| 496 | + $data=$url; |
|
| 497 | + $url=$this->baseUrl; |
|
| 498 | 498 | } |
| 499 | 499 | $this->setUrl($url, $data); |
| 500 | 500 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'HEAD'); |
@@ -514,9 +514,9 @@ discard block |
||
| 514 | 514 | public function headerCallback($ch, $header) |
| 515 | 515 | { |
| 516 | 516 | if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) === 1) { |
| 517 | - $this->responseCookies[$cookie[1]] = trim($cookie[2], " \n\r\t\0\x0B"); |
|
| 517 | + $this->responseCookies[$cookie[1]]=trim($cookie[2], " \n\r\t\0\x0B"); |
|
| 518 | 518 | } |
| 519 | - $this->rawResponseHeaders .= $header; |
|
| 519 | + $this->rawResponseHeaders.=$header; |
|
| 520 | 520 | return strlen($header); |
| 521 | 521 | } |
| 522 | 522 | |
@@ -529,11 +529,11 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | * @return string |
| 531 | 531 | */ |
| 532 | - public function options($url, $data = array()) |
|
| 532 | + public function options($url, $data=array()) |
|
| 533 | 533 | { |
| 534 | 534 | if (is_array($url)) { |
| 535 | - $data = $url; |
|
| 536 | - $url = $this->baseUrl; |
|
| 535 | + $data=$url; |
|
| 536 | + $url=$this->baseUrl; |
|
| 537 | 537 | } |
| 538 | 538 | $this->setUrl($url, $data); |
| 539 | 539 | $this->removeHeader('Content-Length'); |
@@ -550,11 +550,11 @@ discard block |
||
| 550 | 550 | * |
| 551 | 551 | * @return string |
| 552 | 552 | */ |
| 553 | - public function patch($url, $data = array()) |
|
| 553 | + public function patch($url, $data=array()) |
|
| 554 | 554 | { |
| 555 | 555 | if (is_array($url)) { |
| 556 | - $data = $url; |
|
| 557 | - $url = $this->baseUrl; |
|
| 556 | + $data=$url; |
|
| 557 | + $url=$this->baseUrl; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | if (is_array($data) && empty($data)) { |
@@ -592,12 +592,12 @@ discard block |
||
| 592 | 592 | * [2] https://github.com/php/php-src/pull/531 |
| 593 | 593 | * [3] http://php.net/ChangeLog-5.php#5.5.11 |
| 594 | 594 | */ |
| 595 | - public function post($url, $data = array(), $follow_303_with_post = false) |
|
| 595 | + public function post($url, $data=array(), $follow_303_with_post=false) |
|
| 596 | 596 | { |
| 597 | 597 | if (is_array($url)) { |
| 598 | - $follow_303_with_post = (bool)$data; |
|
| 599 | - $data = $url; |
|
| 600 | - $url = $this->baseUrl; |
|
| 598 | + $follow_303_with_post=(bool) $data; |
|
| 599 | + $data=$url; |
|
| 600 | + $url=$this->baseUrl; |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | $this->setUrl($url); |
@@ -634,15 +634,15 @@ discard block |
||
| 634 | 634 | * |
| 635 | 635 | * @return string |
| 636 | 636 | */ |
| 637 | - public function put($url, $data = array()) |
|
| 637 | + public function put($url, $data=array()) |
|
| 638 | 638 | { |
| 639 | 639 | if (is_array($url)) { |
| 640 | - $data = $url; |
|
| 641 | - $url = $this->baseUrl; |
|
| 640 | + $data=$url; |
|
| 641 | + $url=$this->baseUrl; |
|
| 642 | 642 | } |
| 643 | 643 | $this->setUrl($url); |
| 644 | 644 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT'); |
| 645 | - $put_data = $this->buildPostData($data); |
|
| 645 | + $put_data=$this->buildPostData($data); |
|
| 646 | 646 | if (empty($this->options[CURLOPT_INFILE]) && empty($this->options[CURLOPT_INFILESIZE])) { |
| 647 | 647 | if (is_string($put_data)) { |
| 648 | 648 | $this->setHeader('Content-Length', strlen($put_data)); |
@@ -663,15 +663,15 @@ discard block |
||
| 663 | 663 | * |
| 664 | 664 | * @return string |
| 665 | 665 | */ |
| 666 | - public function search($url, $data = array()) |
|
| 666 | + public function search($url, $data=array()) |
|
| 667 | 667 | { |
| 668 | 668 | if (is_array($url)) { |
| 669 | - $data = $url; |
|
| 670 | - $url = $this->baseUrl; |
|
| 669 | + $data=$url; |
|
| 670 | + $url=$this->baseUrl; |
|
| 671 | 671 | } |
| 672 | 672 | $this->setUrl($url); |
| 673 | 673 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'SEARCH'); |
| 674 | - $put_data = $this->buildPostData($data); |
|
| 674 | + $put_data=$this->buildPostData($data); |
|
| 675 | 675 | if (empty($this->options[CURLOPT_INFILE]) && empty($this->options[CURLOPT_INFILESIZE])) { |
| 676 | 676 | if (is_string($put_data)) { |
| 677 | 677 | $this->setHeader('Content-Length', strlen($put_data)); |
@@ -690,10 +690,10 @@ discard block |
||
| 690 | 690 | * @param $username |
| 691 | 691 | * @param $password |
| 692 | 692 | */ |
| 693 | - public function setBasicAuthentication($username, $password = '') |
|
| 693 | + public function setBasicAuthentication($username, $password='') |
|
| 694 | 694 | { |
| 695 | 695 | $this->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
| 696 | - $this->setOpt(CURLOPT_USERPWD, $username . ':' . $password); |
|
| 696 | + $this->setOpt(CURLOPT_USERPWD, $username.':'.$password); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | /** |
@@ -703,10 +703,10 @@ discard block |
||
| 703 | 703 | * @param $username |
| 704 | 704 | * @param $password |
| 705 | 705 | */ |
| 706 | - public function setDigestAuthentication($username, $password = '') |
|
| 706 | + public function setDigestAuthentication($username, $password='') |
|
| 707 | 707 | { |
| 708 | 708 | $this->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); |
| 709 | - $this->setOpt(CURLOPT_USERPWD, $username . ':' . $password); |
|
| 709 | + $this->setOpt(CURLOPT_USERPWD, $username.':'.$password); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -718,27 +718,27 @@ discard block |
||
| 718 | 718 | */ |
| 719 | 719 | public function setCookie($key, $value) |
| 720 | 720 | { |
| 721 | - $name_chars = array(); |
|
| 721 | + $name_chars=array(); |
|
| 722 | 722 | foreach (str_split($key) as $name_char) { |
| 723 | 723 | if (!isset($this->rfc2616[$name_char])) { |
| 724 | - $name_chars[] = rawurlencode($name_char); |
|
| 724 | + $name_chars[]=rawurlencode($name_char); |
|
| 725 | 725 | } else { |
| 726 | - $name_chars[] = $name_char; |
|
| 726 | + $name_chars[]=$name_char; |
|
| 727 | 727 | } |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | - $value_chars = array(); |
|
| 730 | + $value_chars=array(); |
|
| 731 | 731 | foreach (str_split($value) as $value_char) { |
| 732 | 732 | if (!isset($this->rfc6265[$value_char])) { |
| 733 | - $value_chars[] = rawurlencode($value_char); |
|
| 733 | + $value_chars[]=rawurlencode($value_char); |
|
| 734 | 734 | } else { |
| 735 | - $value_chars[] = $value_char; |
|
| 735 | + $value_chars[]=$value_char; |
|
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | - $this->cookies[implode('', $name_chars)] = implode('', $value_chars); |
|
| 740 | - $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function ($k, $v) { |
|
| 741 | - return $k . '=' . $v; |
|
| 739 | + $this->cookies[implode('', $name_chars)]=implode('', $value_chars); |
|
| 740 | + $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function($k, $v) { |
|
| 741 | + return $k.'='.$v; |
|
| 742 | 742 | }, array_keys($this->cookies), array_values($this->cookies)))); |
| 743 | 743 | } |
| 744 | 744 | |
@@ -751,29 +751,29 @@ discard block |
||
| 751 | 751 | public function setCookies($cookies) |
| 752 | 752 | { |
| 753 | 753 | foreach ($cookies as $key => $value) { |
| 754 | - $name_chars = array(); |
|
| 754 | + $name_chars=array(); |
|
| 755 | 755 | foreach (str_split($key) as $name_char) { |
| 756 | 756 | if (!isset($this->rfc2616[$name_char])) { |
| 757 | - $name_chars[] = rawurlencode($name_char); |
|
| 757 | + $name_chars[]=rawurlencode($name_char); |
|
| 758 | 758 | } else { |
| 759 | - $name_chars[] = $name_char; |
|
| 759 | + $name_chars[]=$name_char; |
|
| 760 | 760 | } |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | - $value_chars = array(); |
|
| 763 | + $value_chars=array(); |
|
| 764 | 764 | foreach (str_split($value) as $value_char) { |
| 765 | 765 | if (!isset($this->rfc6265[$value_char])) { |
| 766 | - $value_chars[] = rawurlencode($value_char); |
|
| 766 | + $value_chars[]=rawurlencode($value_char); |
|
| 767 | 767 | } else { |
| 768 | - $value_chars[] = $value_char; |
|
| 768 | + $value_chars[]=$value_char; |
|
| 769 | 769 | } |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | - $this->cookies[implode('', $name_chars)] = implode('', $value_chars); |
|
| 772 | + $this->cookies[implode('', $name_chars)]=implode('', $value_chars); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | - $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function ($k, $v) { |
|
| 776 | - return $k . '=' . $v; |
|
| 775 | + $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function($k, $v) { |
|
| 776 | + return $k.'='.$v; |
|
| 777 | 777 | }, array_keys($this->cookies), array_values($this->cookies)))); |
| 778 | 778 | } |
| 779 | 779 | |
@@ -813,14 +813,14 @@ discard block |
||
| 813 | 813 | { |
| 814 | 814 | // Make compatible with PHP version both before and after 5.5.0. PHP 5.5.0 added the cURL resource as the first |
| 815 | 815 | // argument to the CURLOPT_PROGRESSFUNCTION callback. |
| 816 | - $gte_v550 = version_compare(PHP_VERSION, '5.5.0') >= 0; |
|
| 816 | + $gte_v550=version_compare(PHP_VERSION, '5.5.0') >= 0; |
|
| 817 | 817 | if ($gte_v550) { |
| 818 | - $callback = function ($resource, $download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 818 | + $callback=function($resource, $download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 819 | 819 | // Abort the transfer when $downloaded bytes exceeds maximum $bytes by returning a non-zero value. |
| 820 | 820 | return $downloaded > $bytes ? 1 : 0; |
| 821 | 821 | }; |
| 822 | 822 | } else { |
| 823 | - $callback = function ($download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 823 | + $callback=function($download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 824 | 824 | return $downloaded > $bytes ? 1 : 0; |
| 825 | 825 | }; |
| 826 | 826 | } |
@@ -899,20 +899,20 @@ discard block |
||
| 899 | 899 | */ |
| 900 | 900 | public function setDefaultJsonDecoder() |
| 901 | 901 | { |
| 902 | - $args = func_get_args(); |
|
| 903 | - $this->jsonDecoder = function ($response) use ($args) { |
|
| 902 | + $args=func_get_args(); |
|
| 903 | + $this->jsonDecoder=function($response) use ($args) { |
|
| 904 | 904 | array_unshift($args, $response); |
| 905 | 905 | |
| 906 | 906 | // Call json_decode() without the $options parameter in PHP |
| 907 | 907 | // versions less than 5.4.0 as the $options parameter was added in |
| 908 | 908 | // PHP version 5.4.0. |
| 909 | 909 | if (version_compare(PHP_VERSION, '5.4.0', '<')) { |
| 910 | - $args = array_slice($args, 0, 3); |
|
| 910 | + $args=array_slice($args, 0, 3); |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | - $json_obj = call_user_func_array('json_decode', $args); |
|
| 913 | + $json_obj=call_user_func_array('json_decode', $args); |
|
| 914 | 914 | if (!($json_obj === null)) { |
| 915 | - $response = $json_obj; |
|
| 915 | + $response=$json_obj; |
|
| 916 | 916 | } |
| 917 | 917 | return $response; |
| 918 | 918 | }; |
@@ -925,10 +925,10 @@ discard block |
||
| 925 | 925 | */ |
| 926 | 926 | public function setDefaultXmlDecoder() |
| 927 | 927 | { |
| 928 | - $this->xmlDecoder = function ($response) { |
|
| 929 | - $xml_obj = @simplexml_load_string($response); |
|
| 928 | + $this->xmlDecoder=function($response) { |
|
| 929 | + $xml_obj=@simplexml_load_string($response); |
|
| 930 | 930 | if (!($xml_obj === false)) { |
| 931 | - $response = $xml_obj; |
|
| 931 | + $response=$xml_obj; |
|
| 932 | 932 | } |
| 933 | 933 | return $response; |
| 934 | 934 | }; |
@@ -940,15 +940,15 @@ discard block |
||
| 940 | 940 | * @access public |
| 941 | 941 | * @param $decoder string|callable |
| 942 | 942 | */ |
| 943 | - public function setDefaultDecoder($decoder = 'json') |
|
| 943 | + public function setDefaultDecoder($decoder='json') |
|
| 944 | 944 | { |
| 945 | 945 | if (is_callable($decoder)) { |
| 946 | - $this->defaultDecoder = $decoder; |
|
| 946 | + $this->defaultDecoder=$decoder; |
|
| 947 | 947 | } else { |
| 948 | 948 | if ($decoder === 'json') { |
| 949 | - $this->defaultDecoder = $this->jsonDecoder; |
|
| 949 | + $this->defaultDecoder=$this->jsonDecoder; |
|
| 950 | 950 | } elseif ($decoder === 'xml') { |
| 951 | - $this->defaultDecoder = $this->xmlDecoder; |
|
| 951 | + $this->defaultDecoder=$this->xmlDecoder; |
|
| 952 | 952 | } |
| 953 | 953 | } |
| 954 | 954 | } |
@@ -970,10 +970,10 @@ discard block |
||
| 970 | 970 | */ |
| 971 | 971 | public function setDefaultUserAgent() |
| 972 | 972 | { |
| 973 | - $user_agent = 'puck client' . self::VERSION . ' mini'; |
|
| 974 | - $user_agent .= ' PHP/' . PHP_VERSION; |
|
| 975 | - $curl_version = curl_version(); |
|
| 976 | - $user_agent .= ' curl/' . $curl_version['version']; |
|
| 973 | + $user_agent='puck client'.self::VERSION.' mini'; |
|
| 974 | + $user_agent.=' PHP/'.PHP_VERSION; |
|
| 975 | + $curl_version=curl_version(); |
|
| 976 | + $user_agent.=' curl/'.$curl_version['version']; |
|
| 977 | 977 | $this->setUserAgent($user_agent); |
| 978 | 978 | } |
| 979 | 979 | |
@@ -988,10 +988,10 @@ discard block |
||
| 988 | 988 | */ |
| 989 | 989 | public function setHeader($key, $value) |
| 990 | 990 | { |
| 991 | - $this->headers[$key] = $value; |
|
| 992 | - $headers = array(); |
|
| 991 | + $this->headers[$key]=$value; |
|
| 992 | + $headers=array(); |
|
| 993 | 993 | foreach ($this->headers as $key => $value) { |
| 994 | - $headers[] = $key . ': ' . $value; |
|
| 994 | + $headers[]=$key.': '.$value; |
|
| 995 | 995 | } |
| 996 | 996 | $this->setOpt(CURLOPT_HTTPHEADER, $headers); |
| 997 | 997 | } |
@@ -1007,12 +1007,12 @@ discard block |
||
| 1007 | 1007 | public function setHeaders($headers) |
| 1008 | 1008 | { |
| 1009 | 1009 | foreach ($headers as $key => $value) { |
| 1010 | - $this->headers[$key] = $value; |
|
| 1010 | + $this->headers[$key]=$value; |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | - $headers = array(); |
|
| 1013 | + $headers=array(); |
|
| 1014 | 1014 | foreach ($this->headers as $key => $value) { |
| 1015 | - $headers[] = $key . ': ' . $value; |
|
| 1015 | + $headers[]=$key.': '.$value; |
|
| 1016 | 1016 | } |
| 1017 | 1017 | $this->setOpt(CURLOPT_HTTPHEADER, $headers); |
| 1018 | 1018 | } |
@@ -1026,7 +1026,7 @@ discard block |
||
| 1026 | 1026 | public function setJsonDecoder($function) |
| 1027 | 1027 | { |
| 1028 | 1028 | if (is_callable($function)) { |
| 1029 | - $this->jsonDecoder = $function; |
|
| 1029 | + $this->jsonDecoder=$function; |
|
| 1030 | 1030 | } |
| 1031 | 1031 | } |
| 1032 | 1032 | |
@@ -1039,7 +1039,7 @@ discard block |
||
| 1039 | 1039 | public function setXmlDecoder($function) |
| 1040 | 1040 | { |
| 1041 | 1041 | if (is_callable($function)) { |
| 1042 | - $this->xmlDecoder = $function; |
|
| 1042 | + $this->xmlDecoder=$function; |
|
| 1043 | 1043 | } |
| 1044 | 1044 | } |
| 1045 | 1045 | |
@@ -1054,17 +1054,17 @@ discard block |
||
| 1054 | 1054 | */ |
| 1055 | 1055 | public function setOpt($option, $value) |
| 1056 | 1056 | { |
| 1057 | - $required_options = array( |
|
| 1057 | + $required_options=array( |
|
| 1058 | 1058 | CURLOPT_RETURNTRANSFER => 'CURLOPT_RETURNTRANSFER', |
| 1059 | 1059 | ); |
| 1060 | 1060 | |
| 1061 | 1061 | if (in_array($option, array_keys($required_options), true) && !($value === true)) { |
| 1062 | - trigger_error($required_options[$option] . ' is a required option', E_USER_WARNING); |
|
| 1062 | + trigger_error($required_options[$option].' is a required option', E_USER_WARNING); |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | - $success = curl_setopt($this->curl, $option, $value); |
|
| 1065 | + $success=curl_setopt($this->curl, $option, $value); |
|
| 1066 | 1066 | if ($success) { |
| 1067 | - $this->options[$option] = $value; |
|
| 1067 | + $this->options[$option]=$value; |
|
| 1068 | 1068 | } |
| 1069 | 1069 | return $success; |
| 1070 | 1070 | } |
@@ -1129,10 +1129,10 @@ discard block |
||
| 1129 | 1129 | * @param $url |
| 1130 | 1130 | * @param $data |
| 1131 | 1131 | */ |
| 1132 | - public function setUrl($url, $data = array()) |
|
| 1132 | + public function setUrl($url, $data=array()) |
|
| 1133 | 1133 | { |
| 1134 | - $this->baseUrl = $url; |
|
| 1135 | - $this->url = $this->buildURL($url, $data); |
|
| 1134 | + $this->baseUrl=$url; |
|
| 1135 | + $this->url=$this->buildURL($url, $data); |
|
| 1136 | 1136 | $this->setOpt(CURLOPT_URL, $this->url); |
| 1137 | 1137 | } |
| 1138 | 1138 | |
@@ -1155,7 +1155,7 @@ discard block |
||
| 1155 | 1155 | */ |
| 1156 | 1156 | public function success($callback) |
| 1157 | 1157 | { |
| 1158 | - $this->successFunction = $callback; |
|
| 1158 | + $this->successFunction=$callback; |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | /** |
@@ -1169,9 +1169,9 @@ discard block |
||
| 1169 | 1169 | public function unsetHeader($key) |
| 1170 | 1170 | { |
| 1171 | 1171 | unset($this->headers[$key]); |
| 1172 | - $headers = array(); |
|
| 1172 | + $headers=array(); |
|
| 1173 | 1173 | foreach ($this->headers as $key => $value) { |
| 1174 | - $headers[] = $key . ': ' . $value; |
|
| 1174 | + $headers[]=$key.': '.$value; |
|
| 1175 | 1175 | } |
| 1176 | 1176 | $this->setOpt(CURLOPT_HTTPHEADER, $headers); |
| 1177 | 1177 | } |
@@ -1197,7 +1197,7 @@ discard block |
||
| 1197 | 1197 | * @param bool $on |
| 1198 | 1198 | * @param resource $output |
| 1199 | 1199 | */ |
| 1200 | - public function verbose($on = true, $output = STDERR) |
|
| 1200 | + public function verbose($on=true, $output=STDERR) |
|
| 1201 | 1201 | { |
| 1202 | 1202 | // Turn off CURLINFO_HEADER_OUT for verbose to work. This has the side |
| 1203 | 1203 | // effect of causing Curl::requestHeaders to be empty. |
@@ -1220,9 +1220,9 @@ discard block |
||
| 1220 | 1220 | |
| 1221 | 1221 | public function __get($name) |
| 1222 | 1222 | { |
| 1223 | - $return = null; |
|
| 1224 | - if (in_array($name, self::$deferredProperties) && is_callable(array($this, $getter = '__get_' . $name))) { |
|
| 1225 | - $return = $this->$name = $this->$getter(); |
|
| 1223 | + $return=null; |
|
| 1224 | + if (in_array($name, self::$deferredProperties) && is_callable(array($this, $getter='__get_'.$name))) { |
|
| 1225 | + $return=$this->$name=$this->$getter(); |
|
| 1226 | 1226 | } |
| 1227 | 1227 | return $return; |
| 1228 | 1228 | } |
@@ -1276,9 +1276,9 @@ discard block |
||
| 1276 | 1276 | * |
| 1277 | 1277 | * @return string |
| 1278 | 1278 | */ |
| 1279 | - private function buildURL($url, $data = array()) |
|
| 1279 | + private function buildURL($url, $data=array()) |
|
| 1280 | 1280 | { |
| 1281 | - return $url . (empty($data) ? '' : '?' . http_build_query($data, '', '&')); |
|
| 1281 | + return $url.(empty($data) ? '' : '?'.http_build_query($data, '', '&')); |
|
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | 1284 | /** |
@@ -1291,19 +1291,19 @@ discard block |
||
| 1291 | 1291 | */ |
| 1292 | 1292 | private function parseHeaders($raw_headers) |
| 1293 | 1293 | { |
| 1294 | - $raw_headers = preg_split('/\r\n/', $raw_headers, null, PREG_SPLIT_NO_EMPTY); |
|
| 1295 | - $http_headers = []; |
|
| 1294 | + $raw_headers=preg_split('/\r\n/', $raw_headers, null, PREG_SPLIT_NO_EMPTY); |
|
| 1295 | + $http_headers=[]; |
|
| 1296 | 1296 | |
| 1297 | - $raw_headers_count = count($raw_headers); |
|
| 1298 | - for ($i = 1; $i < $raw_headers_count; $i++) { |
|
| 1299 | - list($key, $value) = explode(':', $raw_headers[$i], 2); |
|
| 1300 | - $key = trim($key); |
|
| 1301 | - $value = trim($value); |
|
| 1297 | + $raw_headers_count=count($raw_headers); |
|
| 1298 | + for ($i=1; $i < $raw_headers_count; $i++) { |
|
| 1299 | + list($key, $value)=explode(':', $raw_headers[$i], 2); |
|
| 1300 | + $key=trim($key); |
|
| 1301 | + $value=trim($value); |
|
| 1302 | 1302 | // Use isset() as array_key_exists() and ArrayAccess are not compatible. |
| 1303 | 1303 | if (isset($http_headers[$key])) { |
| 1304 | - $http_headers[$key] .= ',' . $value; |
|
| 1304 | + $http_headers[$key].=','.$value; |
|
| 1305 | 1305 | } else { |
| 1306 | - $http_headers[$key] = $value; |
|
| 1306 | + $http_headers[$key]=$value; |
|
| 1307 | 1307 | } |
| 1308 | 1308 | } |
| 1309 | 1309 | |
@@ -1320,11 +1320,11 @@ discard block |
||
| 1320 | 1320 | */ |
| 1321 | 1321 | private function parseRequestHeaders($raw_headers) |
| 1322 | 1322 | { |
| 1323 | - $request_headers = []; |
|
| 1324 | - list($first_line, $headers) = $this->parseHeaders($raw_headers); |
|
| 1325 | - $request_headers['Request-Line'] = $first_line; |
|
| 1323 | + $request_headers=[]; |
|
| 1324 | + list($first_line, $headers)=$this->parseHeaders($raw_headers); |
|
| 1325 | + $request_headers['Request-Line']=$first_line; |
|
| 1326 | 1326 | foreach ($headers as $key => $value) { |
| 1327 | - $request_headers[$key] = $value; |
|
| 1327 | + $request_headers[$key]=$value; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | return $request_headers; |
| 1330 | 1330 | } |
@@ -1343,22 +1343,22 @@ discard block |
||
| 1343 | 1343 | */ |
| 1344 | 1344 | private function parseResponse($response_headers, $raw_response) |
| 1345 | 1345 | { |
| 1346 | - $response = $raw_response; |
|
| 1346 | + $response=$raw_response; |
|
| 1347 | 1347 | if (isset($response_headers['Content-Type'])) { |
| 1348 | 1348 | if (preg_match($this->jsonPattern, $response_headers['Content-Type'])) { |
| 1349 | - $json_decoder = $this->jsonDecoder; |
|
| 1349 | + $json_decoder=$this->jsonDecoder; |
|
| 1350 | 1350 | if (is_callable($json_decoder)) { |
| 1351 | - $response = $json_decoder($response); |
|
| 1351 | + $response=$json_decoder($response); |
|
| 1352 | 1352 | } |
| 1353 | 1353 | } elseif (preg_match($this->xmlPattern, $response_headers['Content-Type'])) { |
| 1354 | - $xml_decoder = $this->xmlDecoder; |
|
| 1354 | + $xml_decoder=$this->xmlDecoder; |
|
| 1355 | 1355 | if (is_callable($xml_decoder)) { |
| 1356 | - $response = $xml_decoder($response); |
|
| 1356 | + $response=$xml_decoder($response); |
|
| 1357 | 1357 | } |
| 1358 | 1358 | } else { |
| 1359 | - $decoder = $this->defaultDecoder; |
|
| 1359 | + $decoder=$this->defaultDecoder; |
|
| 1360 | 1360 | if (is_callable($decoder)) { |
| 1361 | - $response = $decoder($response); |
|
| 1361 | + $response=$decoder($response); |
|
| 1362 | 1362 | } |
| 1363 | 1363 | } |
| 1364 | 1364 | } |
@@ -1376,20 +1376,20 @@ discard block |
||
| 1376 | 1376 | */ |
| 1377 | 1377 | private function parseResponseHeaders($raw_response_headers) |
| 1378 | 1378 | { |
| 1379 | - $response_header_array = explode("\r\n\r\n", $raw_response_headers); |
|
| 1380 | - $response_header = ''; |
|
| 1381 | - for ($i = count($response_header_array) - 1; $i >= 0; $i--) { |
|
| 1379 | + $response_header_array=explode("\r\n\r\n", $raw_response_headers); |
|
| 1380 | + $response_header=''; |
|
| 1381 | + for ($i=count($response_header_array) - 1; $i >= 0; $i--) { |
|
| 1382 | 1382 | if (stripos($response_header_array[$i], 'HTTP/') === 0) { |
| 1383 | - $response_header = $response_header_array[$i]; |
|
| 1383 | + $response_header=$response_header_array[$i]; |
|
| 1384 | 1384 | break; |
| 1385 | 1385 | } |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | - $response_headers = []; |
|
| 1389 | - list($first_line, $headers) = $this->parseHeaders($response_header); |
|
| 1390 | - $response_headers['Status-Line'] = $first_line; |
|
| 1388 | + $response_headers=[]; |
|
| 1389 | + list($first_line, $headers)=$this->parseHeaders($response_header); |
|
| 1390 | + $response_headers['Status-Line']=$first_line; |
|
| 1391 | 1391 | foreach ($headers as $key => $value) { |
| 1392 | - $response_headers[$key] = $value; |
|
| 1392 | + $response_headers[$key]=$value; |
|
| 1393 | 1393 | } |
| 1394 | 1394 | return $response_headers; |
| 1395 | 1395 | } |
@@ -12,8 +12,8 @@ |
||
| 12 | 12 | $this->init(); |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - public function init($encoding = 'UTF-8') { |
|
| 16 | - $this->document = new \DOMDocument('1.0', $encoding); |
|
| 15 | + public function init($encoding='UTF-8') { |
|
| 16 | + $this->document=new \DOMDocument('1.0', $encoding); |
|
| 17 | 17 | $this->preserveWhiteSpace(false); |
| 18 | 18 | return $this; |
| 19 | 19 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | { |
| 6 | 6 | |
| 7 | 7 | protected $viewPath=''; |
| 8 | - protected $title = ''; |
|
| 8 | + protected $title=''; |
|
| 9 | 9 | private $twig; |
| 10 | 10 | private $tVar=array(); |
| 11 | 11 | |
@@ -50,15 +50,15 @@ discard block |
||
| 50 | 50 | /** |
| 51 | 51 | * @param string $name |
| 52 | 52 | */ |
| 53 | - protected function assign($name, $value = '') { |
|
| 53 | + protected function assign($name, $value='') { |
|
| 54 | 54 | if (is_array($name)) { |
| 55 | - $this->tVar = array_merge($this->tVar, $name); |
|
| 55 | + $this->tVar=array_merge($this->tVar, $name); |
|
| 56 | 56 | } else { |
| 57 | - $this->tVar[$name] = $value; |
|
| 57 | + $this->tVar[$name]=$value; |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - protected function model($modelName, $vars = []) { |
|
| 62 | - return app($modelName . '_model', $vars); |
|
| 61 | + protected function model($modelName, $vars=[]) { |
|
| 62 | + return app($modelName.'_model', $vars); |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | \ No newline at end of file |