1 <?php
2
3 4 5 6 7
8
9 namespace nk2580\wordsmith\Routes;
10
11 12 13 14 15
16 class RouteFactory {
17
18 public static function fetchGroup($group) {
19 $status = false;
20 $groups = RouteFactory::all();
21 if (!empty($groups)) {
22 foreach ($groups as $g) {
23 if ($g->name == $group) {
24 $status = $g;
25 break;
26 }
27 }
28 }
29 return $status;
30 }
31
32 public static function createGroup($group) {
33 $obj = new RouteGroup($group);
34 $GLOBALS['_cc_routes'][$group] = $obj;
35 return $obj;
36 }
37
38 public static function addRoute(Route $route) {
39 $group = $route->getGroup();
40 $RouteGroup = RouteFactory::fetchGroup($group);
41 if (!$RouteGroup) {
42 $g = RouteFactory::createGroup($group);
43 $g->add($route);
44 } else {
45 $RouteGroup->add($route);
46 }
47 }
48
49 public static function all() {
50 $OBJ = $GLOBALS['_cc_routes'];
51 return $OBJ;
52 }
53
54 public static function init() {
55 if (!is_array($GLOBALS['_cc_routes'])) {
56 $GLOBALS['_cc_routes'] = [];
57 }
58 }
59
60 public static function implementRouteGroup($group, $endpint, $namespace = ""){
61 $obj = RouteFactory::fetchGroup($group);
62 $obj->run($endpint);
63 }
64
65 }
66