20
20
namespace MinusFour \Router \RouteLoader ;
21
21
22
22
use MinusFour \Router \RouteFactory ;
23
- use MinusFour \Router \Action ;
24
- use MinusFour \Utils \ JsonFileParser ;
23
+ use MinusFour \Router \ActionFactory ;
24
+ use MinusFour \Router \ ActionInterface ;
25
25
use MinusFour \Router \RouteContainerInterface ;
26
- use MinusFour \Router \ RouteLoader \ RouteLoaderInterface ;
26
+ use MinusFour \Utils \ JsonFileParser ;
27
27
28
28
class JsonRouteLoader implements RouteLoaderInterface {
29
29
private $ filenames ;
30
30
private $ baseDir ;
31
31
private $ routeFactory ;
32
+ private $ actionFactory ;
32
33
33
- public function __construct (array $ filenames , $ baseDir , RouteFactory $ routeFactory = null ){
34
+ public function __construct (array $ filenames , $ baseDir , RouteFactory $ routeFactory = null , ActionFactoryInterface $ actionFactory = null ){
34
35
$ this ->filenames = $ filenames ;
35
36
$ this ->baseDir = $ baseDir ;
36
37
$ this ->routeFactory = $ routeFactory == null ? new RouteFactory () : $ routeFactory ;
38
+ $ this ->actionFactory = $ actionFactory == null ? new ActionFactory () : $ actionFactory ;
37
39
}
38
40
39
41
public function loadRoutes (RouteContainerInterface $ routeContainer ){
@@ -54,7 +56,7 @@ public function loadRoutes(RouteContainerInterface $routeContainer){
54
56
$ routePath = $ this ->routeFactory ->getCurrentPath ();
55
57
//Move to new base point
56
58
$ this ->routeFactory ->addToPath ($ path );
57
- $ routeLoader = new JsonRouteLoader ([$ newFile ], dirname ($ fullpath ), $ this ->routeFactory );
59
+ $ routeLoader = new JsonRouteLoader ([$ newFile ], dirname ($ fullpath ), $ this ->routeFactory , $ this -> actionFactory );
58
60
$ routeLoader ->loadRoutes ($ routeContainer );
59
61
//Reset route path
60
62
$ this ->routeFactory ->setPath ($ routePath );
@@ -68,9 +70,9 @@ public function loadRoutes(RouteContainerInterface $routeContainer){
68
70
$ actions = $ route ['actions ' ];
69
71
foreach ($ actions as $ method => $ action ){
70
72
if (!isset ($ action ['fixedArgs ' ])){
71
- $ actionObj = new Action ($ action ['class ' ], $ action ['method ' ]);
73
+ $ actionObj = $ this -> actionFactory -> createAction ($ action ['class ' ], $ action ['method ' ]);
72
74
} else {
73
- $ actionObj = new Action ($ action ['class ' ], $ action ['method ' ], $ action ['fixedArgs ' ]);
75
+ $ actionObj = $ this -> actionFactory -> createAction ($ action ['class ' ], $ action ['method ' ], $ action ['fixedArgs ' ]);
74
76
}
75
77
$ routeObj ->setMethodAction ($ method , $ actionObj );
76
78
}
0 commit comments