3
3
use Ligne \ErrorHandler ;
4
4
5
5
/**
6
- * This class controls even if a driver has been entered in the url
7
- * nonexistent or a controller method that does not exist with the following hierarchy:
8
- *
9
- * http: // host / controller / action / [parameter]
10
- * ^ ^
11
- * 1st verify 2nd verify
12
- *
13
- * Until the first condition of this is not given, it does not continue, this being a way
14
- * make sure the controller is correct to verify
15
- * that the method be part of that controller.
16
- *
17
- * The router takes the url captured by request.php and exploits the url in 3
18
- * different parts in the "/" character:
19
- *
20
- **/
6
+ * This class controls even if a driver has been entered in the url
7
+ * nonexistent or a controller method that does not exist with the following hierarchy:
8
+ *
9
+ * http: // host / controller / action / [parameter]
10
+ * ^ ^
11
+ * 1st verify 2nd verify
12
+ *
13
+ * Until the first condition of this is not given, it does not continue, this being a way
14
+ * make sure the controller is correct to verify
15
+ * that the method be part of that controller.
16
+ *
17
+ * The router takes the url captured by request.php and exploits the url in 3
18
+ * different parts in the "/" character:
19
+ *
20
+ **/
21
+
21
22
class Router
22
23
{
23
24
/**
@@ -37,20 +38,20 @@ static public function parse(string $url, object $request): void
37
38
if ($ url == '/ ' . self ::rootDir () . '/ ' || $ controllerName === null )
38
39
self ::loadIndex ($ request );
39
40
elseif ($ controllerName !== null && $ actionNAme !== null )
40
- self ::routeConstruct ($ request , $ controllerName ,$ actionNAme ,$ params );
41
+ self ::routeConstruct ($ request , $ controllerName , $ actionNAme , $ params );
41
42
else
42
43
self ::showNonexistentController ($ controllerName );
43
44
}
44
45
45
46
/**
46
47
* Construct the route base on URL
47
- *
48
+ *
48
49
* @param object $request
49
50
* @param string $controllerName
50
51
* @param string $actionName
51
52
* @param array $params
52
53
*/
53
- static private function routeConstruct (object $ request , string $ controllerName ,string $ actionName ,array $ params ): void
54
+ static private function routeConstruct (object $ request , string $ controllerName , string $ actionName , array $ params ): void
54
55
{
55
56
$ request ->controller = $ controllerName ;
56
57
$ request ->action = $ actionName ;
@@ -144,7 +145,7 @@ static public function subtractControllerName($url)
144
145
$ explodeUrl = explode ('/ ' , $ url );
145
146
$ explodeRootDir = explode ('/ ' , __ROOT__DIR__ );
146
147
147
- $ explodeUrl = self ::unsertKeysFromSourceArray ($ explodeUrl ,$ explodeRootDir );
148
+ $ explodeUrl = self ::unsertKeysFromSourceArray ($ explodeUrl , $ explodeRootDir );
148
149
149
150
$ explodeUrl = array_values ($ explodeUrl );
150
151
return isset ($ explodeUrl [0 ]) ? $ explodeUrl [0 ] : null ;
@@ -155,18 +156,18 @@ static public function subtractActionName($url)
155
156
$ explodeUrl = explode ('/ ' , $ url );
156
157
$ explodeRootDir = explode ('/ ' , __ROOT__DIR__ );
157
158
158
- $ explodeUrl = self ::unsertKeysFromSourceArray ($ explodeUrl ,$ explodeRootDir );
159
+ $ explodeUrl = self ::unsertKeysFromSourceArray ($ explodeUrl , $ explodeRootDir );
159
160
160
161
$ explodeUrl = array_values ($ explodeUrl );
161
162
return isset ($ explodeUrl [1 ]) ? $ explodeUrl [1 ] : null ;
162
163
}
163
164
164
- static public function subtractParams ($ url ):array
165
+ static public function subtractParams ($ url ): array
165
166
{
166
167
$ explodeUrl = explode ('/ ' , $ url );
167
168
$ explodeRootDir = explode ('/ ' , __ROOT__DIR__ );
168
169
169
- $ params = self ::unsertKeysFromSourceArray ($ explodeUrl ,$ explodeRootDir );
170
+ $ params = self ::unsertKeysFromSourceArray ($ explodeUrl , $ explodeRootDir );
170
171
171
172
$ params = array_values ($ explodeUrl );
172
173
//Exclude the controller and action from url
@@ -187,7 +188,8 @@ static public function subtractParams($url):array
187
188
* Unsert project "values" from the $url for determinate if the user specific the
188
189
* controller, action and params
189
190
*/
190
- static private function unsertKeysFromSourceArray (array $ source , array $ target ){
191
+ static private function unsertKeysFromSourceArray (array $ source , array $ target )
192
+ {
191
193
foreach ($ source as $ key => $ value ) {
192
194
if (in_array ($ value , $ target )) {
193
195
unset($ source [$ key ]);
0 commit comments