@@ -30,7 +30,7 @@ class RoutesLoader
3030 /**
3131 * @var RouterInterface $router Роутер.
3232 */
33- private $ router ;
33+ private static $ router ;
3434
3535 /**
3636 * @var ResourceCheckerConfigCacheFactory $cacheFactory
@@ -82,7 +82,7 @@ public function __construct(
8282 $ this ->checker = new SelfCheckingResourceChecker ();
8383 $ this ->cacheFactory = new ResourceCheckerConfigCacheFactory ([$ this ->checker ]);
8484
85- $ this -> router = new Router (
85+ static :: $ router = new Router (
8686 $ delegatingLoader ,
8787 $ configFile ,
8888 [
@@ -129,7 +129,7 @@ public function getRoutes() : RouteCollection
129129 }
130130 }
131131
132- return $ this -> router ->getRouteCollection ();
132+ return static :: $ router ->getRouteCollection ();
133133 }
134134
135135 /**
@@ -153,11 +153,23 @@ public function purgeCache() : void
153153 }
154154
155155 /**
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+ *
156168 * @return RouterInterface
157169 */
158170 public function getRouter (): RouterInterface
159171 {
160- return $ this -> router ;
172+ return static :: $ router ;
161173 }
162174
163175 /**
@@ -172,7 +184,7 @@ private function warmUpCache() : void
172184 }
173185
174186 /** @psalm-suppress UndefinedInterfaceMethod */
175- $ this -> router ->setConfigCacheFactory ($ this ->cacheFactory );
187+ static :: $ router ->setConfigCacheFactory ($ this ->cacheFactory );
176188
177189 if ($ this ->cacheFreshChecker !== null && !$ this ->cacheFreshChecker ->isFresh ()) {
178190 if (!@file_exists ($ this ->cacheDir )) {
@@ -181,10 +193,10 @@ private function warmUpCache() : void
181193
182194 file_put_contents (
183195 $ this ->cacheDir . '/route_collection.json ' ,
184- serialize ($ this -> router ->getRouteCollection ())
196+ serialize (static :: $ router ->getRouteCollection ())
185197 );
186198 }
187199
188- $ this -> router ->getGenerator (); // Трюк по созданию кэша.
200+ static :: $ router ->getGenerator (); // Трюк по созданию кэша.
189201 }
190202}
0 commit comments