Class reference table - Registry

Rank article:
This article has not yet been ranked. Vote this article first of all!

1. Introduction

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.


2. Use the registry

In order to use the registy it must be created SINGLETON. Due to the fact, that the registry is already included and initialized in the page controller a simple
$Reg = &Singleton::getInstance('Registry'); 
can be used, to gather a singleton instance of the registry in the current scope. After that, the method register() can be utilized to change existing values or to register new values. The retrieve() function reades values from the registry. To be able to differenciate 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:
$Reg = &Singleton::getInstance('Registry');
$Reg->register('apf::core','URLRewriting',true);
$Reg->register('apf::core','URLBasePath','http://example.com/folder');
$Reg->register('apf::core','Environment','TESTSERVER');
$Reg->register('apf::core','LogDir','/path/to/my/log/dir'); 
Please note, that manipulation of the default parameters must be done before creating the page or frontcontroller. This is also reasonable for application directives.


3. Write protection

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:
// get a singleton instance of the registry
$Reg = &Singleton::getInstance('Registry');

// action will succeed
$Reg->register('modules::mymodule','MyModuleID',1,true);

// action will last in an error
$Reg->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.


There are no comments belonging to this article.