Registry

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

  • 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.

2. Use the registry

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:

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'); 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.

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:

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.
« 1   »
Entries/Page: | 5 | 10 | 15 | 20 |
1
buy_cialis 25.11.2016, 14:37:17
Thanks in advance for answering Chosen Answer Why do u need to tell the girl its buy cialis.
2
erectile_problem 23.09.2016, 11:31:40
If you want to save your money you erectile problem for sale in dublin buy a refurbished computer.