3434
3535use OC \AppFramework \Routing \RouteParser ;
3636use OCP \AppFramework \App ;
37+ use OCP \Diagnostics \IEventLogger ;
38+ use OCP \IConfig ;
39+ use OCP \IRequest ;
3740use OCP \Route \IRouter ;
3841use OCP \Util ;
42+ use Psr \Container \ContainerInterface ;
3943use Psr \Log \LoggerInterface ;
4044use Symfony \Component \Routing \Exception \ResourceNotFoundException ;
4145use Symfony \Component \Routing \Exception \RouteNotFoundException ;
@@ -64,24 +68,35 @@ class Router implements IRouter {
6468 protected LoggerInterface $ logger ;
6569 /** @var RequestContext */
6670 protected $ context ;
67-
68- public function __construct (LoggerInterface $ logger ) {
71+ private IEventLogger $ eventLogger ;
72+ private IConfig $ config ;
73+ private ContainerInterface $ container ;
74+
75+ public function __construct (
76+ LoggerInterface $ logger ,
77+ IRequest $ request ,
78+ IConfig $ config ,
79+ IEventLogger $ eventLogger ,
80+ ContainerInterface $ container
81+ ) {
6982 $ this ->logger = $ logger ;
83+ $ this ->config = $ config ;
7084 $ baseUrl = \OC ::$ WEBROOT ;
71- if (!(\ OC :: $ server -> getConfig () ->getSystemValue ('htaccess.IgnoreFrontController ' , false ) === true || getenv ('front_controller_active ' ) === 'true ' )) {
85+ if (!($ config ->getSystemValue ('htaccess.IgnoreFrontController ' , false ) === true || getenv ('front_controller_active ' ) === 'true ' )) {
7286 $ baseUrl .= '/index.php ' ;
7387 }
7488 if (!\OC ::$ CLI && isset ($ _SERVER ['REQUEST_METHOD ' ])) {
7589 $ method = $ _SERVER ['REQUEST_METHOD ' ];
7690 } else {
7791 $ method = 'GET ' ;
7892 }
79- $ request = \OC ::$ server ->getRequest ();
8093 $ host = $ request ->getServerHost ();
8194 $ schema = $ request ->getServerProtocol ();
8295 $ this ->context = new RequestContext ($ baseUrl , $ method , $ host , $ schema );
8396 // TODO cache
8497 $ this ->root = $ this ->getCollection ('root ' );
98+ $ this ->eventLogger = $ eventLogger ;
99+ $ this ->container = $ container ;
85100 }
86101
87102 /**
@@ -134,7 +149,7 @@ public function loadRoutes($app = null) {
134149 $ routingFiles = [];
135150 }
136151 }
137- \ OC :: $ server -> getEventLogger () ->start ('loadroutes ' . $ requestedApp , 'Loading Routes ' );
152+ $ this -> eventLogger ->start ('route:load: ' . $ requestedApp , 'Loading Routes for ' . $ requestedApp );
138153 foreach ($ routingFiles as $ app => $ file ) {
139154 if (!isset ($ this ->loadedApps [$ app ])) {
140155 if (!\OC_App::isAppLoaded ($ app )) {
@@ -170,7 +185,7 @@ public function loadRoutes($app = null) {
170185 $ collection ->addPrefix ('/ocs ' );
171186 $ this ->root ->addCollection ($ collection );
172187 }
173- \ OC :: $ server -> getEventLogger () ->end ('loadroutes ' . $ requestedApp );
188+ $ this -> eventLogger ->end ('route:load: ' . $ requestedApp );
174189 }
175190
176191 /**
@@ -231,6 +246,7 @@ public function create($name,
231246 * @return array
232247 */
233248 public function findMatchingRoute (string $ url ): array {
249+ $ this ->eventLogger ->start ('route:match ' , 'Match route ' );
234250 if (substr ($ url , 0 , 6 ) === '/apps/ ' ) {
235251 // empty string / 'apps' / $app / rest of the route
236252 [, , $ app ,] = explode ('/ ' , $ url , 4 );
@@ -249,7 +265,7 @@ public function findMatchingRoute(string $url): array {
249265 $ this ->loadRoutes ('settings ' );
250266 } elseif (substr ($ url , 0 , 6 ) === '/core/ ' ) {
251267 \OC ::$ REQUESTEDAPP = $ url ;
252- if (!\ OC :: $ server -> getConfig () ->getSystemValueBool ('maintenance ' ) && !Util::needUpgrade ()) {
268+ if (!$ this -> config ->getSystemValueBool ('maintenance ' ) && !Util::needUpgrade ()) {
253269 \OC_App::loadApps ();
254270 }
255271 $ this ->loadRoutes ('core ' );
@@ -276,6 +292,7 @@ public function findMatchingRoute(string $url): array {
276292 }
277293 }
278294
295+ $ this ->eventLogger ->end ('route:match ' );
279296 return $ parameters ;
280297 }
281298
@@ -289,7 +306,7 @@ public function findMatchingRoute(string $url): array {
289306 public function match ($ url ) {
290307 $ parameters = $ this ->findMatchingRoute ($ url );
291308
292- \ OC :: $ server -> getEventLogger () ->start ('run_route ' , 'Run route ' );
309+ $ this -> eventLogger ->start ('route:run ' , 'Run route ' );
293310 if (isset ($ parameters ['caller ' ])) {
294311 $ caller = $ parameters ['caller ' ];
295312 unset($ parameters ['caller ' ]);
@@ -303,13 +320,15 @@ public function match($url) {
303320 }
304321 unset($ parameters ['action ' ]);
305322 unset($ parameters ['caller ' ]);
323+ $ this ->eventLogger ->start ('route:run:call ' , 'Run callable route ' );
306324 call_user_func ($ action , $ parameters );
325+ $ this ->eventLogger ->end ('route:run:call ' );
307326 } elseif (isset ($ parameters ['file ' ])) {
308327 include $ parameters ['file ' ];
309328 } else {
310329 throw new \Exception ('no action available ' );
311330 }
312- \ OC :: $ server -> getEventLogger () ->end ('run_route ' );
331+ $ this -> eventLogger ->end ('route:run ' );
313332 }
314333
315334 /**
@@ -434,7 +453,7 @@ private function getApplicationClass(string $appName) {
434453 $ applicationClassName = $ appNameSpace . '\\AppInfo \\Application ' ;
435454
436455 if (class_exists ($ applicationClassName )) {
437- $ application = \ OC :: $ server -> query ($ applicationClassName );
456+ $ application = $ this -> container -> get ($ applicationClassName );
438457 } else {
439458 $ application = new App ($ appName );
440459 }
0 commit comments