File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ which at the moment is unfinished.
34
34
35
35
Start by including the autoloader and setting up the classes:
36
36
``` php
37
- include 'src/Autload .php'
37
+ include 'Autoload .php'
38
38
39
39
use MinusFour\Router\Action;
40
40
use MinusFour\Router\Route;
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace MinusFour \Router \RouteLoader ;
3
+
4
+ use MinusFour \Router \Route ;
5
+ use MinusFour \Router \Action ;
6
+ use MinusFour \Router \RouteContainerInterface ;
7
+
8
+ class JsonRouteLoader {
9
+ protected $ routes ;
10
+
11
+ public function __construct ($ fileName ){
12
+ $ fileContent = file_get_contents ($ fileName );
13
+ //Decode Json
14
+ $ this ->routes = json_decode ($ fileContent , true );
15
+ }
16
+
17
+ public function loadRoutes (RouteContainerInterface $ routeContainer ){
18
+ foreach ($ this ->routes as $ routeName => $ route ){
19
+ $ routeObj = new Route ($ routeName , $ route ['path ' ]);
20
+ $ actions = $ route ['actions ' ];
21
+ foreach ($ actions as $ method => $ action ){
22
+ if (!isset ($ action ['fixedArgs ' ])){
23
+ $ actionObj = new Action ($ action ['class ' ], $ action ['method ' ]);
24
+ } else {
25
+ $ actionObj = new Action ($ action ['class ' ], $ action ['method ' ], $ action ['fixedArgs ' ]);
26
+ }
27
+ $ routeObj ->setMethodAction ($ method , $ actionObj );
28
+ }
29
+ $ routeContainer ->addRoute ($ routeObj );
30
+ }
31
+ }
32
+ }
33
+ ?>
You can’t perform that action at this time.
0 commit comments