Registry

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

URLRewriting: URL rewriting configuration

URLBasePath: URL of your current application

Environment: Environment variable used for configuration issues

LogDir: Path to your log directory

LibPath: Path to your source code files

CurrentRequestURL: Fully qualified request url. You may also use the
Url class for url generation.

Charset: Internal character set (e.g. for filter; default is UTF-8)

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.

The Registry was re-implemented to a static container for performance reasons in 1.12.
In all previous release the Registry must be created using

PHP code

$reg = &Singleton::getInstance('Registry');

Afterwards, it can be addressed as any other object. The Registry instance features two
methods: register() and retrieve(). These methods have the identical interface
as the implementation in 1.12.

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:

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:

PHP code

// action will succeed
Registry::register('modules::mymodule','MyModuleID',1,true);
// action will last in an error
Registry::register('modules::mymodule','MyModuleID',2);

Comments

Do you want to add a comment to the article above, or do you want to post additional hints? So please click
here.
Comments already posted can be found below.