From 7952c6a31c27718428fddbca71c587506eb071d8 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 2 Aug 2012 17:47:38 +0200 Subject: [PATCH] Change access to router object to getter function --- lib/api.php | 2 +- lib/base.php | 18 ++++++++++++------ ocs/v1.php | 6 +++--- 3 files changed, 16 insertions(+), 10 deletions(-) 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) {