@@ -6,71 +6,71 @@ discard block |
||
| 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) $action = $this->basController . '/' . $action; |
| 44 | 44 | |
| 45 | 45 | if ($this->groupMiddleware) { |
| 46 | 46 | |
| 47 | - if (is_array($middleware)) { |
|
| 47 | + if (is_array($middleware)) { |
|
| 48 | 48 | |
| 49 | 49 | $middleware = array_merge($this->groupMiddleware[0], $middleware); |
| 50 | 50 | |
| 51 | - } else { |
|
| 51 | + } else { |
|
| 52 | 52 | |
| 53 | 53 | array_push($this->groupMiddleware[0], $middleware); |
| 54 | 54 | |
| 55 | 55 | $middleware = $this->groupMiddleware[0]; |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $routes = [ |
| 60 | - 'url' => $url, |
|
| 61 | - 'pattern' => $this->generatePattern($url), |
|
| 62 | - 'action' => $this->getAction($action), |
|
| 63 | - 'method' => $requestMethos, |
|
| 64 | - 'middleware' => $middleware |
|
| 60 | + 'url' => $url, |
|
| 61 | + 'pattern' => $this->generatePattern($url), |
|
| 62 | + 'action' => $this->getAction($action), |
|
| 63 | + 'method' => $requestMethos, |
|
| 64 | + 'middleware' => $middleware |
|
| 65 | 65 | ]; |
| 66 | 66 | |
| 67 | 67 | $this->routes[] = $routes; |
| 68 | 68 | |
| 69 | 69 | return $this; |
| 70 | - } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function group($groupOptions, callable $callback) |
|
| 73 | - { |
|
| 72 | + public function group($groupOptions, callable $callback) |
|
| 73 | + { |
|
| 74 | 74 | $prefix = $groupOptions['prefix']; |
| 75 | 75 | $controller = $groupOptions['controller']; |
| 76 | 76 | $middlewareFrom = array_shift($groupOptions['middleware']); |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | $callback($this); |
| 90 | 90 | |
| 91 | 91 | return $this; |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - public function package($url, $controller) |
|
| 95 | - { |
|
| 94 | + public function package($url, $controller) |
|
| 95 | + { |
|
| 96 | 96 | $this->add("$url", "$controller"); |
| 97 | 97 | $this->add("$url/add", "$controller@add", "POST"); |
| 98 | 98 | $this->add("$url/submit", "$controller@submit", "POST"); |
@@ -101,19 +101,19 @@ discard block |
||
| 101 | 101 | $this->add("$url/delete/:id", "$controller@delete", "POST"); |
| 102 | 102 | |
| 103 | 103 | return $this; |
| 104 | - } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - public function generatePattern($url) |
|
| 107 | - { |
|
| 106 | + public function generatePattern($url) |
|
| 107 | + { |
|
| 108 | 108 | $pattern = '#^'; |
| 109 | 109 | $pattern .= str_replace([':text', ':id'], ['([a-zA-Z0-9-]+)', '(\d+)'], $url); |
| 110 | 110 | $pattern .= '$#'; |
| 111 | 111 | |
| 112 | 112 | return $pattern; |
| 113 | - } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - public function getAction($action) |
|
| 116 | - { |
|
| 115 | + public function getAction($action) |
|
| 116 | + { |
|
| 117 | 117 | $action = str_replace('/', '\\', $action); |
| 118 | 118 | |
| 119 | 119 | $action = (strpos($action, '@') != 0) ? $action : $action . '@index'; |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | $action = explode('@', $action); |
| 122 | 122 | |
| 123 | 123 | return $action; |
| 124 | - } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - public function getProperRoute() |
|
| 127 | - { |
|
| 126 | + public function getProperRoute() |
|
| 127 | + { |
|
| 128 | 128 | foreach($this->routes as $route) { |
| 129 | 129 | |
| 130 | - if ($this->isMatching($route['pattern']) && $this->isMatchingRequestMethod($route['method'])) { |
|
| 130 | + if ($this->isMatching($route['pattern']) && $this->isMatchingRequestMethod($route['method'])) { |
|
| 131 | 131 | |
| 132 | 132 | $this->current = $route; |
| 133 | 133 | |
@@ -135,79 +135,79 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | if ($route['middleware']) { |
| 137 | 137 | |
| 138 | - if (is_array($route['middleware'])) { |
|
| 138 | + if (is_array($route['middleware'])) { |
|
| 139 | 139 | |
| 140 | 140 | foreach($route['middleware'] as $middleware) { |
| 141 | 141 | |
| 142 | - $output = $this->middleware($middleware); |
|
| 142 | + $output = $this->middleware($middleware); |
|
| 143 | 143 | |
| 144 | - if ($output != '') break; |
|
| 144 | + if ($output != '') break; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - } else { |
|
| 147 | + } else { |
|
| 148 | 148 | |
| 149 | 149 | $output = $this->middleware($route['middleware']); |
| 150 | 150 | |
| 151 | 151 | if ($output != '') break; |
| 152 | - } |
|
| 152 | + } |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if ($output == '') { |
| 156 | 156 | |
| 157 | - list($controller, $method) = $route['action']; |
|
| 157 | + list($controller, $method) = $route['action']; |
|
| 158 | 158 | |
| 159 | - $arguments = $this->getArgumentsFor($route['pattern']); |
|
| 159 | + $arguments = $this->getArgumentsFor($route['pattern']); |
|
| 160 | 160 | |
| 161 | - $output = (string) $this->app->load->action($controller, $method, $arguments); |
|
| 161 | + $output = (string) $this->app->load->action($controller, $method, $arguments); |
|
| 162 | 162 | |
| 163 | - return $output; |
|
| 163 | + return $output; |
|
| 164 | 164 | |
| 165 | 165 | } |
| 166 | 166 | break; |
| 167 | - } |
|
| 167 | + } |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | $output = (string) $this->app->load->action('notFound', 'index', []); |
| 171 | 171 | |
| 172 | 172 | return $output; |
| 173 | - } |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - public function isMatching($pattern) |
|
| 176 | - { |
|
| 175 | + public function isMatching($pattern) |
|
| 176 | + { |
|
| 177 | 177 | $url = $this->app->request->url(); |
| 178 | 178 | |
| 179 | 179 | $url = strtolower($url); |
| 180 | 180 | |
| 181 | 181 | return preg_match($pattern, $url); |
| 182 | - } |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - private function isMatchingRequestMethod($method) |
|
| 185 | - { |
|
| 184 | + private function isMatchingRequestMethod($method) |
|
| 185 | + { |
|
| 186 | 186 | $methods = ['GET', 'POST']; |
| 187 | 187 | |
| 188 | 188 | if (($method == 'both') && in_array($this->app->request->method(), $methods)) return true; |
| 189 | 189 | |
| 190 | 190 | if (is_array($method)) { |
| 191 | 191 | |
| 192 | - if (count($method) == 1) { |
|
| 192 | + if (count($method) == 1) { |
|
| 193 | 193 | |
| 194 | 194 | $method = $method[0]; |
| 195 | 195 | |
| 196 | - } else if (count($method) == 2) { |
|
| 196 | + } else if (count($method) == 2) { |
|
| 197 | 197 | |
| 198 | 198 | if (in_array($method[0], $methods) && in_array($method[1], $methods)) return true; |
| 199 | 199 | |
| 200 | - } else { |
|
| 200 | + } else { |
|
| 201 | 201 | |
| 202 | 202 | return false; |
| 203 | - } |
|
| 203 | + } |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | return $this->app->request->method() == $method; |
| 207 | - } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - public function getArgumentsFor($pattern) |
|
| 210 | - { |
|
| 209 | + public function getArgumentsFor($pattern) |
|
| 210 | + { |
|
| 211 | 211 | $url = $this->app->request->url(); |
| 212 | 212 | |
| 213 | 213 | preg_match($pattern, $url, $matches); |
@@ -215,15 +215,15 @@ discard block |
||
| 215 | 215 | array_shift($matches); |
| 216 | 216 | |
| 217 | 217 | return $matches; |
| 218 | - } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - public function getCurrent($key) |
|
| 221 | - { |
|
| 220 | + public function getCurrent($key) |
|
| 221 | + { |
|
| 222 | 222 | return $this->current[$key]; |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - private function middleware($middleware, $from = 'admin') |
|
| 226 | - { |
|
| 225 | + private function middleware($middleware, $from = 'admin') |
|
| 226 | + { |
|
| 227 | 227 | $middlewareInterface = 'App\\Middleware\\MiddlewaresInterface'; |
| 228 | 228 | |
| 229 | 229 | $middlewares = $this->app->alias['middlewares'][$from]; |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | $middlewareClass = $middlewares[$middleware]; |
| 232 | 232 | |
| 233 | 233 | if (! in_array($middlewareInterface, class_implements($middlewareClass))) { |
| 234 | - throw new Exception("$middlewareClass not Implement"); |
|
| 234 | + throw new Exception("$middlewareClass not Implement"); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | $middlewareObject = new $middlewareClass; |
@@ -241,5 +241,5 @@ discard block |
||
| 241 | 241 | if ($output && $output === static::NEXT) $output = ''; |
| 242 | 242 | |
| 243 | 243 | return $output; |
| 244 | - } |
|
| 244 | + } |
|
| 245 | 245 | } |
| 246 | 246 | \ No newline at end of file |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $middlewareFrom = array_shift($groupOptions['middleware']); |
| 77 | 77 | $middleware = $groupOptions['middleware']; |
| 78 | 78 | |
| 79 | - $url = ltrim($this->app->request->url(), '/'); |
|
| 79 | + $url = ltrim($this->app->request->url(), '/'); |
|
| 80 | 80 | $check = '/' . explode('/', $url)[0]; |
| 81 | 81 | |
| 82 | 82 | if ($check !== $prefix) return $this; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | public function getProperRoute() |
| 127 | 127 | { |
| 128 | - foreach($this->routes as $route) { |
|
| 128 | + foreach ($this->routes as $route) { |
|
| 129 | 129 | |
| 130 | 130 | if ($this->isMatching($route['pattern']) && $this->isMatchingRequestMethod($route['method'])) { |
| 131 | 131 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | if (is_array($route['middleware'])) { |
| 139 | 139 | |
| 140 | - foreach($route['middleware'] as $middleware) { |
|
| 140 | + foreach ($route['middleware'] as $middleware) { |
|
| 141 | 141 | |
| 142 | 142 | $output = $this->middleware($middleware); |
| 143 | 143 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | $middlewareClass = $middlewares[$middleware]; |
| 232 | 232 | |
| 233 | - if (! in_array($middlewareInterface, class_implements($middlewareClass))) { |
|
| 233 | + if (!in_array($middlewareInterface, class_implements($middlewareClass))) { |
|
| 234 | 234 | throw new Exception("$middlewareClass not Implement"); |
| 235 | 235 | } |
| 236 | 236 | |
@@ -40,7 +40,9 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if ($this->basController) $action = $this->basController . '/' . $action; |
|
| 43 | + if ($this->basController) { |
|
| 44 | + $action = $this->basController . '/' . $action; |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | if ($this->groupMiddleware) { |
| 46 | 48 | |
@@ -79,7 +81,9 @@ discard block |
||
| 79 | 81 | $url = ltrim($this->app->request->url(), '/'); |
| 80 | 82 | $check = '/' . explode('/', $url)[0]; |
| 81 | 83 | |
| 82 | - if ($check !== $prefix) return $this; |
|
| 84 | + if ($check !== $prefix) { |
|
| 85 | + return $this; |
|
| 86 | + } |
|
| 83 | 87 | |
| 84 | 88 | $this->prefix = $prefix; |
| 85 | 89 | $this->basController = $controller; |
@@ -141,14 +145,18 @@ discard block |
||
| 141 | 145 | |
| 142 | 146 | $output = $this->middleware($middleware); |
| 143 | 147 | |
| 144 | - if ($output != '') break; |
|
| 148 | + if ($output != '') { |
|
| 149 | + break; |
|
| 150 | + } |
|
| 145 | 151 | } |
| 146 | 152 | |
| 147 | 153 | } else { |
| 148 | 154 | |
| 149 | 155 | $output = $this->middleware($route['middleware']); |
| 150 | 156 | |
| 151 | - if ($output != '') break; |
|
| 157 | + if ($output != '') { |
|
| 158 | + break; |
|
| 159 | + } |
|
| 152 | 160 | } |
| 153 | 161 | } |
| 154 | 162 | |
@@ -185,7 +193,9 @@ discard block |
||
| 185 | 193 | { |
| 186 | 194 | $methods = ['GET', 'POST']; |
| 187 | 195 | |
| 188 | - if (($method == 'both') && in_array($this->app->request->method(), $methods)) return true; |
|
| 196 | + if (($method == 'both') && in_array($this->app->request->method(), $methods)) { |
|
| 197 | + return true; |
|
| 198 | + } |
|
| 189 | 199 | |
| 190 | 200 | if (is_array($method)) { |
| 191 | 201 | |
@@ -195,7 +205,9 @@ discard block |
||
| 195 | 205 | |
| 196 | 206 | } else if (count($method) == 2) { |
| 197 | 207 | |
| 198 | - if (in_array($method[0], $methods) && in_array($method[1], $methods)) return true; |
|
| 208 | + if (in_array($method[0], $methods) && in_array($method[1], $methods)) { |
|
| 209 | + return true; |
|
| 210 | + } |
|
| 199 | 211 | |
| 200 | 212 | } else { |
| 201 | 213 | |
@@ -238,7 +250,9 @@ discard block |
||
| 238 | 250 | |
| 239 | 251 | $output = $middlewareObject->handle($this->app, static::NEXT); |
| 240 | 252 | |
| 241 | - if ($output && $output === static::NEXT) $output = ''; |
|
| 253 | + if ($output && $output === static::NEXT) { |
|
| 254 | + $output = ''; |
|
| 255 | + } |
|
| 242 | 256 | |
| 243 | 257 | return $output; |
| 244 | 258 | } |
@@ -6,11 +6,11 @@ |
||
| 6 | 6 | |
| 7 | 7 | class DataProtectionController extends Controller |
| 8 | 8 | { |
| 9 | - public function index() |
|
| 10 | - { |
|
| 9 | + public function index() |
|
| 10 | + { |
|
| 11 | 11 | $context = [ |
| 12 | 12 | |
| 13 | 13 | ]; |
| 14 | 14 | return $this->PugView->render('website/pages/dataProtection', $context); |
| 15 | - } |
|
| 15 | + } |
|
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -6,8 +6,8 @@ |
||
| 6 | 6 | |
| 7 | 7 | class LogoutController extends Controller |
| 8 | 8 | { |
| 9 | - public function index() |
|
| 10 | - { |
|
| 9 | + public function index() |
|
| 10 | + { |
|
| 11 | 11 | |
| 12 | - } |
|
| 12 | + } |
|
| 13 | 13 | } |
| 14 | 14 | \ No newline at end of file |
@@ -6,11 +6,11 @@ |
||
| 6 | 6 | |
| 7 | 7 | class NotfoundController extends Controller |
| 8 | 8 | { |
| 9 | - public function index() |
|
| 10 | - { |
|
| 9 | + public function index() |
|
| 10 | + { |
|
| 11 | 11 | $context = [ |
| 12 | 12 | |
| 13 | 13 | ]; |
| 14 | 14 | return $this->PugView->render('notfound', $context); |
| 15 | - } |
|
| 15 | + } |
|
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |