\documentclass{article}
\usepackage{ulem}
\pagestyle{headings}
\begin{document}
\part{Horde\_Registry}
Horde\_Registry is responsible for setting up the Horde environment and coordinating interaction between Horde, its libraries, and Horde applications.  It must be initialized at the very beginning of any script that will be using the Horde framework.

The typical use pattern for a script will be as follows.

The first line of the script should be a \texttt{require\_once} statement that points to the application's \texttt{lib/Application.php} file.  (All applications REQUIRE the lib/Application.php file.  See the skeleton module for a stub lib/Application.php\footnote{https://github.com/horde/skeleton/blob/master/lib/Application.php} that demonstrates what is required in that file).  Requiring \texttt{lib/Application.php} will set up the base PHP environment and setup the proper autoloader paths for Horde libraries.

Since your script lives in a known location in the application layout, and autoloading is not yet setup at this point, the filepath needed to load \texttt{lib/Application.php} will be its full pathname.  For example, in an application \texttt{foo}, for the script \texttt{bar.php}, the following is needed:

\begin{verbatim}

require_once dirname(__FILE__) . '/lib/Application.php';
\end{verbatim}

At this point, autoloading is available, but the Registry has not yet been initialized.  This is because we may want to configure various aspects of the Registry prior to loading.  To facilitate this configuration, the static function Horde\_Registry::appInit()\footnote{https://dev.horde.org/api/master/lib/Core/class-Horde\_Registry.html\#\_appInit} is provided.  This function has two parameters: the application being initialized (REQUIRED) and an array of configuration options (OPTIONAL).  By default, appInit() will assume the script is being run from the web, that the user must be authenticated and have the necessary permissions to access the application, that output compression should be turned on, and that the session should be opened read-write.  For example, to initialize the application 'foo' with the default arguments, the following is needed:

\begin{verbatim}

$appOb = Horde_Registry::appInit('foo');
\end{verbatim}

On authentication success, \$appOb will be set to the Horde\_Registry\_Application instance for the current application.  On authentication failure the default action is to redirect the user to the login page.

\texttt{Horde\_Registry::appInit()} has several configuration options that can be used to tweak environment initialization and authentication error handling.  A full list of these configuration options can be found here\footnote{https://dev.horde.org/api/master/lib/Core/class-Horde\_Registry.html\#\_appInit}.

\textbf{Horde\_Registry::appInit() should ONLY be called as the first lines in a script - it is simply a shortcut to bootstrap/initialize the Horde environment.  It should NEVER be used otherwise (e.g. within a library) to initialize an application.}

Once the Registry has been initialized, all Horde global variables/constants\footnote{http://example.com/index.php?page=Doc/Dev/Globals} are available.

In conclusion, the following is the minimum needed to initialize the Horde environment at the beginning of the script:

\begin{verbatim}

require_once dirname(__FILE__) . '/lib/Application.php';
$appOb = Horde_Registry::appInit('foo');
\end{verbatim}

\section{Horde\_Registry\_Application}
TODO

init()

\section{Linking to another application}
Here is example code on the code needed to create a link to another application:

\begin{verbatim}

// Check to see if the functionality we want is there
if (!$registry->hasMethod('mail/compose')) {
    exit('No mail/compose method defined');
}

// Generate the link
echo $registry->link('mail/compose', array('to' => 'foo@example.com', 'subject' => 'bar'));
\end{verbatim}

\section{Calling API methods}
Calling an API method in another application can be done like this:

\begin{verbatim}

// Check to see if the functionality we want is there
if (!$registry->hasMethod('contacts/search')) {
    exit('No contacts/search method defined');
}

// 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')
);

// "Classic" method 
$results = $registry->call('contacts/search', $args);

// -or- "New" method
$results = $registry->contacts->search($args);
\end{verbatim}

\section{pushApp()/popApp()}
TODO

\section{getAuth()}
This method returns the currently logged-in Horde user.

\section{Application version}
The version number of an application (in this example, application 'foo') can be obtained from Horde\_Registry with the following code:

\begin{verbatim}

$version = $registry->getVersion('foo');
\end{verbatim}

\end{document}
