Browse Source

moved router in app; expport app when loading routes

develop
Robin Thoni 8 years ago
parent
commit
5dfa9b04ff
2 changed files with 25 additions and 19 deletions
  1. 1
    14
      src/Utils/Controller/LuRoute.php
  2. 24
    5
      src/Utils/Controller/LuticateApplication.php

+ 1
- 14
src/Utils/Controller/LuRoute.php View File

35
      */
35
      */
36
     private $routes = array();
36
     private $routes = array();
37
 
37
 
38
-    /**
39
-     * @var LuRoute
40
-     */
41
-    private static $instance = null;
42
-
43
-    private function __construct()
38
+    public function __construct()
44
     {
39
     {
45
     }
40
     }
46
 
41
 
47
-    public static function getInstance()
48
-    {
49
-        if (is_null(self::$instance)) {
50
-            self::$instance = new static();
51
-        }
52
-        return self::$instance;
53
-    }
54
-
55
     public function getRoutes()
42
     public function getRoutes()
56
     {
43
     {
57
         return $this->routes;
44
         return $this->routes;

+ 24
- 5
src/Utils/Controller/LuticateApplication.php View File

19
     private $_version = 1.0;
19
     private $_version = 1.0;
20
     private $_config = null;
20
     private $_config = null;
21
     private $_clients = null;
21
     private $_clients = null;
22
+    private $_router = null;
22
     
23
     
23
     private static $_app = null;
24
     private static $_app = null;
24
     
25
     
34
     {
35
     {
35
         $this->_config = $configuration;
36
         $this->_config = $configuration;
36
         $this->_clients = new \SplObjectStorage;
37
         $this->_clients = new \SplObjectStorage;
38
+        $this->_router = new LuRoute();
37
         self::$_app = $this;
39
         self::$_app = $this;
38
     }
40
     }
39
 
41
 
42
+    /**
43
+     * @return LuRoute
44
+     */
45
+    public function getRouter()
46
+    {
47
+        return $this->_router;
48
+    }
49
+
50
+    /**
51
+     * @param LuRoute|null $router
52
+     */
53
+    public function setRouter($router)
54
+    {
55
+        $this->_router = $router;
56
+    }
57
+
40
     /**
58
     /**
41
      * @param $version float
59
      * @param $version float
42
      */
60
      */
55
     
73
     
56
     public function setupRoutes()
74
     public function setupRoutes()
57
     {
75
     {
58
-        require_once __DIR__ . '/../../../../../../app/routes.php';
59
-        $router = LuRoute::getInstance();
76
+        function($app)
77
+        {
78
+            require_once __DIR__ . '/../../../../../../app/routes.php';
79
+        }($this);
60
         
80
         
61
-        $router->setup();
81
+        $this->_router->setup();
62
     }
82
     }
63
     
83
     
64
     public function runHttp()
84
     public function runHttp()
65
     {
85
     {
66
         $httpMethod = $_SERVER['REQUEST_METHOD'];
86
         $httpMethod = $_SERVER['REQUEST_METHOD'];
67
         $url = $_SERVER['REQUEST_URI'];
87
         $url = $_SERVER['REQUEST_URI'];
68
-        $router = LuRoute::getInstance();
69
 
88
 
70
         $parameters = array_merge($_GET, $_POST);
89
         $parameters = array_merge($_GET, $_POST);
71
 
90
 
72
-        $router->dispatch($httpMethod, $url, $parameters);
91
+        $this->_router->dispatch($httpMethod, $url, $parameters);
73
     }
92
     }
74
     
93
     
75
     public function runWs()
94
     public function runWs()

Loading…
Cancel
Save