From 993fea2f05ae300fd1036d2a82ba02413f2649d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 25 Nov 2013 11:36:33 +0100 Subject: [PATCH 1/3] fix appframework routing --- lib/private/appframework/app.php | 5 ++++- .../appframework/routing/routeactionhandler.php | 2 +- lib/public/appframework/app.php | 11 +++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/private/appframework/app.php b/lib/private/appframework/app.php index 6d3effbf1f..7d32403a55 100644 --- a/lib/private/appframework/app.php +++ b/lib/private/appframework/app.php @@ -44,7 +44,10 @@ class App { * @param string $methodName the method that you want to call * @param DIContainer $container an instance of a pimple container. */ - public static function main($controllerName, $methodName, IAppContainer $container) { + public static function main($controllerName, $methodName, DIContainer $container, array $urlParams = null) { + if (!is_null($urlParams)) { + $container['urlParams'] = $urlParams; + } $controller = $container[$controllerName]; // initialize the dispatcher and run all the middleware before the controller diff --git a/lib/private/appframework/routing/routeactionhandler.php b/lib/private/appframework/routing/routeactionhandler.php index 7fb56f14ea..2b9dc38dc4 100644 --- a/lib/private/appframework/routing/routeactionhandler.php +++ b/lib/private/appframework/routing/routeactionhandler.php @@ -37,6 +37,6 @@ class RouteActionHandler { } public function __invoke($params) { - App::main($this->controllerName, $this->actionName, $params, $this->container); + App::main($this->controllerName, $this->actionName, $this->container, $params); } } diff --git a/lib/public/appframework/app.php b/lib/public/appframework/app.php index 6ac48bf102..1f82f8da88 100644 --- a/lib/public/appframework/app.php +++ b/lib/public/appframework/app.php @@ -21,6 +21,7 @@ */ namespace OCP\AppFramework; +use OC\AppFramework\routing\RouteConfig; /** @@ -47,6 +48,16 @@ class App { return $this->container; } + /** + * This function is to be called + * @param \OC_Router $router + * @param array $routes + */ + public function registerRoutes($router, $routes) { + $routeConfig = new RouteConfig($this->container, $router, $routes); + $routeConfig->register(); + } + /** * This function is called by the routing component to fire up the frameworks dispatch mechanism. * From 1fdd2ac7eed9cfd0322e6f17957a083310311470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 25 Nov 2013 17:15:08 +0100 Subject: [PATCH 2/3] adding documentation for registerRoutes() --- lib/public/appframework/app.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/public/appframework/app.php b/lib/public/appframework/app.php index 1f82f8da88..1021a21397 100644 --- a/lib/public/appframework/app.php +++ b/lib/public/appframework/app.php @@ -49,7 +49,19 @@ class App { } /** - * This function is to be called + * This function is to be called to create single routes and restful routes based on the given $routes array. + * + * Example code in routes.php of tasks app (it will register two restful resources): + * $routes = array( + * 'resources' => array( + * 'lists' => array('url' => '/tasklists'), + * 'tasks' => array('url' => '/tasklists/{listId}/tasks') + * ) + * ); + * + * $a = new TasksApp(); + * $a->registerRoutes($this, $routes); + * * @param \OC_Router $router * @param array $routes */ From 7755e69af0fea0925afacd7b038b792b9fb0e3e1 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 27 Nov 2013 10:55:06 +0100 Subject: [PATCH 3/3] add PHPDoc for urlParams --- lib/private/appframework/app.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/appframework/app.php b/lib/private/appframework/app.php index 7d32403a55..b835188661 100644 --- a/lib/private/appframework/app.php +++ b/lib/private/appframework/app.php @@ -43,6 +43,7 @@ class App { * stored in the DI container * @param string $methodName the method that you want to call * @param DIContainer $container an instance of a pimple container. + * @param array $urlParams list of URL parameters (optional) */ public static function main($controllerName, $methodName, DIContainer $container, array $urlParams = null) { if (!is_null($urlParams)) {