Passed
Branch master (a87359)
by refat
08:10 queued 04:12
created
Core/System/Application.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
 
12 12
 class Application
13 13
 {
14
-  private $container = [];
14
+    private $container = [];
15 15
 
16
-  private static $instance;
16
+    private static $instance;
17 17
 
18
-  public function __construct(File $file)
19
-  {
18
+    public function __construct(File $file)
19
+    {
20 20
     $this->handleErrors();
21 21
 
22 22
     $this->share('file', $file);
@@ -26,9 +26,9 @@  discard block
 block discarded – undo
26 26
     $this->share('alias', $this->file->call($this->file->to('config/alias', '.php')));
27 27
 
28 28
     $this->loadHelpers();
29
-  }
29
+    }
30 30
 
31
-  private function handleErrors() {
31
+    private function handleErrors() {
32 32
 
33 33
     $run = new Whoops();
34 34
 
@@ -36,23 +36,23 @@  discard block
 block discarded – undo
36 36
 
37 37
     if (WhoopsMisc::isAjaxRequest()) {
38 38
 
39
-      $jsonHandler = new JsonResponseHandler();
39
+        $jsonHandler = new JsonResponseHandler();
40 40
 
41
-      $jsonHandler->setJsonApi(true);
41
+        $jsonHandler->setJsonApi(true);
42 42
 
43
-      $run->prependHandler($jsonHandler);
43
+        $run->prependHandler($jsonHandler);
44 44
     }
45 45
 
46 46
     $run->register();
47
-  }
47
+    }
48 48
 
49
-  public static function getInstance($file = null)
50
-  {
49
+    public static function getInstance($file = null)
50
+    {
51 51
     return static::$instance = is_null(static::$instance) ? new static($file) : static::$instance;
52
-  }
52
+    }
53 53
 
54
-  public function run()
55
-  {
54
+    public function run()
55
+    {
56 56
     $this->session->start();
57 57
 
58 58
     $this->request->prepareUrl();
@@ -66,62 +66,62 @@  discard block
 block discarded – undo
66 66
     $this->response->setOutput($output);
67 67
 
68 68
     $this->response->send();
69
-  }
69
+    }
70 70
 
71
-  private function loadHelpers()
72
-  {
71
+    private function loadHelpers()
72
+    {
73 73
     $helpers = $this->file->to('Core/helpers', '.php');
74 74
 
75 75
     $this->file->call($helpers);
76
-  }
76
+    }
77 77
 
78
-  public function coreClasses()
79
-  {
78
+    public function coreClasses()
79
+    {
80 80
     return $this->alias['classes'];
81
-  }
81
+    }
82 82
 
83
-  public function share($key, $value)
84
-  {
83
+    public function share($key, $value)
84
+    {
85 85
     if ($value instanceof Closure) $value = call_user_func($value, $this);
86 86
 
87 87
     $this->container[$key] = $value;
88
-  }
88
+    }
89 89
 
90
-  public function get($key)
91
-  {
90
+    public function get($key)
91
+    {
92 92
     if (! $this->isSharing($key)) {
93 93
 
94
-      if ($this->isCoreAlias($key)) {
94
+        if ($this->isCoreAlias($key)) {
95 95
 
96 96
         $this->share($key, $this->createObject($key));
97 97
 
98
-      } else {
98
+        } else {
99 99
 
100 100
         throw new Exception("$key is not found");
101
-      }
101
+        }
102 102
     }
103 103
     return $this->container[$key];
104
-  }
104
+    }
105 105
 
106
-  public function isSharing($key)
107
-  {
106
+    public function isSharing($key)
107
+    {
108 108
     return isset($this->container[$key]);
109
-  }
109
+    }
110 110
 
111
-  public function isCoreAlias($key)
112
-  {
111
+    public function isCoreAlias($key)
112
+    {
113 113
     return isset($this->coreClasses()[$key]);
114
-  }
114
+    }
115 115
 
116
-  public function createObject($key)
117
-  {
116
+    public function createObject($key)
117
+    {
118 118
     $object = $this->coreClasses()[$key];
119 119
 
120 120
     return new $object($this);
121
-  }
121
+    }
122 122
 
123
-  public function __get($key)
124
-  {
123
+    public function __get($key)
124
+    {
125 125
     return $this->get($key);
126
-  }
126
+    }
127 127
 }
128 128
\ No newline at end of file
Please login to merge, or discard this patch.
Core/System/Loader.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -6,54 +6,54 @@  discard block
 block discarded – undo
6 6
 
7 7
 class Loader
8 8
 {
9
-  private $app;
9
+    private $app;
10 10
 
11
-  private $controllers = [];
11
+    private $controllers = [];
12 12
 
13
-  private $models = [];
13
+    private $models = [];
14 14
 
15
-  public function __construct(Application $app)
16
-  {
15
+    public function __construct(Application $app)
16
+    {
17 17
     $this->app = $app;
18
-  }
18
+    }
19 19
 
20
-  public function action($controller, $method, array $arguments)
21
-  {
20
+    public function action($controller, $method, array $arguments)
21
+    {
22 22
     $object = $this->controller($controller);
23 23
 
24 24
     return call_user_func([$object, $method], $arguments);
25
-  }
25
+    }
26 26
 
27
-  public function controller($controller)
28
-  {
27
+    public function controller($controller)
28
+    {
29 29
     $controller = $this->getControllerName($controller);
30 30
 
31 31
     if (! $this->hasController($controller)) {
32
-      $this->addController($controller);
32
+        $this->addController($controller);
33 33
     }
34 34
 
35 35
     return $this->getController($controller);
36
-  }
36
+    }
37 37
 
38
-  private function hasController($controller)
39
-  {
38
+    private function hasController($controller)
39
+    {
40 40
     return array_key_exists($controller, $this->controllers);
41
-  }
41
+    }
42 42
 
43
-  private function addController($controller)
44
-  {
43
+    private function addController($controller)
44
+    {
45 45
     $object = new $controller($this->app);
46 46
 
47 47
     $this->controllers[$controller] = $object;
48
-  }
48
+    }
49 49
 
50
-  private function getController($controller)
51
-  {
50
+    private function getController($controller)
51
+    {
52 52
     return $this->controllers[$controller];
53
-  }
53
+    }
54 54
 
55
-  private function getControllerName($controller)
56
-  {
55
+    private function getControllerName($controller)
56
+    {
57 57
     $controller .= strpos($controller, 'Controller') ? '' : 'Controller';
58 58
 
59 59
     $controller = str_replace('/', DS, $controller);
@@ -61,38 +61,38 @@  discard block
 block discarded – undo
61 61
     $controller = 'App' . DS .'Controllers' . DS . $controller;
62 62
 
63 63
     return $controller;
64
-  }
64
+    }
65 65
 
66
-  public function model($model)
67
-  {
66
+    public function model($model)
67
+    {
68 68
     $model = $this->getModelName($model);
69 69
 
70 70
     if (! $this->hasModel($model)) {
71
-      $this->addModel($model);
71
+        $this->addModel($model);
72 72
     }
73 73
 
74 74
     return $this->getModel($model);
75
-  }
75
+    }
76 76
 
77
-  private function hasModel($model)
78
-  {
77
+    private function hasModel($model)
78
+    {
79 79
     return array_key_exists($model, $this->models);
80
-  }
80
+    }
81 81
 
82
-  private function addModel($model)
83
-  {
82
+    private function addModel($model)
83
+    {
84 84
     $object = new $model($this->app);
85 85
 
86 86
     $this->models[$model] = $object;
87
-  }
87
+    }
88 88
 
89
-  private function getModel($model)
90
-  {
89
+    private function getModel($model)
90
+    {
91 91
     return $this->models[$model];
92
-  }
92
+    }
93 93
 
94
-  private function getModelName($model)
95
-  {
94
+    private function getModelName($model)
95
+    {
96 96
     $model .= strpos($model, 'Model') ? '' : 'Model';
97 97
 
98 98
     $model = str_replace('/', DS, $model);
@@ -100,5 +100,5 @@  discard block
 block discarded – undo
100 100
     $model = 'App' . DS . 'Models' . DS . $model;
101 101
 
102 102
     return $model;
103
-  }
103
+    }
104 104
 }
105 105
\ No newline at end of file
Please login to merge, or discard this patch.
Core/System/Route.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -6,73 +6,73 @@  discard block
 block discarded – undo
6 6
 
7 7
 class Route
8 8
 {
9
-  const NEXT = '_NEXT_';
9
+    const NEXT = '_NEXT_';
10 10
 
11
-  private $app;
11
+    private $app;
12 12
 
13
-  private $routes = [];
13
+    private $routes = [];
14 14
 
15
-  public $current = [];
15
+    public $current = [];
16 16
 
17
-  private $prefix;
17
+    private $prefix;
18 18
 
19
-  private $basController;
19
+    private $basController;
20 20
 
21
-  private $middlewareFrom;
21
+    private $middlewareFrom;
22 22
 
23
-  private $groupMiddleware = [];
23
+    private $groupMiddleware = [];
24 24
 
25
-  public function __construct(Application $app)
26
-  {
25
+    public function __construct(Application $app)
26
+    {
27 27
     $this->app = $app;
28
-  }
28
+    }
29 29
 
30
-  public function add($url, $action, $requestMethos = 'GET', $middleware = [])
31
-  {
30
+    public function add($url, $action, $requestMethos = 'GET', $middleware = [])
31
+    {
32 32
 
33 33
     if ($this->prefix) {
34 34
 
35
-      if ($this->prefix !== '/') {
35
+        if ($this->prefix !== '/') {
36 36
 
37 37
         $url = $this->prefix . $url;
38 38
 
39 39
         $url = rtrim($url, '/');
40
-      }
40
+        }
41 41
     }
42 42
 
43 43
     if ($this->basController) {
44
-      $action = $this->basController . '/' . $action;
44
+        $action = $this->basController . '/' . $action;
45 45
     }
46 46
 
47 47
     if (!empty($this->groupMiddleware)) {
48 48
 
49
-      if (is_array($middleware)) {
49
+        if (is_array($middleware)) {
50 50
 
51 51
         $middleware = array_merge($this->groupMiddleware[0], $middleware);
52 52
 
53
-      } else {
53
+        } else {
54 54
 
55 55
         array_push($this->groupMiddleware[0], $middleware);
56 56
 
57 57
         $middleware = $this->groupMiddleware[0];
58
-      }
58
+        }
59 59
     }
60 60
 
61 61
     $routes = [
62
-      'url'         => $url,
63
-      'pattern'     => $this->generatePattern($url),
64
-      'action'      => $this->getAction($action),
65
-      'method'      => $requestMethos,
66
-      'middleware'  => $middleware
62
+        'url'         => $url,
63
+        'pattern'     => $this->generatePattern($url),
64
+        'action'      => $this->getAction($action),
65
+        'method'      => $requestMethos,
66
+        'middleware'  => $middleware
67 67
     ];
68 68
 
69 69
     $this->routes[] = $routes;
70 70
 
71 71
     return $this;
72
-  }
72
+    }
73 73
 
74
-  public function group($groupOptions, callable $callback)
75
-  {
74
+    public function group($groupOptions, callable $callback)
75
+    {
76 76
     $prefix = $groupOptions['prefix'];
77 77
     $controller = $groupOptions['controller'];
78 78
     $middlewareFrom = array_shift($groupOptions['middleware']);
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
     $check = '/' . explode('/', $url)[0];
83 83
 
84 84
     if ($check !== $prefix) {
85
-      return $this;
85
+        return $this;
86 86
     }
87 87
 
88 88
     $this->prefix = $prefix;
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
     $callback($this);
94 94
 
95 95
     return $this;
96
-  }
96
+    }
97 97
 
98
-  public function package($url, $controller)
99
-  {
98
+    public function package($url, $controller)
99
+    {
100 100
     $this->add("$url", "$controller");
101 101
     $this->add("$url/add", "$controller@add", "POST");
102 102
     $this->add("$url/submit", "$controller@submit", "POST");
@@ -105,19 +105,19 @@  discard block
 block discarded – undo
105 105
     $this->add("$url/delete/:id", "$controller@delete", "POST");
106 106
 
107 107
     return $this;
108
-  }
108
+    }
109 109
 
110
-  public function generatePattern($url)
111
-  {
110
+    public function generatePattern($url)
111
+    {
112 112
     $pattern = '#^';
113 113
     $pattern .= str_replace([':text', ':id'], ['([a-zA-Z0-9-]+)', '(\d+)'], $url);
114 114
     $pattern .= '$#';
115 115
 
116 116
     return $pattern;
117
-  }
117
+    }
118 118
 
119
-  public function getAction($action)
120
-  {
119
+    public function getAction($action)
120
+    {
121 121
     $action = str_replace('/', '\\', $action);
122 122
 
123 123
     $action = (strpos($action, '@') != 0) ? $action : $action . '@index';
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
     $action = explode('@', $action);
126 126
 
127 127
     return $action;
128
-  }
128
+    }
129 129
 
130
-  public function getProperRoute()
131
-  {
130
+    public function getProperRoute()
131
+    {
132 132
     foreach ($this->routes as $route) {
133 133
 
134
-      if ($this->isMatching($route['pattern']) && $this->isMatchingRequestMethod($route['method'])) {
134
+        if ($this->isMatching($route['pattern']) && $this->isMatchingRequestMethod($route['method'])) {
135 135
 
136 136
         $this->current = $route;
137 137
 
@@ -139,87 +139,87 @@  discard block
 block discarded – undo
139 139
 
140 140
         if ($route['middleware']) {
141 141
 
142
-          if (is_array($route['middleware'])) {
142
+            if (is_array($route['middleware'])) {
143 143
 
144 144
             foreach ($route['middleware'] as $middleware) {
145 145
 
146
-              $output = $this->middleware($middleware);
146
+                $output = $this->middleware($middleware);
147 147
 
148
-              if ($output != '') {
148
+                if ($output != '') {
149 149
                 break;
150
-              }
150
+                }
151 151
             }
152 152
 
153
-          } else {
153
+            } else {
154 154
 
155 155
             $output = $this->middleware($route['middleware']);
156 156
 
157 157
             if ($output != '') {
158
-              break;
158
+                break;
159
+            }
159 160
             }
160
-          }
161 161
         }
162 162
 
163 163
         if ($output == '') {
164 164
 
165
-          list($controller, $method) = $route['action'];
165
+            list($controller, $method) = $route['action'];
166 166
 
167
-          $arguments = $this->getArgumentsFor($route['pattern']);
167
+            $arguments = $this->getArgumentsFor($route['pattern']);
168 168
 
169
-          $output = (string) $this->app->load->action($controller, $method, $arguments);
169
+            $output = (string) $this->app->load->action($controller, $method, $arguments);
170 170
 
171
-          return $output;
171
+            return $output;
172 172
 
173 173
         }
174 174
         break;
175
-      }
175
+        }
176 176
     }
177 177
 
178 178
     $output = (string) $this->app->load->action('notFound', 'index', []);
179 179
 
180 180
     return $output;
181
-  }
181
+    }
182 182
 
183
-  public function isMatching($pattern)
184
-  {
183
+    public function isMatching($pattern)
184
+    {
185 185
     $url = $this->app->request->url();
186 186
 
187 187
     $url = strtolower($url);
188 188
 
189 189
     return preg_match($pattern, $url);
190
-  }
190
+    }
191 191
 
192
-  private function isMatchingRequestMethod($method)
193
-  {
192
+    private function isMatchingRequestMethod($method)
193
+    {
194 194
     $methods = ['GET', 'POST'];
195 195
 
196 196
     if (($method == 'both') && in_array($this->app->request->method(), $methods)) {
197
-      return true;
197
+        return true;
198 198
     }
199 199
 
200 200
     if (is_array($method)) {
201 201
 
202
-      if (count($method) == 1) {
202
+        if (count($method) == 1) {
203 203
 
204 204
         $method = $method[0];
205 205
 
206
-      } else if (count($method) == 2) {
206
+        } else if (count($method) == 2) {
207 207
 
208 208
         if (in_array($method[0], $methods) && in_array($method[1], $methods)) {
209
-          return true;
209
+            return true;
210 210
         }
211 211
 
212
-      } else {
212
+        } else {
213 213
 
214 214
         return false;
215
-      }
215
+        }
216 216
     }
217 217
 
218 218
     return $this->app->request->method() == $method;
219
-  }
219
+    }
220 220
 
221
-  public function getArgumentsFor($pattern)
222
-  {
221
+    public function getArgumentsFor($pattern)
222
+    {
223 223
     $url = $this->app->request->url();
224 224
 
225 225
     preg_match($pattern, $url, $matches);
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
     array_shift($matches);
228 228
 
229 229
     return $matches;
230
-  }
230
+    }
231 231
 
232
-  public function getCurrent($key)
233
-  {
232
+    public function getCurrent($key)
233
+    {
234 234
     return $this->current[$key];
235
-  }
235
+    }
236 236
 
237
-  private function middleware($middleware, $from = 'admin')
238
-  {
237
+    private function middleware($middleware, $from = 'admin')
238
+    {
239 239
     $middlewareInterface = 'App\\Middleware\\MiddlewaresInterface';
240 240
 
241 241
     $middlewares = $this->app->alias['middlewares'][$from];
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     $middlewareClass = $middlewares[$middleware];
244 244
 
245 245
     if (!in_array($middlewareInterface, class_implements($middlewareClass))) {
246
-      throw new Exception("$middlewareClass not Implement");
246
+        throw new Exception("$middlewareClass not Implement");
247 247
     }
248 248
 
249 249
     $middlewareObject = new $middlewareClass;
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
     $output = $middlewareObject->handle($this->app, static::NEXT);
252 252
 
253 253
     if ($output && $output === static::NEXT) {
254
-      $output = '';
254
+        $output = '';
255 255
     }
256 256
 
257 257
     return $output;
258
-  }
258
+    }
259 259
 }
260 260
\ No newline at end of file
Please login to merge, or discard this patch.