Documentation:

Back
phpchartPlus Documentation
Tsiavos Chris <[email protected]>
Date: 18-Feb-2005
License: GPL
4.3 Developing new backends
If you want to extend the available backends or introduce new ones to the phpchartPlus environment you have to implement each time the relevant interface . Note that interfaces is one of the new features PHP supports.
The CachingStrategy Interface
To develop a new CachingStrategy backend, your class must implement the CachingStrategy Interface

- The Interface

The function Initialize is used to initialize the CachingStrategy object. It must return void and accepts as parameters:
  • The Content-Type value of the generated image $CacheImageType
  • The validity period of the cached image $CacheForMinutes
  • an arbitrary number of caching-specific parameters to the strategy object $Params. For example in a database backend the database connection parameters

The function CacheImage
is the place where the caching is actually done, so any mechanisms required to perform the request operation should be here.

- Indicating errors

If you want to indicate a faulty situation, such as improper initialization or image caching you can throw a CachingStrategy exception and let the caller decide what to do with the error.
class CachingStrategy_Exception extends Exception {               
function CachingStrategy_Exception($data) {
   Exception::__construct($data);
   }   
}

Interface CachingStrategy_Interface {
                 
   public function Initialize
($CacheImageType,$CacheForMinutes,$Params); public function CacheImage();
}
The ConfigStrategy Interface
To develop a new ConfigStrategy backend, your class must implement the ConfigStrategy Interface

- The Interface

The function initialize
is used to initialize the ConfigStrategy object. It must return void and accepts an arbitrary number of configuration-specific parameters in variable $params. For example in an XMLConfig backend the filename of the xml data file.

The function readData
is the place where the reading of data is actually done. The configuration parameters are returned in a ConfigData object which the client uses, the ConfigParser, to obtain the actual values. This function also accepts an arbitrary number of parameters in variable $params. These parameters can be an array of data to read as in the case of PHPConfig Strategy

The function finalize
is used to finalize the strategy object. Any cleanup code such as closing file descriptors or database connections should be put here.


- Indicating errors

If you want to indicate a faulty situation, such as improper initialization or data import you can throw a ConfigStrategy exception and let the caller decide what to do with the error.
class ConfigStrategy_Exception extends Exception {
               
 function ConfigStrategy_Exception($data) {
    Exception::__construct($data);
 } 
}
   
class ConfigData {
 
  public $ImageWidth;
  public $ImageHeight;
  public $ImageOutputType;
  public $ChartTitle;
  public $ChartType;
  public $ChartUseBlending;
  public $ChartUseAntialias;
  public $ChartHmargin;
  public $ChartVmargin;
  public $ChartUseStatus;
  public $ImageColor_Start;
  public $ImageColor_Finish;
  public $ImageColor_Alpha;
  public $ChartColor_Start;
  public $ChartColor_Finish;
  public $ChartColor_Alpha;
  public $ChartBgImage;
  public $FontFileLocation;
  public $FontColor;
  public $FontWidth;
  public $FontHeight;
  public $FontSize;
  public $LegendColors=array();
  public $LegendColors_Alpha=array();
  public $GridNum;
  public $GridMinValue;
  public $GridMaxValue;
  public $GridColor;
}
Interface ConfigStrategy_Interface {
     
   public function initialize($params=NULL);
   
   public function readData($params=NULL); 
   //returns ConfigData
   
   public function finalize();

}
The DataStrategy Interface
To develop a new DataStrategy backend, your class must implement the DataStrategy Interface

- The Interface

The function initialize
is used to initialize the DataStrategy object. It must return void and accepts an arbitrary number of data-specific parameters in variable $params. For example in an TXTData backend the filename of the TXT data file.

The function perform
is the place where the reading of data is actually done. The data read are returned as an array of Group classes. Each Group class has two attributes, the Group name and an array of GroupItem classes and each GroupItem class has an ItemName and ItemValue members. This function also accepts an arbitrary number of parameters in variable $params. These parameters can be for example the sql database query as in the case of PEARDBData Strategy.

The function finalize
is used to finalize the strategy object. Any cleanup code such as closing file descriptors or database connections should be put here.

- Indicating errors

If you want to indicate a faulty situation, such as improper initialization or data import you can throw a DataStrategy exception and let the caller decide what to do with the error.
class DataStrategy_Exception extends Exception {               
   function DataStrategy_Exception($data) {
   Exception::__construct($data);
   }

}

class GroupItem {

   public $ItemName;
   public $ItemValue;

}
class Group {
   public $GroupName;
   public $GroupItems=array();
}
Interface DataStrategy_Interface {
   public function initialize($params=NULL);
   
   public function perform($params=NULL); 
   
   public function finalize();
}

 
Hosted by www.Geocities.ws

1