@@ -9,7 +9,6 @@ |
||
9 | 9 | * |
10 | 10 | * @package Zortje\MVC\Model |
11 | 11 | */ |
12 | -class User extends Entity |
|
13 | -{ |
|
12 | +class User extends Entity { |
|
14 | 13 | |
15 | 14 | } |
@@ -10,39 +10,39 @@ |
||
10 | 10 | class Request |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @var string Full URL |
|
15 | - */ |
|
16 | - protected $url; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var array POST data |
|
20 | - */ |
|
21 | - protected $post; |
|
22 | - |
|
23 | - /** |
|
24 | - * Get request URL path |
|
25 | - * |
|
26 | - * @return string URL path |
|
27 | - */ |
|
28 | - public function getPath() |
|
29 | - { |
|
30 | - $path = parse_url($this->url, PHP_URL_PATH); |
|
31 | - |
|
32 | - if ($path === false) { |
|
33 | - $path = ''; |
|
34 | - } |
|
35 | - |
|
36 | - return $path; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * @param string $url URL of the request, trailing slash are removed automatically |
|
41 | - * @param array $post URL post fields |
|
42 | - */ |
|
43 | - public function __construct($url, array $post) |
|
44 | - { |
|
45 | - $this->url = rtrim($url, '/'); |
|
46 | - $this->post = $post; |
|
47 | - } |
|
13 | + /** |
|
14 | + * @var string Full URL |
|
15 | + */ |
|
16 | + protected $url; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var array POST data |
|
20 | + */ |
|
21 | + protected $post; |
|
22 | + |
|
23 | + /** |
|
24 | + * Get request URL path |
|
25 | + * |
|
26 | + * @return string URL path |
|
27 | + */ |
|
28 | + public function getPath() |
|
29 | + { |
|
30 | + $path = parse_url($this->url, PHP_URL_PATH); |
|
31 | + |
|
32 | + if ($path === false) { |
|
33 | + $path = ''; |
|
34 | + } |
|
35 | + |
|
36 | + return $path; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * @param string $url URL of the request, trailing slash are removed automatically |
|
41 | + * @param array $post URL post fields |
|
42 | + */ |
|
43 | + public function __construct($url, array $post) |
|
44 | + { |
|
45 | + $this->url = rtrim($url, '/'); |
|
46 | + $this->post = $post; |
|
47 | + } |
|
48 | 48 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @package Zortje\MVC\Network |
9 | 9 | */ |
10 | -class Request |
|
11 | -{ |
|
10 | +class Request { |
|
12 | 11 | |
13 | 12 | /** |
14 | 13 | * @var string Full URL |
@@ -25,8 +24,7 @@ discard block |
||
25 | 24 | * |
26 | 25 | * @return string URL path |
27 | 26 | */ |
28 | - public function getPath() |
|
29 | - { |
|
27 | + public function getPath() { |
|
30 | 28 | $path = parse_url($this->url, PHP_URL_PATH); |
31 | 29 | |
32 | 30 | if ($path === false) { |
@@ -40,8 +38,7 @@ discard block |
||
40 | 38 | * @param string $url URL of the request, trailing slash are removed automatically |
41 | 39 | * @param array $post URL post fields |
42 | 40 | */ |
43 | - public function __construct($url, array $post) |
|
44 | - { |
|
41 | + public function __construct($url, array $post) { |
|
45 | 42 | $this->url = rtrim($url, '/'); |
46 | 43 | $this->post = $post; |
47 | 44 | } |
@@ -10,34 +10,34 @@ |
||
10 | 10 | class Response |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @var array HTTP headers |
|
15 | - */ |
|
16 | - protected $headers = []; |
|
13 | + /** |
|
14 | + * @var array HTTP headers |
|
15 | + */ |
|
16 | + protected $headers = []; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @var string Output |
|
20 | - */ |
|
21 | - protected $output; |
|
18 | + /** |
|
19 | + * @var string Output |
|
20 | + */ |
|
21 | + protected $output; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return array |
|
25 | - */ |
|
26 | - public function output() |
|
27 | - { |
|
28 | - return [ |
|
29 | - 'headers' => $this->headers, |
|
30 | - 'output' => $this->output |
|
31 | - ]; |
|
32 | - } |
|
23 | + /** |
|
24 | + * @return array |
|
25 | + */ |
|
26 | + public function output() |
|
27 | + { |
|
28 | + return [ |
|
29 | + 'headers' => $this->headers, |
|
30 | + 'output' => $this->output |
|
31 | + ]; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param array $headers |
|
36 | - * @param string $output |
|
37 | - */ |
|
38 | - public function __construct($headers, $output) |
|
39 | - { |
|
40 | - $this->headers = $headers; |
|
41 | - $this->output = $output; |
|
42 | - } |
|
34 | + /** |
|
35 | + * @param array $headers |
|
36 | + * @param string $output |
|
37 | + */ |
|
38 | + public function __construct($headers, $output) |
|
39 | + { |
|
40 | + $this->headers = $headers; |
|
41 | + $this->output = $output; |
|
42 | + } |
|
43 | 43 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @package Zortje\MVC\Network |
9 | 9 | */ |
10 | -class Response |
|
11 | -{ |
|
10 | +class Response { |
|
12 | 11 | |
13 | 12 | /** |
14 | 13 | * @var array HTTP headers |
@@ -23,8 +22,7 @@ discard block |
||
23 | 22 | /** |
24 | 23 | * @return array |
25 | 24 | */ |
26 | - public function output() |
|
27 | - { |
|
25 | + public function output() { |
|
28 | 26 | return [ |
29 | 27 | 'headers' => $this->headers, |
30 | 28 | 'output' => $this->output |
@@ -35,8 +33,7 @@ discard block |
||
35 | 33 | * @param array $headers |
36 | 34 | * @param string $output |
37 | 35 | */ |
38 | - public function __construct($headers, $output) |
|
39 | - { |
|
36 | + public function __construct($headers, $output) { |
|
40 | 37 | $this->headers = $headers; |
41 | 38 | $this->output = $output; |
42 | 39 | } |
@@ -23,179 +23,179 @@ |
||
23 | 23 | class Dispatcher |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var Router |
|
28 | - */ |
|
29 | - protected $router; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var \PDO PDO |
|
33 | - */ |
|
34 | - protected $pdo; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string App file path |
|
38 | - */ |
|
39 | - protected $appPath; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var null|User User |
|
43 | - */ |
|
44 | - protected $user; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var Logger |
|
48 | - */ |
|
49 | - protected $logger; |
|
50 | - |
|
51 | - /** |
|
52 | - * Set logger to be used for any logging that could occure in the dispatching process |
|
53 | - * |
|
54 | - * @param Logger $logger |
|
55 | - */ |
|
56 | - public function setLogger(Logger $logger) |
|
57 | - { |
|
58 | - $this->logger = $logger; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param Request $request Request object |
|
63 | - * |
|
64 | - * @return Response Reponse object |
|
65 | - * |
|
66 | - * @throws \Exception If unexpected exception is thrown |
|
67 | - */ |
|
68 | - public function dispatch(Request $request) |
|
69 | - { |
|
70 | - $controllerFactory = new ControllerFactory($this->pdo, $this->appPath, $this->user); |
|
71 | - |
|
72 | - try { |
|
73 | - list($controllerName, $action) = array_values($this->router->route($request->getPath())); |
|
74 | - |
|
75 | - /** |
|
76 | - * Validate and initialize controller |
|
77 | - */ |
|
78 | - try { |
|
79 | - $controller = $controllerFactory->create($controllerName); |
|
80 | - } catch (\Exception $e) { |
|
81 | - if ($e instanceof ControllerNonexistentException || $e instanceof ControllerInvalidSuperclassException) { |
|
82 | - /** |
|
83 | - * Log invalid superclass |
|
84 | - */ |
|
85 | - if ($this->logger && $e instanceof ControllerInvalidSuperclassException) { |
|
86 | - $this->logger->addCritical('Controller must be an subclass of Zortje\MVC\Controller', [ |
|
87 | - 'path' => $request->getPath(), |
|
88 | - 'controller' => $controllerName |
|
89 | - ]); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Log nonexistent |
|
94 | - */ |
|
95 | - if ($this->logger && $e instanceof ControllerNonexistentException) { |
|
96 | - $this->logger->addCritical('Controller is nonexistent', [ |
|
97 | - 'path' => $request->getPath(), |
|
98 | - 'controller' => $controllerName |
|
99 | - ]); |
|
100 | - } |
|
101 | - |
|
102 | - $controller = $controllerFactory->create(NotFoundController::class); |
|
103 | - $action = 'index'; |
|
104 | - } else { |
|
105 | - throw $e; |
|
106 | - } |
|
107 | - } |
|
108 | - } catch (RouteNonexistentException $e) { |
|
109 | - /** |
|
110 | - * Log nonexistent route (404) |
|
111 | - */ |
|
112 | - if ($this->logger) { |
|
113 | - $this->logger->addWarning('Route not connected', [ |
|
114 | - 'path' => $request->getPath() |
|
115 | - ]); |
|
116 | - } |
|
117 | - |
|
118 | - $controller = $controllerFactory->create(NotFoundController::class); |
|
119 | - $action = 'index'; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Validate and set controller action |
|
124 | - */ |
|
125 | - try { |
|
126 | - $controller->setAction($action); |
|
127 | - } catch (ControllerActionProtectedInsufficientAuthenticationException $e) { |
|
128 | - /** |
|
129 | - * Log unauthed protected controller action (403) |
|
130 | - */ |
|
131 | - if ($this->logger) { |
|
132 | - $this->logger->addWarning('Unauthenticated attempt to access protected action', [ |
|
133 | - 'path' => $request->getPath(), |
|
134 | - 'controller' => $controller->getShortName(), |
|
135 | - 'action' => $action |
|
136 | - ]); |
|
137 | - } |
|
138 | - |
|
139 | - // @todo redirect to login page & and save what action was requested to redirect after successful login |
|
140 | - |
|
141 | - } catch (ControllerActionPrivateInsufficientAuthenticationException $e) { |
|
142 | - /** |
|
143 | - * Log unauthed private controller action (403) |
|
144 | - */ |
|
145 | - if ($this->logger) { |
|
146 | - $this->logger->addWarning('Unauthenticated attempt to access private action', [ |
|
147 | - 'path' => $request->getPath(), |
|
148 | - 'controller' => $controller->getShortName(), |
|
149 | - 'action' => $action |
|
150 | - ]); |
|
151 | - } |
|
152 | - |
|
153 | - $controller = $controllerFactory->create(NotFoundController::class); |
|
154 | - } catch (ControllerActionNonexistentException $e) { |
|
155 | - /** |
|
156 | - * Log nonexistent controller action |
|
157 | - */ |
|
158 | - if ($this->logger) { |
|
159 | - $this->logger->addCritical('Controller action is nonexistent', [ |
|
160 | - 'path' => $request->getPath(), |
|
161 | - 'controller' => $controller->getShortName(), |
|
162 | - 'action' => $action |
|
163 | - ]); |
|
164 | - } |
|
165 | - |
|
166 | - $controller = $controllerFactory->create(NotFoundController::class); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Create response from controller action headers and output |
|
171 | - */ |
|
172 | - list($headers, $output) = array_values($controller->callAction()); |
|
173 | - |
|
174 | - /** |
|
175 | - * Performance logging |
|
176 | - */ |
|
177 | - if ($this->logger) { |
|
178 | - $this->logger->addDebug(vsprintf('Dispatched request in %s ms', |
|
179 | - number_format((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2)), [ |
|
180 | - 'path' => $request->getPath() |
|
181 | - ]); |
|
182 | - } |
|
183 | - |
|
184 | - return new Response($headers, $output); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @param Router $router |
|
189 | - * @param \PDO $pdo |
|
190 | - * @param string $appPath |
|
191 | - * @param null|User $user |
|
192 | - */ |
|
193 | - public function __construct(Router $router, \PDO $pdo, $appPath, User $user = null) |
|
194 | - { |
|
195 | - $this->router = $router; |
|
196 | - $this->pdo = $pdo; |
|
197 | - $this->appPath = $appPath; |
|
198 | - $this->user = $user; |
|
199 | - } |
|
26 | + /** |
|
27 | + * @var Router |
|
28 | + */ |
|
29 | + protected $router; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var \PDO PDO |
|
33 | + */ |
|
34 | + protected $pdo; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string App file path |
|
38 | + */ |
|
39 | + protected $appPath; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var null|User User |
|
43 | + */ |
|
44 | + protected $user; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var Logger |
|
48 | + */ |
|
49 | + protected $logger; |
|
50 | + |
|
51 | + /** |
|
52 | + * Set logger to be used for any logging that could occure in the dispatching process |
|
53 | + * |
|
54 | + * @param Logger $logger |
|
55 | + */ |
|
56 | + public function setLogger(Logger $logger) |
|
57 | + { |
|
58 | + $this->logger = $logger; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param Request $request Request object |
|
63 | + * |
|
64 | + * @return Response Reponse object |
|
65 | + * |
|
66 | + * @throws \Exception If unexpected exception is thrown |
|
67 | + */ |
|
68 | + public function dispatch(Request $request) |
|
69 | + { |
|
70 | + $controllerFactory = new ControllerFactory($this->pdo, $this->appPath, $this->user); |
|
71 | + |
|
72 | + try { |
|
73 | + list($controllerName, $action) = array_values($this->router->route($request->getPath())); |
|
74 | + |
|
75 | + /** |
|
76 | + * Validate and initialize controller |
|
77 | + */ |
|
78 | + try { |
|
79 | + $controller = $controllerFactory->create($controllerName); |
|
80 | + } catch (\Exception $e) { |
|
81 | + if ($e instanceof ControllerNonexistentException || $e instanceof ControllerInvalidSuperclassException) { |
|
82 | + /** |
|
83 | + * Log invalid superclass |
|
84 | + */ |
|
85 | + if ($this->logger && $e instanceof ControllerInvalidSuperclassException) { |
|
86 | + $this->logger->addCritical('Controller must be an subclass of Zortje\MVC\Controller', [ |
|
87 | + 'path' => $request->getPath(), |
|
88 | + 'controller' => $controllerName |
|
89 | + ]); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Log nonexistent |
|
94 | + */ |
|
95 | + if ($this->logger && $e instanceof ControllerNonexistentException) { |
|
96 | + $this->logger->addCritical('Controller is nonexistent', [ |
|
97 | + 'path' => $request->getPath(), |
|
98 | + 'controller' => $controllerName |
|
99 | + ]); |
|
100 | + } |
|
101 | + |
|
102 | + $controller = $controllerFactory->create(NotFoundController::class); |
|
103 | + $action = 'index'; |
|
104 | + } else { |
|
105 | + throw $e; |
|
106 | + } |
|
107 | + } |
|
108 | + } catch (RouteNonexistentException $e) { |
|
109 | + /** |
|
110 | + * Log nonexistent route (404) |
|
111 | + */ |
|
112 | + if ($this->logger) { |
|
113 | + $this->logger->addWarning('Route not connected', [ |
|
114 | + 'path' => $request->getPath() |
|
115 | + ]); |
|
116 | + } |
|
117 | + |
|
118 | + $controller = $controllerFactory->create(NotFoundController::class); |
|
119 | + $action = 'index'; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Validate and set controller action |
|
124 | + */ |
|
125 | + try { |
|
126 | + $controller->setAction($action); |
|
127 | + } catch (ControllerActionProtectedInsufficientAuthenticationException $e) { |
|
128 | + /** |
|
129 | + * Log unauthed protected controller action (403) |
|
130 | + */ |
|
131 | + if ($this->logger) { |
|
132 | + $this->logger->addWarning('Unauthenticated attempt to access protected action', [ |
|
133 | + 'path' => $request->getPath(), |
|
134 | + 'controller' => $controller->getShortName(), |
|
135 | + 'action' => $action |
|
136 | + ]); |
|
137 | + } |
|
138 | + |
|
139 | + // @todo redirect to login page & and save what action was requested to redirect after successful login |
|
140 | + |
|
141 | + } catch (ControllerActionPrivateInsufficientAuthenticationException $e) { |
|
142 | + /** |
|
143 | + * Log unauthed private controller action (403) |
|
144 | + */ |
|
145 | + if ($this->logger) { |
|
146 | + $this->logger->addWarning('Unauthenticated attempt to access private action', [ |
|
147 | + 'path' => $request->getPath(), |
|
148 | + 'controller' => $controller->getShortName(), |
|
149 | + 'action' => $action |
|
150 | + ]); |
|
151 | + } |
|
152 | + |
|
153 | + $controller = $controllerFactory->create(NotFoundController::class); |
|
154 | + } catch (ControllerActionNonexistentException $e) { |
|
155 | + /** |
|
156 | + * Log nonexistent controller action |
|
157 | + */ |
|
158 | + if ($this->logger) { |
|
159 | + $this->logger->addCritical('Controller action is nonexistent', [ |
|
160 | + 'path' => $request->getPath(), |
|
161 | + 'controller' => $controller->getShortName(), |
|
162 | + 'action' => $action |
|
163 | + ]); |
|
164 | + } |
|
165 | + |
|
166 | + $controller = $controllerFactory->create(NotFoundController::class); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Create response from controller action headers and output |
|
171 | + */ |
|
172 | + list($headers, $output) = array_values($controller->callAction()); |
|
173 | + |
|
174 | + /** |
|
175 | + * Performance logging |
|
176 | + */ |
|
177 | + if ($this->logger) { |
|
178 | + $this->logger->addDebug(vsprintf('Dispatched request in %s ms', |
|
179 | + number_format((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000, 2)), [ |
|
180 | + 'path' => $request->getPath() |
|
181 | + ]); |
|
182 | + } |
|
183 | + |
|
184 | + return new Response($headers, $output); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @param Router $router |
|
189 | + * @param \PDO $pdo |
|
190 | + * @param string $appPath |
|
191 | + * @param null|User $user |
|
192 | + */ |
|
193 | + public function __construct(Router $router, \PDO $pdo, $appPath, User $user = null) |
|
194 | + { |
|
195 | + $this->router = $router; |
|
196 | + $this->pdo = $pdo; |
|
197 | + $this->appPath = $appPath; |
|
198 | + $this->user = $user; |
|
199 | + } |
|
200 | 200 | |
201 | 201 | } |
@@ -20,8 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @package Zortje\MVC\Routing |
22 | 22 | */ |
23 | -class Dispatcher |
|
24 | -{ |
|
23 | +class Dispatcher { |
|
25 | 24 | |
26 | 25 | /** |
27 | 26 | * @var Router |
@@ -53,8 +52,7 @@ discard block |
||
53 | 52 | * |
54 | 53 | * @param Logger $logger |
55 | 54 | */ |
56 | - public function setLogger(Logger $logger) |
|
57 | - { |
|
55 | + public function setLogger(Logger $logger) { |
|
58 | 56 | $this->logger = $logger; |
59 | 57 | } |
60 | 58 | |
@@ -65,8 +63,7 @@ discard block |
||
65 | 63 | * |
66 | 64 | * @throws \Exception If unexpected exception is thrown |
67 | 65 | */ |
68 | - public function dispatch(Request $request) |
|
69 | - { |
|
66 | + public function dispatch(Request $request) { |
|
70 | 67 | $controllerFactory = new ControllerFactory($this->pdo, $this->appPath, $this->user); |
71 | 68 | |
72 | 69 | try { |
@@ -190,8 +187,7 @@ discard block |
||
190 | 187 | * @param string $appPath |
191 | 188 | * @param null|User $user |
192 | 189 | */ |
193 | - public function __construct(Router $router, \PDO $pdo, $appPath, User $user = null) |
|
194 | - { |
|
190 | + public function __construct(Router $router, \PDO $pdo, $appPath, User $user = null) { |
|
195 | 191 | $this->router = $router; |
196 | 192 | $this->pdo = $pdo; |
197 | 193 | $this->appPath = $appPath; |
@@ -12,16 +12,16 @@ |
||
12 | 12 | class RouteAlreadyConnectedException extends Exception |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * {@inheritdoc} |
|
17 | - */ |
|
18 | - protected $template = 'Route %s is already connected'; |
|
15 | + /** |
|
16 | + * {@inheritdoc} |
|
17 | + */ |
|
18 | + protected $template = 'Route %s is already connected'; |
|
19 | 19 | |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - public function __construct($message) |
|
24 | - { |
|
25 | - parent::__construct($message); |
|
26 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + public function __construct($message) |
|
24 | + { |
|
25 | + parent::__construct($message); |
|
26 | + } |
|
27 | 27 | } |
@@ -9,8 +9,7 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @package Zortje\MVC\Routing\Exception |
11 | 11 | */ |
12 | -class RouteAlreadyConnectedException extends Exception |
|
13 | -{ |
|
12 | +class RouteAlreadyConnectedException extends Exception { |
|
14 | 13 | |
15 | 14 | /** |
16 | 15 | * {@inheritdoc} |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | /** |
21 | 20 | * {@inheritdoc} |
22 | 21 | */ |
23 | - public function __construct($message) |
|
24 | - { |
|
22 | + public function __construct($message) { |
|
25 | 23 | parent::__construct($message); |
26 | 24 | } |
27 | 25 | } |
@@ -12,16 +12,16 @@ |
||
12 | 12 | class RouteNonexistentException extends Exception |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * {@inheritdoc} |
|
17 | - */ |
|
18 | - protected $template = 'Route %s is not connected'; |
|
15 | + /** |
|
16 | + * {@inheritdoc} |
|
17 | + */ |
|
18 | + protected $template = 'Route %s is not connected'; |
|
19 | 19 | |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - public function __construct($message) |
|
24 | - { |
|
25 | - parent::__construct($message); |
|
26 | - } |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + public function __construct($message) |
|
24 | + { |
|
25 | + parent::__construct($message); |
|
26 | + } |
|
27 | 27 | } |
@@ -9,8 +9,7 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @package Zortje\MVC\Routing\Exception |
11 | 11 | */ |
12 | -class RouteNonexistentException extends Exception |
|
13 | -{ |
|
12 | +class RouteNonexistentException extends Exception { |
|
14 | 13 | |
15 | 14 | /** |
16 | 15 | * {@inheritdoc} |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | /** |
21 | 20 | * {@inheritdoc} |
22 | 21 | */ |
23 | - public function __construct($message) |
|
24 | - { |
|
22 | + public function __construct($message) { |
|
25 | 23 | parent::__construct($message); |
26 | 24 | } |
27 | 25 | } |
@@ -13,49 +13,49 @@ |
||
13 | 13 | class Router |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var array Routes |
|
18 | - */ |
|
19 | - protected $routes = []; |
|
20 | - |
|
21 | - /** |
|
22 | - * Connects a new route in the router |
|
23 | - * |
|
24 | - * @param string $route Route |
|
25 | - * @param string $controller Controller |
|
26 | - * @param string $action Action |
|
27 | - * |
|
28 | - * @throws RouteAlreadyConnectedException When route is already connected |
|
29 | - */ |
|
30 | - public function connect($route, $controller, $action) |
|
31 | - { |
|
32 | - if (isset($this->routes[$route]) === true) { |
|
33 | - throw new RouteAlreadyConnectedException([$route]); |
|
34 | - } |
|
35 | - |
|
36 | - $this->routes[$route] = [ |
|
37 | - 'controller' => $controller, |
|
38 | - 'action' => $action |
|
39 | - ]; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Route to get controller and action |
|
44 | - * |
|
45 | - * @param string $route Route |
|
46 | - * |
|
47 | - * @return array Controller and action |
|
48 | - * |
|
49 | - * @throws RouteNonexistentException When route is not connected |
|
50 | - */ |
|
51 | - public function route($route) |
|
52 | - { |
|
53 | - if (isset($this->routes[$route]) === false) { |
|
54 | - throw new RouteNonexistentException([$route]); |
|
55 | - } |
|
56 | - |
|
57 | - $result = $this->routes[$route]; |
|
58 | - |
|
59 | - return $result; |
|
60 | - } |
|
16 | + /** |
|
17 | + * @var array Routes |
|
18 | + */ |
|
19 | + protected $routes = []; |
|
20 | + |
|
21 | + /** |
|
22 | + * Connects a new route in the router |
|
23 | + * |
|
24 | + * @param string $route Route |
|
25 | + * @param string $controller Controller |
|
26 | + * @param string $action Action |
|
27 | + * |
|
28 | + * @throws RouteAlreadyConnectedException When route is already connected |
|
29 | + */ |
|
30 | + public function connect($route, $controller, $action) |
|
31 | + { |
|
32 | + if (isset($this->routes[$route]) === true) { |
|
33 | + throw new RouteAlreadyConnectedException([$route]); |
|
34 | + } |
|
35 | + |
|
36 | + $this->routes[$route] = [ |
|
37 | + 'controller' => $controller, |
|
38 | + 'action' => $action |
|
39 | + ]; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Route to get controller and action |
|
44 | + * |
|
45 | + * @param string $route Route |
|
46 | + * |
|
47 | + * @return array Controller and action |
|
48 | + * |
|
49 | + * @throws RouteNonexistentException When route is not connected |
|
50 | + */ |
|
51 | + public function route($route) |
|
52 | + { |
|
53 | + if (isset($this->routes[$route]) === false) { |
|
54 | + throw new RouteNonexistentException([$route]); |
|
55 | + } |
|
56 | + |
|
57 | + $result = $this->routes[$route]; |
|
58 | + |
|
59 | + return $result; |
|
60 | + } |
|
61 | 61 | } |
@@ -10,8 +10,7 @@ discard block |
||
10 | 10 | * |
11 | 11 | * @package Zortje\MVC\Routing |
12 | 12 | */ |
13 | -class Router |
|
14 | -{ |
|
13 | +class Router { |
|
15 | 14 | |
16 | 15 | /** |
17 | 16 | * @var array Routes |
@@ -27,8 +26,7 @@ discard block |
||
27 | 26 | * |
28 | 27 | * @throws RouteAlreadyConnectedException When route is already connected |
29 | 28 | */ |
30 | - public function connect($route, $controller, $action) |
|
31 | - { |
|
29 | + public function connect($route, $controller, $action) { |
|
32 | 30 | if (isset($this->routes[$route]) === true) { |
33 | 31 | throw new RouteAlreadyConnectedException([$route]); |
34 | 32 | } |
@@ -48,8 +46,7 @@ discard block |
||
48 | 46 | * |
49 | 47 | * @throws RouteNonexistentException When route is not connected |
50 | 48 | */ |
51 | - public function route($route) |
|
52 | - { |
|
49 | + public function route($route) { |
|
53 | 50 | if (isset($this->routes[$route]) === false) { |
54 | 51 | throw new RouteNonexistentException([$route]); |
55 | 52 | } |