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)
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
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:
PHP-Code
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');
Please note, that manipulation of the default parameters must be done before creating the page or
frontcontroller. 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:
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.
There are no comments belonging to this article.