File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 5
5
use Phroute \Phroute \{ RouteCollector , RouteParser , Dispatcher };
6
6
use Phroute \Phroute \Exception \{ HttpRouteNotFoundException , HttpMethodNotAllowedException };
7
7
use LionRoute \Middleware ;
8
+ use LionRoute \Singleton ;
8
9
9
10
class Route {
10
11
12
+ use Singleton;
13
+
11
14
private static RouteCollector $ router ;
12
15
private static array $ addMiddleware = [];
13
-
14
- public function __construct () {
15
-
16
- }
17
16
18
17
public static function init (): Route {
19
18
self ::$ router = new RouteCollector (new RouteParser ());
20
- return new Route ();
19
+ return self :: getInstance ();
21
20
}
22
21
23
22
public static function getRoutes (): array {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace LionRoute ;
4
+
5
+ trait Singleton {
6
+
7
+ private static $ singleton = false ;
8
+
9
+ final private function __construct () {
10
+
11
+ }
12
+
13
+ final public static function getInstance () {
14
+ if (self ::$ singleton === false ) {
15
+ self ::$ singleton = new self ();
16
+ }
17
+
18
+ return self ::$ singleton ;
19
+ }
20
+
21
+ }
You can’t perform that action at this time.
0 commit comments