11<?php
2+ namespace app \Routes ;
23
3- class Router {
4- private $ Controller = 'pages ' ;
5- private $ methode = 'index ' ;
6- private $ param =[];
4+ class Router
5+ {
6+ private $ controller = 'Page ' ;
7+ private $ method = 'index ' ;
8+ private $ param = [];
79 public function __construct ()
810 {
9- $ uri = $ this ->getUrl ();
10- if (isset ($ uri [0 ])){
11- if (file_exists ('../app/controllers/ ' .ucwords ($ uri [0 ]).'Controller.php ' )){
11+ $ url = $ this ->getUrl ();
12+
13+ if (isset ($ url [0 ])) {
14+ $ controllerClass = ucwords ($ url [0 ]);
15+ var_dump (PROJECT_ROOTS .'\\Controllers \\' . $ controllerClass . 'Controller ' );
16+ var_dump ($ controllerClass );
17+ $ class =class_exists (PROJECT_ROOTS .'\\Controllers \\' . $ controllerClass . 'Controller ' );
18+ var_dump ($ class );
19+ if ($ class ) {
20+ $ this ->controller = $ controllerClass ;
21+ }
1222
13- $ this ->Controller =ucwords ($ uri [0 ]) ;
14- unset($ uri [0 ]);
1523
16- }
24+ $ controllerClass = '\\app \\controllers \\' . $ this ->controller . 'Controller ' ;
25+ $ this ->controller = new $ controllerClass ;
1726
18- require_once PROJECT_ROOT .'\app\controlles ' . $ this ->Controller ;
27+ if (isset ($ url [1 ])) {
28+
29+ if (method_exists ($ this ->controller , $ url [1 ])) {
30+ $ this ->method = $ url [1 ];
31+ }
32+ }
33+ if (!empty ($ _REQUEST )) {
34+ $ this ->convertArray ($ _REQUEST );
35+ } else {
36+ $ this ->param = [];
37+ }
1938 } else {
20- include '../resources/views/error404.php ' ;
21- exit ;
39+ $ this ->controller = new $ this ->controller ;
2240 }
41+ call_user_func_array ([$ this ->controller , $ this ->method ], $ this ->param );
2342 }
24- public function getUrl ()
43+ private function getUrl ()
44+ {
45+ $ uri = $ _SERVER ['PATH_INFO ' ] ?? '/ ' ;
46+ $ uri = explode ('/ ' , trim ($ uri , '/ ' ));
47+ return $ uri ;
48+ }
49+ private function convertArray ($ array )
2550 {
26- // var_dump($_REQUEST);
27-
2851
29- if (empty ($ _SERVER ['REQUEST_URI ' ])) {
30- $ uri = '' ;
31- } else {
32- $ uri = $ _SERVER ['REQUEST_URI ' ];
52+ foreach ($ array as $ value ) {
53+ array_push ($ this ->param , $ value );
3354 }
34-
35-
36- $ uri = explode ('/ ' , trim ($ uri , '/ ' ));
37- // var_dump( $uri);
38- // }
39-
40- return $ uri ;
55+ }
56+ private function getBasePaths ()
57+ {
58+ $ path = $ _SERVER ['HTTP_REFERER ' ];
59+ header ("Location: $ path " );
4160 }
4261}
43-
44-
45-
46-
47-
48-
49-
50-
51-
52-
53-
54-
55-
56- ?>
0 commit comments