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