From 8a7681dc51bd3ffe960254bd2f82995acfdda9fc Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 19 Dec 2018 10:50:08 +0100 Subject: [PATCH] There is no need to register controllers. DI all the way Signed-off-by: Roeland Jago Douma --- developer_manual/app/classloader.rst | 1 + developer_manual/app/requests/controllers.rst | 36 ++----------------- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/developer_manual/app/classloader.rst b/developer_manual/app/classloader.rst index 53097161b..ed009eb7b 100644 --- a/developer_manual/app/classloader.rst +++ b/developer_manual/app/classloader.rst @@ -2,6 +2,7 @@ Classloader =========== +.. app_classloader: .. sectionauthor:: Bernhard Posselt The classloader is provided by Nextcloud and loads all your classes automatically. The only thing left to include by yourself are 3rdparty libraries. Those should be loaded in :file:`lib/AppInfo/Application.php`. diff --git a/developer_manual/app/requests/controllers.rst b/developer_manual/app/requests/controllers.rst index 1e9055ccc..502375e1d 100644 --- a/developer_manual/app/requests/controllers.rst +++ b/developer_manual/app/requests/controllers.rst @@ -28,40 +28,10 @@ To create a controller, simply extend the Controller class and create a method t Connecting a controller and a route ----------------------------------- -To connect a controller and a route the controller has to be registered in the :doc:`container` like this: +If you use a proper namespace for your app (see :ref:`app_classloader`) Nextcloud +will resolve your controller and its dependencies automatically. -.. code-block:: php - - getContainer(); - - /** - * Controllers - */ - $container->registerService('AuthorApiController', function($c) { - return new AuthorApiController( - $c->query('AppName'), - $c->query('Request') - ); - }); - } - } - -Every controller needs the app name and the request object passed into their parent constructor, which can easily be injected like shown in the example code above. The important part is not the class name but rather the string which is passed in as the first parameter of the **registerService** method. - -The other part is the route name. An example route name would look like this:: +An example route name would look like this:: author_api#some_method