[cvs] [Wiki] changed: Doc/Dev/Registry

Jan Schneider jan at horde.org
Sun Aug 7 13:54:35 PDT 2005


jan  Sun, 07 Aug 2005 13:54:35 -0700

Modified page: http://wiki.horde.org/Doc/Dev/Registry
New Revision:  1.2
Change log:  Add more stuff from oscon2001-horde_tutorial

@@ -1,5 +1,77 @@
 + The Registry
+
+Horde's Registry is the glue that holds different applications together
+
+<code type="php">
+require_once HORDE_BASE . 'Horde/Registry.php';
+
+// The Registry has a singleton method that should be used to ensure
+// that there is only ever one instance of the Registry during a request.
+$registry = &Registry::singleton();
+
+// All applications should put themselves on the application stack when they start running
+// This also takes care of reading the application's configuration file.
+$registry->pushApp('curapp');
+
+// When an app is finished, pop it off the application stack
+// This also returns the global $conf variable to that of the previous application.
+$registry->popApp();
+
+// Routines can determine the current app:
+$curapp = $registry->getApp();
+
+// Find out if an application allows access for the current user (may be a guest user)
+if ($registry->hasPermission('app')) {
+    // access allowed
+}
+</code>
+
+* The Registry system keeps track of Horde's application stack, and which app is currently running.
+* When you switch applications, the registry will take care of switching the gettext textdomain correctly.
+* It also lets you determine configuration information about installed applications.
+
+The Registry lets you generate links to other apps
+
+<code type="php">
+require_once HORDE_BASE . 'Horde/Registry.php';
+$registry = &Registry::singleton();
+
+// Check to see if the functionality we want is there
+if (!$registry->hasMethod('mail/compose')) {
+    echo 'no mail/compose method defined';
+    exit;
+}
+
+// Generate the link
+echo $registry->link('mail/compose', array('to' => 'foo at example.com', 'subject' => 'bar'));
+</code>
+
+* Links will be to the application that provides the functionality.
+* Any arguments that the target script needs (headers for an email, for instance) will be filled out of the second argument to link().
+
+The Registry also lets you invoke methods in other applications
+
+<code type="php">
+require_once HORDE_BASE . 'Horde/Registry.php';
+$registry = &Registry::singleton();
+
+// Check to see if the functionality we want is there
+if (!$registry->hasMethod('contacts/search')) {
+    echo 'no contacts/search method defined';
+    exit;
+}
+
+// The contacts/search method takes two arrays; one of names, one of addressbooks
+$args = array('sources' => array('myldap'),
+                         'names' => array('Chuck'),
+                          'fields' => array('name', 'email'));
+$results = $registry->call('contacts/search', $args);
+</code>
+
+* The registry config file defines where to find the code necessary to execute the method, and what application implements it.
+* Any application can be integrated this way; all you need to do is map it to the registry interface.
+
 
 ++ registry.php
 
 Here's an application's registry.php entry:


More information about the cvs mailing list