The registry (see registry pattern) is used as a central store for configuration parameters in the Adventure PHP Framework. Parameters in this case mean simple data types like string or numbers but objects as well. The registry is used to store the directives
that are used by the core and tools components in the namespace apf::core. However, it can also be used as a configuration parameter container for your applications.
$reg = &Singleton::getInstance('Registry');
Since release 1.12 the Registry is implemented as a static container for global configuration purpose of the framework and for custom configuration. The method register() can be utilized to change existing values or to register new values. The retrieve() function reads values from the registry. To be able to differentiate between the various param domains the registry features namespaces. In order to not produce interferences with other param domains, it is well to use the namespace of your application as a namespace within the registry.
In order to manipulate the default values of the apf::core namespace, the following PHP code can be used:
Registry::register('apf::core', 'URLRewriting', true); Registry::register('apf::core', 'URLBasePath', 'http://example.com/folder'); Registry::register('apf::core', 'Environment', 'TESTSERVER'); Registry::register('apf::core', 'LogDir', '/path/to/my/log/dir'); Registry::register('apf::core', 'Charset', 'UTF-16');
Please note, that manipulation of the default parameters must be done before creating the page or front controller. This is also reasonable for application directives.
In many cases, it is necessary to provide write protection to application parameters stored in the registry. Thus, the registry provides write protection as well. This feature can be activated on every param by a forth parameter to the register() method. If this switch is enabled, the value cannot be manipulated within the whole request. The following code sample can be used as a code template for configuring write protection:
// action will succeed Registry::register('modules::mymodule','MyModuleID',1,true); // action will last in an error Registry::register('modules::mymodule','MyModuleID',2);