Browse Source

added static LuRoute instance; save routes

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
f80d636731
2 changed files with 181 additions and 10 deletions
  1. 42
    10
      src/Utils/LuRoute.php
  2. 139
    0
      src/Utils/LuRouteDbo.php

+ 42
- 10
src/Utils/LuRoute.php View File

@@ -8,6 +8,29 @@ class LuRoute {
8 8
      */
9 9
     private $middleware = array('Luticate\Utils\ParametersMiddleware');
10 10
 
11
+    /**
12
+     * @var LuRouteDbo[]
13
+     */
14
+    private $routes = array();
15
+
16
+    /**
17
+     * @var LuRoute
18
+     */
19
+    private static $instance = null;
20
+
21
+    public static function getInstance()
22
+    {
23
+        if (is_null(self::$instance)) {
24
+            self::$instance = new LuRoute();
25
+        }
26
+        return self::$instance;
27
+    }
28
+
29
+    public function getRoutes()
30
+    {
31
+        return $this->routes;
32
+    }
33
+
11 34
     /**
12 35
      * @param $middleware string
13 36
      */
@@ -16,7 +39,7 @@ class LuRoute {
16 39
         $this->middleware[] = $middleware;
17 40
     }
18 41
 
19
-    private function getOptions($url, $business, $method, $permissions, $middleware)
42
+    private function getOptions($method, $url, $business, $method, $permissions, $middleware)
20 43
     {
21 44
         if (!is_array($permissions)) {
22 45
             $permissions = array($permissions);
@@ -30,14 +53,23 @@ class LuRoute {
30 53
 
31 54
             $middleware_string[] = $mid . (strpos($mid, ":") !== false ? "," : ":") . $permissions_string;
32 55
         }
33
-        return [function() use($business, $method, $permissions)
56
+
57
+        if (strpos($business, "\\") === false) {
58
+            $business = "App\\Http\\Business\\" . $business . "Business";
59
+        }
60
+
61
+        $route = new LuRouteDbo();
62
+        $route->setUrl($url);
63
+        $route->setBusinessClass($business);
64
+        $route->setMiddlware($middleware_string);
65
+        $route->setPermissions($permissions);
66
+        $route->setMethod($method);
67
+        $this->routes[] = $route;
68
+
69
+        return [function() use($business, $method)
34 70
         {
35 71
             $controller = new LuController();
36 72
 
37
-            if (strpos($business, "\\") === false) {
38
-                $business = "App\\Http\\Business\\" . $business . "Business";
39
-            }
40
-
41 73
             return $controller->execute($business, $method);
42 74
         },
43 75
             'middleware' => $middleware_string];
@@ -54,7 +86,7 @@ class LuRoute {
54 86
     public function get($url, $business, $method, $permissions = array(), $middleware = array())
55 87
     {
56 88
         global $app;
57
-        return $app->get($url, $this->getOptions($url, $business, $method, $permissions, $middleware));
89
+        return $app->get($url, $this->getOptions("GET", $url, $business, $method, $permissions, $middleware));
58 90
     }
59 91
 
60 92
     /**
@@ -68,7 +100,7 @@ class LuRoute {
68 100
     public function post($url, $business, $method, $permissions = array(), $middleware = array())
69 101
     {
70 102
         global $app;
71
-        return $app->post($url, $this->getOptions($url, $business, $method, $permissions, $middleware));
103
+        return $app->post($url, $this->getOptions("POST", $url, $business, $method, $permissions, $middleware));
72 104
     }
73 105
 
74 106
     /**
@@ -82,7 +114,7 @@ class LuRoute {
82 114
     public function put($url, $business, $method, $permissions = array(), $middleware = array())
83 115
     {
84 116
         global $app;
85
-        return $app->put($url, $this->getOptions($url, $business, $method, $permissions, $middleware));
117
+        return $app->put($url, $this->getOptions("PUT", $url, $business, $method, $permissions, $middleware));
86 118
     }
87 119
 
88 120
     /**
@@ -96,6 +128,6 @@ class LuRoute {
96 128
     public function delete($url, $business, $method, $permissions = array(), $middleware = array())
97 129
     {
98 130
         global $app;
99
-        return $app->delete($url, $this->getOptions($url, $business, $method, $permissions, $middleware));
131
+        return $app->delete($url, $this->getOptions("DELETE", $url, $business, $method, $permissions, $middleware));
100 132
     }
101 133
 }

+ 139
- 0
src/Utils/LuRouteDbo.php View File

@@ -0,0 +1,139 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 10/22/15
6
+ * Time: 7:52 PM
7
+ */
8
+
9
+namespace Luticate\Utils;
10
+
11
+
12
+class LuRouteDbo
13
+{
14
+    /**
15
+     * @var string
16
+     */
17
+    private $_url;
18
+
19
+    /**
20
+     * @var string
21
+     */
22
+    private $_businessClass;
23
+
24
+    /**
25
+     * @var string
26
+     */
27
+    private $_businessMethod;
28
+
29
+    /**
30
+     * @var string[]
31
+     */
32
+    private $_permissions;
33
+
34
+    /**
35
+     * @var string[]
36
+     */
37
+    private $_middlware;
38
+
39
+    /**
40
+     * @var string
41
+     */
42
+    private $_method;
43
+
44
+    /**
45
+     * @return string
46
+     */
47
+    public function getMethod()
48
+    {
49
+        return $this->_method;
50
+    }
51
+
52
+    /**
53
+     * @param string $method
54
+     */
55
+    public function setMethod($method)
56
+    {
57
+        $this->_method = $method;
58
+    }
59
+
60
+    /**
61
+     * @return string
62
+     */
63
+    public function getUrl()
64
+    {
65
+        return $this->_url;
66
+    }
67
+
68
+    /**
69
+     * @param string $url
70
+     */
71
+    public function setUrl($url)
72
+    {
73
+        $this->_url = $url;
74
+    }
75
+
76
+    /**
77
+     * @return string
78
+     */
79
+    public function getBusinessClass()
80
+    {
81
+        return $this->_businessClass;
82
+    }
83
+
84
+    /**
85
+     * @param string $businessClass
86
+     */
87
+    public function setBusinessClass($businessClass)
88
+    {
89
+        $this->_businessClass = $businessClass;
90
+    }
91
+
92
+    /**
93
+     * @return string
94
+     */
95
+    public function getBusinessMethod()
96
+    {
97
+        return $this->_businessMethod;
98
+    }
99
+
100
+    /**
101
+     * @param string $businessMethod
102
+     */
103
+    public function setBusinessMethod($businessMethod)
104
+    {
105
+        $this->_businessMethod = $businessMethod;
106
+    }
107
+
108
+    /**
109
+     * @return \string[]
110
+     */
111
+    public function getPermissions()
112
+    {
113
+        return $this->_permissions;
114
+    }
115
+
116
+    /**
117
+     * @param \string[] $permissions
118
+     */
119
+    public function setPermissions($permissions)
120
+    {
121
+        $this->_permissions = $permissions;
122
+    }
123
+
124
+    /**
125
+     * @return \string[]
126
+     */
127
+    public function getMiddlware()
128
+    {
129
+        return $this->_middlware;
130
+    }
131
+
132
+    /**
133
+     * @param \string[] $middlware
134
+     */
135
+    public function setMiddlware($middlware)
136
+    {
137
+        $this->_middlware = $middlware;
138
+    }
139
+}

Loading…
Cancel
Save