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

Jan Schneider jan at horde.org
Mon Aug 8 12:29:06 PDT 2005


jan  Mon, 08 Aug 2005 12:29:06 -0700

Modified page: http://wiki.horde.org/Doc/Dev/FrameworkPackage
New Revision:  1.1
Change log:  Initial content

@@ -1 +1,78 @@
++ Registry::
 
+Registry usage example:
+
+<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>
+
+Creating the Registry object, one can control how and if a session is started. Note that this only works if calling {{Registry::singleton()}} for the first time.
+
+<code type="php">
+// Let the registry start a regular session.
+$registry = &Registry::singleton();
+
+// Let the registry start a readonly session.
+$registry = &Registry::singleton(HORDE_SESSION_READONLY);
+
+// Don't let the registry start a session.
+$registry = &Registry::singleton(HORDE_SESSION_NONE);
+</code>
+
+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>
+
+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);
+
+// Using Horde 3.1 and PHP 5, calling API methods is even more elegant:
+$results = $registry->contacts->search($args);
+</code>


More information about the cvs mailing list