diff --git a/lib/api.php b/lib/api.php index 6ee570d60e..155082fa0d 100644 --- a/lib/api.php +++ b/lib/api.php @@ -44,7 +44,7 @@ class OC_API { $name = strtolower($method).$url; $name = str_replace(array('/', '{', '}'), '_', $name); if(!isset(self::$actions[$name])){ - OC::$router->create($name, $url.'.{_format}') + OC::getRouter()->create($name, $url.'.{_format}') ->method($method) ->defaults(array('_format' => 'xml') + $defaults) ->requirements(array('_format' => 'xml|json') + $requirements) diff --git a/lib/base.php b/lib/base.php index 29a3502e35..43588944d0 100644 --- a/lib/base.php +++ b/lib/base.php @@ -62,14 +62,14 @@ class OC{ * requested file of app */ public static $REQUESTEDFILE = ''; - /* - * OC router - */ - public static $router = null; /** * check if owncloud runs in cli mode */ public static $CLI = false; + /* + * OC router + */ + protected static $router = null; /** * SPL autoload */ @@ -275,6 +275,14 @@ class OC{ } } + public static function getRouter() { + if (!isset(OC::$router)) { + OC::$router = new OC_Router(); + } + + return OC::$router; + } + public static function init(){ // register autoloader spl_autoload_register(array('OC','autoload')); @@ -358,8 +366,6 @@ class OC{ OC_User::useBackend(new OC_User_Database()); OC_Group::useBackend(new OC_Group_Database()); - OC::$router = new OC_Router(); - // Load Apps // This includes plugins for users and filesystems as well global $RUNTIME_NOAPPS; diff --git a/ocs/v1.php b/ocs/v1.php index 7cd61035e7..cb8a1faf87 100644 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -25,11 +25,11 @@ require_once('../lib/base.php'); use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Exception\MethodNotAllowedException; -OC::$router->useCollection('ocs'); -OC::$router->loadRoutes(); +OC::getRouter()->useCollection('ocs'); +OC::getRouter()->loadRoutes(); try { - OC::$router->match($_SERVER['PATH_INFO']); + OC::getRouter()->match($_SERVER['PATH_INFO']); } catch (ResourceNotFoundException $e) { OC_OCS::notFound(); } catch (MethodNotAllowedException $e) {