Registry

1. Introduction

The registry (see Registry) is used as a central store for global configuration parameters in the Adventure PHP Framework. Parameters in this case mean simple data types like string or numbers but objects as well.

Besides, the Registry is used for configuration of components within the core and tools section of the APF. The following list describes the used values:

Namespace Key Default value Description Usage
APF\core Environment DEFAULT Defiles the environment the application is used at. Details can be found under Configuration.
APF\core InternalLogTarget apf Defiles the name of the standard log target. Details can be found under Logger.
APF\core Charset UTF-8 Defines the character set for string functions. The character set is e.g. used within htmlspecialchars() or htmlentities() calls.

2. Use the registry

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 above default values, the following PHP code can be used:

PHP code
Registry::register('APF\core', 'Environment', 'TESTSERVER'); Registry::register('APF\core', 'InternalLogTarget', 'foo'); 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. Details on the configuration of your application within the bootstrap file can be taken from chapter Basics.

Getting the values of the above configured keys is as follows:

PHP code
$env = Registry::retrieve('APF\core', 'Environment'); $logTarget = Registry::retrieve('APF\core', 'InternalLogTarget'); $charset = Registry::retrieve('APF\core', 'Charset');

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('VENDOR\module', 'param-one', 1, true); // Action will last in an exception Registry::register('VENDOR\module', 'param-one', 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.