aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-04-23 17:47:00 -0700
committerredmatrix <git@macgirvin.com>2016-04-23 17:47:00 -0700
commit5b3f536613d1db389a7194d4ebe4a23505af0573 (patch)
treece050c69eb30908a632bec1345e948e267864458
parentce45a1cf945617f3895fb3e40b13e6f705fbc000 (diff)
downloadvolse-hubzilla-5b3f536613d1db389a7194d4ebe4a23505af0573.tar.gz
volse-hubzilla-5b3f536613d1db389a7194d4ebe4a23505af0573.tar.bz2
volse-hubzilla-5b3f536613d1db389a7194d4ebe4a23505af0573.zip
updated doco to document how to use hook callbacks which are object methods
-rw-r--r--doc/plugins.bb24
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/plugins.bb b/doc/plugins.bb
index f96fb8dee..f2f0b04e8 100644
--- a/doc/plugins.bb
+++ b/doc/plugins.bb
@@ -264,6 +264,30 @@ we will create an argc/argv list for use by your module functions
3 whatever
[/code]
+[h3]Using class methods as hook handler functions[/h3]
+
+To register a hook using a class method as a callback, a couple of things need to be considered. The first is that the functions need to be declared static public so that they are available from all contexts, and they need to have a namespace attached because they can be called from within multiple namespaces. You can then register them as strings or arrays (using the PHP internal calling method).
+
+[code]
+<?php
+/*
+ * plugin info block goes here
+ */
+
+function myplugin_load() {
+ Zotlabs\Extend\Hook::register('hook_name','addon/myplugin/myplugin.php','\\Myplugin::foo');
+[b]or[/b]
+ Zotlabs\Extend\Hook::register('hook_name','addon/myplugin/myplugin.php',array('\\Myplugin','foo'));
+}
+
+class Myplugin {
+
+ public static function foo($params) {
+ // handler for 'hook_name'
+ }
+}
+[/code]
+
If you want to keep your plugin hidden from the siteinfo page, simply create a file called '.hidden' in your addon directory
[code]
touch addon/<addon name>/.hidden