Documentation is available at ConfigParser.php
<?php /* ************************************************** Class: ConfigParser.php ************************************************** Author: Tsiavos Chris <jaames@freemail.gr> Date: October 2004 **************************************************/ /** *Includes the ChartData class, the common communication structure between *ConfigStrategy objects and ConfigParser */ require_once("ConfigStrategy_Interface.php"); class ConfigParser_Exception extends Exception { function ConfigParser_Exception($data) { Exception::__construct($data); } } /** *Class for importing configuration data to the application *This class can be strategized with the appropriate Strategy Object to support the collection and *parsing of data in a way independent of the configuration source implementation details. *@final *@author Tsiavos Chris <jaames@freemail.gr> *@license http://opensource.org/licenses/gpl-license.php GNU Public License */ final class ConfigParser { /** *Holds a reference to the selected ConfigStrategy instance *@access private *@var mixed */ private $Parser_Strategy; /** *Specifies the object containing the parsed configuration data *returned by the selected Strategy Object *@access private *@var ConfigData */ private $Parser_Results; /** *Constructor */ function __construct() { } /** *Destructor.Calls the finalize method of the selected Strategy Object for clean-up */ function __destruct() { $this->Parser_Strategy->finalize(); } /** *Instructs the selected Strategy Object to collect and return the configuration data *to ConfigParser for analysis *@access public *@return void *@param mixed $params Specifies an arbitrary number of parameters passed to the *sselected Strategy Object during data parsing */ public function parse($params=NULL) { if (!is_object($this->Parser_Strategy)) throw new ConfigParser_Exception("ConfigParser: No strategy found"); $this->Parser_Results=$this->Parser_Strategy->readData($params); //a chance to throw an exception $this->get_ImageWidth(); $this->get_ImageHeight(); $this->get_ImageOutputType(); $this->get_ChartType(); $this->get_ChartUseBlending(); $this->get_ChartUseAntialias(); $this->get_ChartHmargin(); $this->get_ChartVmargin(); $this->get_ChartUseStatus(); $this->get_ImageColor_Alpha(); $this->get_ChartColor_Alpha(); $this->get_ChartBgImage(); $this->get_FontFileLocation(); $this->get_GridNum(); $this->get_GridMinValue(); } /** *Strategizes the ConfigParser with the selected Strategy object *@access public *@return void *@param mixed &$Parser_Strategy_Object *@param mixed $params Specifies an arbitrary number of parameters passed to the *sselected Strategy Object */ public function strategize(&$Strategy_Object,$params=NULL) { $this->Parser_Strategy=$Strategy_Object; $this->Parser_Strategy->initialize($params); } /** *@access public *@return integer *@throws ConfigParser_Exception */ public function get_ImageWidth() { if ($this->Parser_Results->ImageWidth<0) throw new ConfigParser_Exception("ConfigParser: Invalid ImageWidth value"); return $this->Parser_Results->ImageWidth; } /** *@access public *@return integer *@throws ConfigParser_Exception */ public function get_ImageHeight() { if ($this->Parser_Results->ImageHeight<0) throw new ConfigParser_Exception("ConfigParser: Invalid ImageHeight value"); return $this->Parser_Results->ImageHeight; } /** *Returns the Image's content-type value *@access public *@return integer *@throws ConfigParser_Exception */ public function get_ImageOutputType() { $ImageOutputType=$this->Parser_Results->ImageOutputType; if (!($ImageOutputType=="png" || $ImageOutputType=="jpeg" || $ImageOutputType=="gif")) throw new ConfigParser_Exception("ConfigParser: Invalid ImageOutputType"); return $ImageOutputType; } /** *@access public *@return string */ public function get_ChartTitle() { return $this->Parser_Results->ChartTitle; } /** *Returns the chart type *@access public *@return string *@throws ConfigParser_Exception */ public function get_ChartType() { $ChartType=$this->Parser_Results->ChartType; if (!($ChartType=="Bar" || $ChartType=="Area" || $ChartType=="Line" || $ChartType=="Pie")) throw new ConfigParser_Exception("ConfigParser: Invalid ChartType"); return $ChartType; } /** *Determines if phpchartPlus will use blending for the generated chart image *@access public *@return string ("Yes","No") *@throws ConfigParser_Exception */ public function get_ChartUseBlending() { $ChartUseBlending=$this->Parser_Results->ChartUseBlending; if (!($ChartUseBlending=="Yes" || $ChartUseBlending=="No")) throw new ConfigParser_Exception("ConfigParser: Invalid Blend value.Use Yes or No"); return $ChartUseBlending; } /** *Determines if phpchartPlus will use antialias functions *@access public *@return string ("Yes","No") *@throws ConfigParser_Exception */ public function get_ChartUseAntialias() { $ChartUseAntialias=$this->Parser_Results->ChartUseAntialias; if (!($ChartUseAntialias=="Yes" || $ChartUseAntialias=="No")) throw new ConfigParser_Exception("ConfigParser: Invalid Antialias value.Use Yes or No"); return $ChartUseAntialias; } /** *Returns chart's x-distance from the top left corner of the image *@access public *@return integer *@throws ConfigParser_Exception */ public function get_ChartHmargin() { if ($this->Parser_Results->ChartHmargin<0) throw new ConfigParser_Exception("ConfigParser: Invalid ChartHmargin value"); return $this->Parser_Results->ChartHmargin; } /** *Returns chart's y-distance from the top left corner of the image *@access public *@return integer *@throws ConfigParser_Exception */ public function get_ChartVmargin() { if ($this->Parser_Results->ChartVmargin<0) throw new ConfigParser_Exception("ConfigParser: Invalid ImageVmargin value"); return $this->Parser_Results->ChartVmargin; } /** *Determines if phpchartPlus will use status indication for the generated chart *@access public *@return string ("Yes","No") *@throws ConfigParser_Exception */ public function get_ChartUseStatus() { $ChartUseStatus=$this->Parser_Results->ChartUseStatus; if (! ($ChartUseStatus=="Yes" || $ChartUseStatus=="No")) throw new ConfigParser_Exception("ConfigParser: Invalid ChartUseStatus value"); return $ChartUseStatus; } /** *Returns the starting color of the image area. If starting *color is diffrent from finishing color then the image area will be *filled with gradient color *@access public *@return string */ public function get_ImageColor_Start() { return $this->Parser_Results->ImageColor_Start; } /** *Returns the finishing color of the image area. If finishing *color is diffrent from starting color then the image area will be *filled with gradient color *@access public *@return string */ public function get_ImageColor_Finish() { return $this->Parser_Results->ImageColor_Finish; } /** *Returns the image's color alpha value *@access public *@return integer *@throws ConfigParser_Exception */ public function get_ImageColor_Alpha() { $ImageColorAlpha=$this->Parser_Results->ImageColor_Alpha; if (($ImageColorAlpha<0) || ($ImageColorAlpha>127)) throw new ConfigParser_Exception("ConfigParser: Invalid ImageColor_Alpha value"); return $ImageColorAlpha; } /** *Returns the starting color of the chart area.If starting *color is diffrent from finishing color then the chart area will be *filled with gradient color *@access public *@return string */ public function get_ChartColor_Start() { return $this->Parser_Results->ChartColor_Start; } /** *Returns the finishing color of the chart area.If finishing *color is different from starting color then the chart area will be *filled with gradient color *@access public *@return string */ public function get_ChartColor_Finish() { return $this->Parser_Results->ChartColor_Finish; } /** *@access public *@return integer *@throws ConfigParser_Exception */ public function get_ChartColor_Alpha() { $ChartColorAlpha=$this->Parser_Results->ChartColor_Alpha; if (($ChartColorAlpha<0) || ($ChartColorAlpha>127)) throw new ConfigParser_Exception("ConfigParser: Invalid ChartColor_Alpha value"); return $ChartColorAlpha; } /** *Returns the full path of chart's background image. If the value *returned is null then no background image will be used *@access public *@return string *@throws ConfigParser_Exception */ public function get_ChartBgImage() { if ($this->Parser_Results->ChartBgImage!=NULL) { if (!file_exists($this->Parser_Results->ChartBgImage)) throw new ConfigParser_Exception("ConfigParser: Background image not found"); } return $this->Parser_Results->ChartBgImage; } /** *Returns the full path of the FreeType2 font the chart will use for drawing *characters in the chart image *@access public *@return string *@throws ConfigParser_Exception */ public function get_FontFileLocation() { if ($this->Parser_Results->FontFileLocation!=NULL) { if (!file_exists($this->Parser_Results->FontFileLocation)) throw new ConfigParser_Exception("ConfigParser: Font file not found"); } return $this->Parser_Results->FontFileLocation; } /** *Returns the font color *@access public *@return string */ public function get_FontColor() { return $this->Parser_Results->FontColor; } /** *Returns the width of the built-in font *@access public *@return string */ public function get_FontWidth() { return $this->Parser_Results->FontWidth; } /** *Returns the height of the built-in font *@access public *@return string */ public function get_FontHeight() { return $this->Parser_Results->FontHeight; } /** *Returns the font size of the selected FreeType2 font *@access public *@return string */ public function get_FontSize() { return $this->Parser_Results->FontSize; } /** *Returns an array holding the legend colors *@access public *@return string[] */ public function get_LegendColors() { return $this->Parser_Results->LegendColors; } /** *Returns the alpha value of the legend's colors *@access public *@return integer[] */ public function get_LegendColors_Alpha() { return $this->Parser_Results->LegendColors_Alpha; } /** *Returns the number of the grids phpchartPlus will use *for segmentating the chart area *@access public *@return integer *@throws ConfigParser_Exception */ public function get_GridNum() { if ($this->Parser_Results->GridNum<=0) throw new ConfigParser_Exception("ConfigParser: Invalid GridNum value"); return $this->Parser_Results->GridNum; } /** *Returns the minimum grid value *@access public *@return integer *@throws ConfigParser_Exception */ public function get_GridMinValue() { if ($this->Parser_Results->GridMinValue<0) { if (abs($this->Parser_Results->GridMinValue)!=$this->get_GridMaxValue()) throw new ConfigParser_Exception("ConfigParser: Sum of GridMinValue and GridMaxValue should be zero"); } else if ($this->Parser_Results->GridMinValue>0) throw new ConfigParser_Exception("ConfigParser: GridMinValue should start from zero"); return $this->Parser_Results->GridMinValue; } /** *Returns the maximum grid value *@access public *@return integer */ public function get_GridMaxValue() { return $this->Parser_Results->GridMaxValue; } /** *Returns the grid color *@access public *@return string */ public function get_GridColor() { return $this->Parser_Results->GridColor; } } ?>