Esempio n. 1
0
 /**
  * Loads the routes
  *
  * @param null|string $app
  */
 public function loadRoutes($app = null)
 {
     if (is_string($app)) {
         $app = \OC_App::cleanAppId($app);
     }
     $requestedApp = $app;
     if ($this->loaded) {
         return;
     }
     if (is_null($app)) {
         $this->loaded = true;
         $routingFiles = $this->getRoutingFiles();
     } else {
         if (isset($this->loadedApps[$app])) {
             return;
         }
         $file = \OC_App::getAppPath($app) . '/appinfo/routes.php';
         if ($file !== false && file_exists($file)) {
             $routingFiles = [$app => $file];
         } else {
             $routingFiles = [];
         }
     }
     \OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes');
     foreach ($routingFiles as $app => $file) {
         if (!isset($this->loadedApps[$app])) {
             if (!\OC_App::isAppLoaded($app)) {
                 // app MUST be loaded before app routes
                 // try again next time loadRoutes() is called
                 $this->loaded = false;
                 continue;
             }
             $this->loadedApps[$app] = true;
             $this->useCollection($app);
             $this->requireRouteFile($file, $app);
             $collection = $this->getCollection($app);
             $collection->addPrefix('/apps/' . $app);
             $this->root->addCollection($collection);
         }
     }
     if (!isset($this->loadedApps['core'])) {
         $this->loadedApps['core'] = true;
         $this->useCollection('root');
         require_once __DIR__ . '/../../../settings/routes.php';
         require_once __DIR__ . '/../../../core/routes.php';
     }
     if ($this->loaded) {
         // include ocs routes, must be loaded last for /ocs prefix
         require_once __DIR__ . '/../../../ocs/routes.php';
         $collection = $this->getCollection('ocs');
         $collection->addPrefix('/ocs');
         $this->root->addCollection($collection);
     }
     \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp);
 }