Completed
Push — master ( bb1ab9...4cd17e )
by Sinnarasa
02:25
created
src/Routing/Response.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -166,8 +166,9 @@
 block discarded – undo
166 166
      */
167 167
     public function sendHeaders()
168 168
     {
169
-        foreach($this->headers as $key => $content)
170
-            header($key.' : '.$content);
169
+        foreach($this->headers as $key => $content) {
170
+                    header($key.' : '.$content);
171
+        }
171 172
         http_response_code($this->getStatusCode());
172 173
         return $this;
173 174
     }
Please login to merge, or discard this patch.
src/Routing/Match/RoutesMatch.php 1 patch
Braces   +31 added lines, -18 removed lines patch added patch discarded remove patch
@@ -78,8 +78,9 @@  discard block
 block discarded – undo
78 78
                 $this->request['path'] = $dependencies;
79 79
                 $this->request['index'] = $i;
80 80
                 $this->request['route'] = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], '/' . trim(trim($this->request['prefix'], '/') . '/' . trim($route, '/'), '/'));
81
-                if ($this->routeMatch('#^' . $this->request['route'] . '$#'))
82
-                    return $this->generateTarget();
81
+                if ($this->routeMatch('#^' . $this->request['route'] . '$#')) {
82
+                                    return $this->generateTarget();
83
+                }
83 84
             }
84 85
         }
85 86
         unset($this->request);
@@ -107,8 +108,9 @@  discard block
 block discarded – undo
107 108
     {
108 109
         if (substr($this->request['route'], -1) == '*') {
109 110
             $pos = strpos($this->request['route'], '*');
110
-            if (substr($this->router->route->getUrl(), 0, $pos) == substr($this->request['route'], 0, $pos))
111
-                if (isset($this->request)) return true;
111
+            if (substr($this->router->route->getUrl(), 0, $pos) == substr($this->request['route'], 0, $pos)) {
112
+                            if (isset($this->request)) return true;
113
+            }
112 114
         }
113 115
         if (preg_match($regex, $this->router->route->getUrl(), $this->request['parameters'])) {
114 116
             array_shift($this->request['parameters']);
@@ -128,19 +130,26 @@  discard block
 block discarded – undo
128 130
             $this->matchClosure();
129 131
             $this->router->response->setStatusCode(202);
130 132
         } else {
131
-            if (isset($this->request['path']['name'])) $this->router->route->setName($this->request['path']['name']);
132
-            if (isset($this->request['path']['method'])) $this->request['path']['method'] = is_array($this->request['path']['method']) ? $this->request['path']['method'] : [$this->request['path']['method']];
133
-            if (isset($this->request['path']))
134
-                (is_array($this->request['path']) && isset($this->request['path']['use']))
133
+            if (isset($this->request['path']['name'])) {
134
+                $this->router->route->setName($this->request['path']['name']);
135
+            }
136
+            if (isset($this->request['path']['method'])) {
137
+                $this->request['path']['method'] = is_array($this->request['path']['method']) ? $this->request['path']['method'] : [$this->request['path']['method']];
138
+            }
139
+            if (isset($this->request['path'])) {
140
+                            (is_array($this->request['path']) && isset($this->request['path']['use']))
135 141
                     ? $this->router->route->setCallback($this->request['path']['use'])
136
-                    : $this->router->route->setCallback($this->request['path']);
142
+                    : $this->router->route->setCallback($this->request['path']);
143
+            }
137 144
             $this->router->route->setDetail($this->request);
138 145
             if($this->validMethod()) {
139
-                foreach($this->matcher as $matcher)
140
-                    call_user_func([$this,$matcher]);
146
+                foreach($this->matcher as $matcher) {
147
+                                    call_user_func([$this,$matcher]);
148
+                }
141 149
                 $this->router->response->setStatusCode(202);
142
-            }else
143
-                $this->router->response->setStatusCode(405);
150
+            } else {
151
+                            $this->router->response->setStatusCode(405);
152
+            }
144 153
         }
145 154
         return $this->router->route->hasTarget();
146 155
     }
@@ -150,8 +159,9 @@  discard block
 block discarded – undo
150 159
      */
151 160
     public function validMethod()
152 161
     {
153
-        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
154
-            return (isset($this->request['path']['ajax']) && $this->request['path']['ajax'] === true) ? true : false;
162
+        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
163
+                    return (isset($this->request['path']['ajax']) && $this->request['path']['ajax'] === true) ? true : false;
164
+        }
155 165
         $method = (isset($this->router->route->getDetail()['path']['method'])) ? $this->router->route->getDetail()['path']['method'] : ['GET'];
156 166
         return (in_array($this->router->route->getMethod(), $method)) ? true : false;
157 167
     }
@@ -177,13 +187,16 @@  discard block
 block discarded – undo
177 187
     {
178 188
         if (!$this->router->route->hasTarget() && strpos($this->router->route->getCallback(), '@') !== false) {
179 189
             $routes = explode('@', $this->router->route->getCallback());
180
-            if (!isset($routes[1])) $routes[1] = 'index';
190
+            if (!isset($routes[1])) {
191
+                $routes[1] = 'index';
192
+            }
181 193
             $index = isset($this->request['index']) ? $this->request['index'] : 0;
182 194
             $class = (class_exists($routes[0]))
183 195
                 ? $routes[0]
184 196
                 : $this->router->collection->getRoutes()['namespace_'.$index].$routes[0];
185
-            if (!class_exists($class))
186
-                throw new \Exception('Class "' . $class . '." is not found');
197
+            if (!class_exists($class)) {
198
+                            throw new \Exception('Class "' . $class . '." is not found');
199
+            }
187 200
             if (method_exists($class, $routes[1])) {
188 201
                 $this->router->route->setTarget([
189 202
                     'dispatcher' => $this->dispatcher['matchController'],
Please login to merge, or discard this patch.
src/Routing/Dispatcher/TemplateDispatcher.php 1 patch
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -47,12 +47,14 @@
 block discarded – undo
47 47
      */
48 48
     public function call()
49 49
     {
50
-        if ($this->response->getStatusCode() == 202)
51
-            $this->setContentType($this->route->getTarget('extension'));
52
-        if (isset($this->route->getTarget()['callback'][$this->route->getTarget('extension')]))
53
-            $this->response->setContent(call_user_func_array($this->route->getTarget()['callback'][$this->route->getTarget('extension')], [$this->route]));
54
-        else
55
-            $this->response->setContent(require($this->route->getTarget('template')));
50
+        if ($this->response->getStatusCode() == 202) {
51
+                    $this->setContentType($this->route->getTarget('extension'));
52
+        }
53
+        if (isset($this->route->getTarget()['callback'][$this->route->getTarget('extension')])) {
54
+                    $this->response->setContent(call_user_func_array($this->route->getTarget()['callback'][$this->route->getTarget('extension')], [$this->route]));
55
+        } else {
56
+                    $this->response->setContent(require($this->route->getTarget('template')));
57
+        }
56 58
     }
57 59
 
58 60
     /**
Please login to merge, or discard this patch.
src/Routing/Dispatcher/ControllerDispatcher.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -48,8 +48,9 @@  discard block
 block discarded – undo
48 48
                 array_unshift($dependencies, call_user_func_array($this->route->getTarget('di'),[$class]));
49 49
             }
50 50
         }
51
-        if ($this->response->getStatusCode() == 202)
52
-            $this->response->setStatusCode(200);
51
+        if ($this->response->getStatusCode() == 202) {
52
+                    $this->response->setStatusCode(200);
53
+        }
53 54
         return $this->response->setContent($reflectionMethod->invokeArgs($this->getController(), $dependencies));
54 55
     }
55 56
 
@@ -61,8 +62,9 @@  discard block
 block discarded – undo
61 62
     private function getController()
62 63
     {
63 64
         $reflector = new ReflectionClass($this->route->getTarget('controller'));
64
-        if (!$reflector->isInstantiable())
65
-            throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.');
65
+        if (!$reflector->isInstantiable()) {
66
+                    throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.');
67
+        }
66 68
         $constructor = $reflector->getConstructor();
67 69
         if (is_null($constructor)) {
68 70
             $class = $this->route->getTarget('controller');
Please login to merge, or discard this patch.
src/Routing/Route.php 1 patch
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -52,10 +52,18 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public function set($args = [])
54 54
     {
55
-        if (isset($args['name'])) $this->name = $args['name'];
56
-        if (isset($args['callback'])) $this->callback = $args['callback'];
57
-        if (isset($args['target'])) $this->target = $args['target'];
58
-        if (isset($args['detail'])) $this->detail = $args['detail'];
55
+        if (isset($args['name'])) {
56
+            $this->name = $args['name'];
57
+        }
58
+        if (isset($args['callback'])) {
59
+            $this->callback = $args['callback'];
60
+        }
61
+        if (isset($args['target'])) {
62
+            $this->target = $args['target'];
63
+        }
64
+        if (isset($args['detail'])) {
65
+            $this->detail = $args['detail'];
66
+        }
59 67
     }
60 68
 
61 69
     /**
@@ -145,8 +153,9 @@  discard block
 block discarded – undo
145 153
      */
146 154
     public function getTarget($key = null)
147 155
     {
148
-        if (!is_null($key))
149
-            return isset($this->target[$key]) ? $this->target[$key] : '';
156
+        if (!is_null($key)) {
157
+                    return isset($this->target[$key]) ? $this->target[$key] : '';
158
+        }
150 159
         return empty($this->target) ? '' : $this->target;
151 160
     }
152 161
 
@@ -165,8 +174,9 @@  discard block
 block discarded – undo
165 174
      */
166 175
     public function hasTarget($key = null)
167 176
     {
168
-        if (!is_null($key))
169
-            return isset($this->target[$key]) ? true : false;
177
+        if (!is_null($key)) {
178
+                    return isset($this->target[$key]) ? true : false;
179
+        }
170 180
         return empty($this->target) ? false : true;
171 181
     }
172 182
 
Please login to merge, or discard this patch.