Преглед на файлове

moved router in app; expport app when loading routes

develop
Robin Thoni преди 8 години
родител
ревизия
5dfa9b04ff
променени са 2 файла, в които са добавени 25 реда и са изтрити 19 реда
  1. 1
    14
      src/Utils/Controller/LuRoute.php
  2. 24
    5
      src/Utils/Controller/LuticateApplication.php

+ 1
- 14
src/Utils/Controller/LuRoute.php Целия файл

@@ -35,23 +35,10 @@ class LuRoute {
35 35
      */
36 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 42
     public function getRoutes()
56 43
     {
57 44
         return $this->routes;

+ 24
- 5
src/Utils/Controller/LuticateApplication.php Целия файл

@@ -19,6 +19,7 @@ class LuticateApplication implements MessageComponentInterface
19 19
     private $_version = 1.0;
20 20
     private $_config = null;
21 21
     private $_clients = null;
22
+    private $_router = null;
22 23
     
23 24
     private static $_app = null;
24 25
     
@@ -34,9 +35,26 @@ class LuticateApplication implements MessageComponentInterface
34 35
     {
35 36
         $this->_config = $configuration;
36 37
         $this->_clients = new \SplObjectStorage;
38
+        $this->_router = new LuRoute();
37 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 59
      * @param $version float
42 60
      */
@@ -55,21 +73,22 @@ class LuticateApplication implements MessageComponentInterface
55 73
     
56 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 84
     public function runHttp()
65 85
     {
66 86
         $httpMethod = $_SERVER['REQUEST_METHOD'];
67 87
         $url = $_SERVER['REQUEST_URI'];
68
-        $router = LuRoute::getInstance();
69 88
 
70 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 94
     public function runWs()

Loading…
Отказ
Запис