\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
\part{Horde\_Registry}
\textbf{This information is valid for Horde 3 only.}

Registry usage example:

<pre><code class="language-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></pre>
Creating the Registry object, one can control how and if a session is started. Note that this only works if calling \texttt{Registry::singleton()} for the first time.

<pre><code class="language-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></pre>
The Registry lets you generate links to other apps

<pre><code class="language-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@example.com', 'subject' => 'bar'));
</code></pre>
The Registry also lets you invoke methods in other applications

<pre><code class="language-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></pre>
\end{document}
