jan  Tue, 03 Oct 2017 14:41:39 +0000

Modified page: https://wiki.horde.org/Doc/Dev/RegistryUsage
New Revision:  6
Change log:  Update links

@@ -3,25 +3,25 @@
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 {{require_once}} statement that points to the application's {{lib/Application.php}} file. (All applications REQUIRE the lib/Application.php file. See the skeleton module for a stub [http://git.horde.org/co.php/skeleton/lib/Application.php?rt=horde-git lib/Application.php] that demonstrates what is required in that file). Requiring {{lib/Application.php}} will set up the base PHP environment and setup the proper autoloader paths for Horde libraries. +The first line of the script should be a {{require_once}} statement that points to the application's {{lib/Application.php}} file. (All applications REQUIRE the lib/Application.php file. See the skeleton module for a stub [https://github.com/horde/skeleton/blob/master/lib/Application.php lib/Application.php] that demonstrates what is required in that file). Requiring {{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 {{lib/Application.php}} will be its full pathname. For example, in an application {{foo}}, for the script {{bar.php}}, the following is needed:

 <code type="php">
 require_once dirname(__FILE__) . '/lib/Application.php';
 </code>

-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 [http://dev.horde.org/api/framework/Core/Core/Horde_Registry.html#appInit Horde_Registry::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: +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 [https://dev.horde.org/api/master/lib/Core/class-Horde_Registry.html#_appInit Horde_Registry::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:

 <code type="php">
 $appOb = Horde_Registry::appInit('foo');
 </code>

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.

-{{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 [http://dev.horde.org/api/framework/Core/Core/Horde_Registry.html#appInit here]. +{{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 [https://dev.horde.org/api/master/lib/Core/class-Horde_Registry.html#_appInit here].

**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 ((Doc/Dev/Globals|Horde global variables/constants)) are available.

--
commits mailing list
Frequently Asked Questions: http://wiki.horde.org/FAQ
To unsubscribe, mail: [email protected]

Reply via email to