Zeta Components Manual :: Docs For Class ezcBaseInit
Base::ezcBaseInit
Class ezcBaseInit
Provides a method to implement delayed initialization of objects.
With the methods in this class you can implement callbacks to configure singleton classes. In order to do so you will have to change the getInstance() method of your singleton class to include a call to ezcBaseInit::fetchConfig() as in the following example:
- <?php
- public static function getInstance()
- {
- {
- self::$instance = new ezcConfigurationmanager();
- }
- return self::$instance;
- }
- ?>
You will also need to configure which callback class to call. This you do with the ezcBaseInit::setCallback() method. The following examples sets the callback classname for the configuration identifier 'ezcInitConfigurationManager' to 'cfgConfigurationManager':
- <?php
- ?>
The class 'cfgConfigurationManager' is required to implement the ezcBaseConfigurationInitializer interface, which defines only one method: configureObject(). An example on how to implement such a class could be:
- <?php
- class cfgConfigurationManager implements ezcBaseConfigurationInitializer
- {
- static public function configureObject( ezcConfigurationManager $cfgManagerObject )
- {
- $cfgManagerObject->init( 'ezcConfigurationIniReader', 'settings', array( 'useComments' => true ) );
- }
- }
- ?>
Of course the implementation of this callback class is up to the application developer that uses the component (in this example the Configuration component's class ezcConfigurationManager).
Source for this file: /Base/src/init.php
Version: | //autogentag// |
Method Summary
public static mixed |
fetchConfig(
$identifier
, $object
)
Uses the configured callback belonging to $identifier to configure the $object. |
public static void |
setCallback(
$identifier
, $callbackClassname
)
Adds the classname $callbackClassname as callback for the identifier $identifier. |
Methods
fetchConfig
Uses the configured callback belonging to $identifier to configure the $object.
The method will return the return value of the callback method, or null in case there was no callback set for the specified $identifier.
Parameters:
Name | Type | Description |
---|---|---|
$identifier |
string | |
$object |
object |
setCallback
Adds the classname $callbackClassname as callback for the identifier $identifier.
Parameters:
Name | Type | Description |
---|---|---|
$identifier |
string | |
$callbackClassname |
string |