@@ -30,7 +30,7 @@ class RoutesLoader
30
30
/**
31
31
* @var RouterInterface $router Роутер.
32
32
*/
33
- private $ router ;
33
+ private static $ router ;
34
34
35
35
/**
36
36
* @var ResourceCheckerConfigCacheFactory $cacheFactory
@@ -82,7 +82,7 @@ public function __construct(
82
82
$ this ->checker = new SelfCheckingResourceChecker ();
83
83
$ this ->cacheFactory = new ResourceCheckerConfigCacheFactory ([$ this ->checker ]);
84
84
85
- $ this -> router = new Router (
85
+ static :: $ router = new Router (
86
86
$ delegatingLoader ,
87
87
$ configFile ,
88
88
[
@@ -129,7 +129,7 @@ public function getRoutes() : RouteCollection
129
129
}
130
130
}
131
131
132
- return $ this -> router ->getRouteCollection ();
132
+ return static :: $ router ->getRouteCollection ();
133
133
}
134
134
135
135
/**
@@ -153,11 +153,23 @@ public function purgeCache() : void
153
153
}
154
154
155
155
/**
156
+ * Экземпляр Symfony Router.
157
+ *
158
+ * @return RouterInterface|null
159
+ */
160
+ public static function getInstance () : ?RouterInterface
161
+ {
162
+ return static ::$ router ;
163
+ }
164
+
165
+ /**
166
+ * Экземпляр Symfony Router.
167
+ *
156
168
* @return RouterInterface
157
169
*/
158
170
public function getRouter (): RouterInterface
159
171
{
160
- return $ this -> router ;
172
+ return static :: $ router ;
161
173
}
162
174
163
175
/**
@@ -172,7 +184,7 @@ private function warmUpCache() : void
172
184
}
173
185
174
186
/** @psalm-suppress UndefinedInterfaceMethod */
175
- $ this -> router ->setConfigCacheFactory ($ this ->cacheFactory );
187
+ static :: $ router ->setConfigCacheFactory ($ this ->cacheFactory );
176
188
177
189
if ($ this ->cacheFreshChecker !== null && !$ this ->cacheFreshChecker ->isFresh ()) {
178
190
if (!@file_exists ($ this ->cacheDir )) {
@@ -181,10 +193,10 @@ private function warmUpCache() : void
181
193
182
194
file_put_contents (
183
195
$ this ->cacheDir . '/route_collection.json ' ,
184
- serialize ($ this -> router ->getRouteCollection ())
196
+ serialize (static :: $ router ->getRouteCollection ())
185
197
);
186
198
}
187
199
188
- $ this -> router ->getGenerator (); // Трюк по созданию кэша.
200
+ static :: $ router ->getGenerator (); // Трюк по созданию кэша.
189
201
}
190
202
}
0 commit comments