Path

ez components / documentation / api reference / 2006.2 / base


eZ Components 2006.2

Base: ezcBaseInit

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

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_nullself::$instance ) )
 5.      {
 6.          self::$instance new ezcConfigurationmanager();
 7.          ezcBaseInit::fetchConfig'ConfigurationManagerConfig'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 'ConfigurationManagerConfig' to 'cfgConfigurationManager':
1.  <?php
2.  ezcBaseInit::setCallback'ConfigurationManagerConfig''cfgConfigurationManager' );
3.  ?>
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
3.  {
4.      static public function configureObjectezcConfigurationManager $cfgManagerObject )
5.      {
6.          $cfgManagerObject->init'ezcConfigurationIniReader''settings'array'useComments' => true ) );
7.      }
8.  }
9.  ?>
Ofcourse 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 void 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

void fetchConfig( string $identifier, object $object )
Uses the configured callback belonging to $identifier to configure the $object.

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: Thu, 01 Nov 2007