[Pkg-owncloud-commits] [owncloud-doc] 81/270: more hooks documentation where it should go

David Prévot taffit at moszumanska.debian.org
Thu Jul 31 03:53:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud-doc.

commit f46964a2b95be50e74864671fbeee7df5257caf6
Author: Bernhard Posselt <dev at bernhard-posselt.com>
Date:   Mon May 12 16:14:58 2014 +0200

    more hooks documentation where it should go
---
 developer_manual/app/hooks.rst   | 77 +++++++++++++++++++++++++++++++++++++---
 developer_manual/app/request.rst |  6 ++--
 2 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/developer_manual/app/hooks.rst b/developer_manual/app/hooks.rst
index 0e9f50b..b5b130e 100644
--- a/developer_manual/app/hooks.rst
+++ b/developer_manual/app/hooks.rst
@@ -4,7 +4,67 @@ Hooks
 
 .. sectionauthor:: Bernhard Posselt <dev at bernhard-posselt.com>
 
-Hooks are used to execute code before or after an event has occured. This is for instance useful to run cleanup code after users, groups or files have been deleted.
+Hooks are used to execute code before or after an event has occured. This is for instance useful to run cleanup code after users, groups or files have been deleted. Hooks should be registered in the :doc:`app.php <init>`:
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\AppInfo;
+
+    $app = new Application();
+    $app->getContainer()->query('UserHooks')->register();
+
+The hook logic should be in a seperate class that is being registered in the :doc:`container`
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\AppInfo;
+
+    use \OCP\AppFramework\App;
+
+    use \OCA\MyApp\Hooks\UserHooks;
+
+
+    class Application extends App {
+
+        public function __construct(array $urlParams=array()){
+            parent::__construct('myapp', $urlParams);
+
+            $container = $this->getContainer();
+
+            /**
+             * Controllers
+             */
+            $container->registerService('UserHooks', function($c) {
+                return new UserHooks(
+                    $c->query('ServerContainer')->getUserManager()
+                );
+            });
+        }
+    }
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\Hooks;
+
+    class UserHooks {
+
+        private $userManager;
+
+        public function __construct($userManager){
+            $this->userManager = $userManager;
+        }
+
+        public function register() {
+            $callback = function($user) {
+                // your code that executes before $user is deleted
+            };
+            $userManager->listen('\OC\User', 'preDelete', $callback);
+        }
+
+    }
 
 Available hooks
 ===============
@@ -15,12 +75,21 @@ The scope is the first parameter that is passed to the **listen** method, the se
     <?php
     
     // listen on user predelete
-    $userManager->listen('\OC\User', 'preDelete', function($user) {
+    $callback = function($user) {
         // your code that executes before $user is deleted
-    });
+    };
+    $userManager->listen('\OC\User', 'preDelete', $callback);
+
+
+Hooks can also be removed by using the **removeListener** method on the object:
 
+.. code-block:: php
+
+    <?php
+    
+    // delete previous callback
+    $userManager->removeListener(null, null, $callback);
 
-Hooks can also be removed by using the **removeListener** method on the object.
 
 The following hooks are available:
 
diff --git a/developer_manual/app/request.rst b/developer_manual/app/request.rst
index 33d9808..a53ecf1 100644
--- a/developer_manual/app/request.rst
+++ b/developer_manual/app/request.rst
@@ -21,12 +21,12 @@ In the beginning, all requests are sent to ownCloud's :file:`index.php` which in
 * Filesystem
 * Logging
 
-The type of the app is determined by inspecting the app's :doc:`configuration file <info>` (:file:`appinfo/info.xml`). Loading apps means that the :doc:`main file <main>` (:file:`appinfo/app.php`) of each installed app is being loaded and executed. That means that if you want to execute code before a specific app is being run, you can place code in your app's :doc:`main` file.
+The type of the app is determined by inspecting the app's :doc:`configuration file <info>` (:file:`appinfo/info.xml`). Loading apps means that the :doc:`main file <init>` (:file:`appinfo/app.php`) of each installed app is being loaded and executed. That means that if you want to execute code before a specific app is being run, you can place code in your app's :doc:`init` file.
 
 Afterwards the following steps are performed:
 
-* Try to :doc:`authenticate the user <userbackend>`
-* Load and execute all the remaining apps' :doc:`main` files
+* Try to authenticate the user
+* Load and execute all the remaining apps' :doc:`init` files
 * Load and run all the routes in the apps' :file:`appinfo/routes.php`
 * Execute the router
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-doc.git



More information about the Pkg-owncloud-commits mailing list