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