Base: ezcBaseInit
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcBaseInit
|
Provides a method to implement delayed initialization of objects. [
source]
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:
1. <?php
2. public static function getInstance()
3. {
4. if ( is_null( self::$instance ) )
5. {
6. self::$instance = new ezcConfigurationmanager();
7. ezcBaseInit::fetchConfig( 'ezcInitConfigurationManager', self::$instance );
8. }
9. return self::$instance;
10. }
11. ?>
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':
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:
1. <?php
2. class cfgConfigurationManager implements ezcBaseConfigurationInitializer
3. {
4. static public function configureObject( ezcConfigurationManager $cfgManagerObject )
5. {
6. $cfgManagerObject->init( 'ezcConfigurationIniReader', 'settings', array( 'useComments' => true ) );
7. }
8. }
9. ?>
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).
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
mixed fetchConfig(
string
$identifier, object
$object )
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
void setCallback(
string
$identifier, string
$callbackClassname )
Adds the classname $callbackClassname as callback for the identifier $identifier.
Parameters
| Name |
Type |
Description |
$identifier |
string |
|
$callbackClassname |
string |
|
Last updated: Mon, 09 Feb 2009