[ class tree: phpchartPlus ] [ index: phpchartPlus ] [ all elements ]

Source for file ConfigParser.php

Documentation is available at ConfigParser.php

  1. <?php
  2.  
  3. /*
  4. **************************************************
  5. Class: ConfigParser.php
  6. **************************************************
  7. Author: Tsiavos Chris <jaames@freemail.gr>
  8. Date: October 2004
  9. **************************************************/
  10.  
  11. /**
  12. *Includes the ChartData class, the common communication structure between
  13. *ConfigStrategy objects and ConfigParser
  14. */
  15. require_once("ConfigStrategy_Interface.php");
  16.  
  17. class ConfigParser_Exception extends Exception {
  18. function ConfigParser_Exception($data) {
  19. Exception::__construct($data);
  20. }
  21. }
  22.  
  23. /**
  24. *Class for importing configuration data to the application
  25. *This class can be strategized with the appropriate Strategy Object to support the collection and
  26. *parsing of data in a way independent of the configuration source implementation details.
  27. *@final
  28. *@author Tsiavos Chris <jaames@freemail.gr>
  29. *@license http://opensource.org/licenses/gpl-license.php GNU Public License
  30. */
  31.  
  32. final class ConfigParser {
  33.  
  34. /**
  35. *Holds a reference to the selected ConfigStrategy instance
  36. *@access private
  37. *@var mixed
  38. */
  39. private $Parser_Strategy;
  40. /**
  41. *Specifies the object containing the parsed configuration data
  42. *returned by the selected Strategy Object
  43. *@access private
  44. *@var ConfigData
  45. */
  46. private $Parser_Results;
  47. /**
  48. *Constructor
  49. */
  50. function __construct() { }
  51. /**
  52. *Destructor.Calls the finalize method of the selected Strategy Object for clean-up
  53. */
  54. function __destruct() {
  55. $this->Parser_Strategy->finalize();
  56. }
  57. /**
  58. *Instructs the selected Strategy Object to collect and return the configuration data
  59. *to ConfigParser for analysis
  60. *@access public
  61. *@return void
  62. *@param mixed $params Specifies an arbitrary number of parameters passed to the
  63. *sselected Strategy Object during data parsing
  64. */
  65. public function parse($params=NULL) {
  66. if (!is_object($this->Parser_Strategy))
  67. throw new ConfigParser_Exception("ConfigParser: No strategy found");
  68. $this->Parser_Results=$this->Parser_Strategy->readData($params);
  69. //a chance to throw an exception
  70. $this->get_ImageWidth();
  71. $this->get_ImageHeight();
  72. $this->get_ImageOutputType();
  73. $this->get_ChartType();
  74. $this->get_ChartUseBlending();
  75. $this->get_ChartUseAntialias();
  76. $this->get_ChartHmargin();
  77. $this->get_ChartVmargin();
  78. $this->get_ChartUseStatus();
  79. $this->get_ImageColor_Alpha();
  80. $this->get_ChartColor_Alpha();
  81. $this->get_ChartBgImage();
  82. $this->get_FontFileLocation();
  83. $this->get_GridNum();
  84. $this->get_GridMinValue();
  85. }
  86. /**
  87. *Strategizes the ConfigParser with the selected Strategy object
  88. *@access public
  89. *@return void
  90. *@param mixed &$Parser_Strategy_Object
  91. *@param mixed $params Specifies an arbitrary number of parameters passed to the
  92. *sselected Strategy Object
  93. */
  94. public function strategize(&$Strategy_Object,$params=NULL) {
  95. $this->Parser_Strategy=$Strategy_Object;
  96. $this->Parser_Strategy->initialize($params);
  97. }
  98. /**
  99. *@access public
  100. *@return integer
  101. *@throws ConfigParser_Exception
  102. */
  103. public function get_ImageWidth() {
  104. if ($this->Parser_Results->ImageWidth<0)
  105. throw new ConfigParser_Exception("ConfigParser: Invalid ImageWidth value");
  106. return $this->Parser_Results->ImageWidth;
  107. }
  108. /**
  109. *@access public
  110. *@return integer
  111. *@throws ConfigParser_Exception
  112. */
  113. public function get_ImageHeight() {
  114. if ($this->Parser_Results->ImageHeight<0)
  115. throw new ConfigParser_Exception("ConfigParser: Invalid ImageHeight value");
  116. return $this->Parser_Results->ImageHeight;
  117. }
  118. /**
  119. *Returns the Image's content-type value
  120. *@access public
  121. *@return integer
  122. *@throws ConfigParser_Exception
  123. */
  124. public function get_ImageOutputType() {
  125. $ImageOutputType=$this->Parser_Results->ImageOutputType;
  126. if (!($ImageOutputType=="png" || $ImageOutputType=="jpeg" || $ImageOutputType=="gif"))
  127. throw new ConfigParser_Exception("ConfigParser: Invalid ImageOutputType");
  128. return $ImageOutputType;
  129. }
  130. /**
  131. *@access public
  132. *@return string
  133. */
  134. public function get_ChartTitle() {
  135. return $this->Parser_Results->ChartTitle;
  136. }
  137. /**
  138. *Returns the chart type
  139. *@access public
  140. *@return string
  141. *@throws ConfigParser_Exception
  142. */
  143. public function get_ChartType() {
  144. $ChartType=$this->Parser_Results->ChartType;
  145. if (!($ChartType=="Bar" || $ChartType=="Area" || $ChartType=="Line" || $ChartType=="Pie"))
  146. throw new ConfigParser_Exception("ConfigParser: Invalid ChartType");
  147. return $ChartType;
  148. }
  149. /**
  150. *Determines if phpchartPlus will use blending for the generated chart image
  151. *@access public
  152. *@return string ("Yes","No")
  153. *@throws ConfigParser_Exception
  154. */
  155. public function get_ChartUseBlending() {
  156. $ChartUseBlending=$this->Parser_Results->ChartUseBlending;
  157. if (!($ChartUseBlending=="Yes" || $ChartUseBlending=="No"))
  158. throw new ConfigParser_Exception("ConfigParser: Invalid Blend value.Use Yes or No");
  159. return $ChartUseBlending;
  160. }
  161. /**
  162. *Determines if phpchartPlus will use antialias functions
  163. *@access public
  164. *@return string ("Yes","No")
  165. *@throws ConfigParser_Exception
  166. */
  167. public function get_ChartUseAntialias() {
  168. $ChartUseAntialias=$this->Parser_Results->ChartUseAntialias;
  169. if (!($ChartUseAntialias=="Yes" || $ChartUseAntialias=="No"))
  170. throw new ConfigParser_Exception("ConfigParser: Invalid Antialias value.Use Yes or No");
  171. return $ChartUseAntialias;
  172. }
  173. /**
  174. *Returns chart's x-distance from the top left corner of the image
  175. *@access public
  176. *@return integer
  177. *@throws ConfigParser_Exception
  178. */
  179. public function get_ChartHmargin() {
  180. if ($this->Parser_Results->ChartHmargin<0)
  181. throw new ConfigParser_Exception("ConfigParser: Invalid ChartHmargin value");
  182. return $this->Parser_Results->ChartHmargin;
  183. }
  184. /**
  185. *Returns chart's y-distance from the top left corner of the image
  186. *@access public
  187. *@return integer
  188. *@throws ConfigParser_Exception
  189. */
  190. public function get_ChartVmargin() {
  191. if ($this->Parser_Results->ChartVmargin<0)
  192. throw new ConfigParser_Exception("ConfigParser: Invalid ImageVmargin value");
  193. return $this->Parser_Results->ChartVmargin;
  194. }
  195. /**
  196. *Determines if phpchartPlus will use status indication for the generated chart
  197. *@access public
  198. *@return string ("Yes","No")
  199. *@throws ConfigParser_Exception
  200. */
  201. public function get_ChartUseStatus() {
  202. $ChartUseStatus=$this->Parser_Results->ChartUseStatus;
  203. if (! ($ChartUseStatus=="Yes" || $ChartUseStatus=="No"))
  204. throw new ConfigParser_Exception("ConfigParser: Invalid ChartUseStatus value");
  205. return $ChartUseStatus;
  206. }
  207. /**
  208. *Returns the starting color of the image area. If starting
  209. *color is diffrent from finishing color then the image area will be
  210. *filled with gradient color
  211. *@access public
  212. *@return string
  213. */
  214. public function get_ImageColor_Start() {
  215. return $this->Parser_Results->ImageColor_Start;
  216. }
  217. /**
  218. *Returns the finishing color of the image area. If finishing
  219. *color is diffrent from starting color then the image area will be
  220. *filled with gradient color
  221. *@access public
  222. *@return string
  223. */
  224. public function get_ImageColor_Finish() {
  225. return $this->Parser_Results->ImageColor_Finish;
  226. }
  227. /**
  228. *Returns the image's color alpha value
  229. *@access public
  230. *@return integer
  231. *@throws ConfigParser_Exception
  232. */
  233. public function get_ImageColor_Alpha() {
  234. $ImageColorAlpha=$this->Parser_Results->ImageColor_Alpha;
  235. if (($ImageColorAlpha<0) || ($ImageColorAlpha>127))
  236. throw new ConfigParser_Exception("ConfigParser: Invalid ImageColor_Alpha value");
  237. return $ImageColorAlpha;
  238. }
  239. /**
  240. *Returns the starting color of the chart area.If starting
  241. *color is diffrent from finishing color then the chart area will be
  242. *filled with gradient color
  243. *@access public
  244. *@return string
  245. */
  246. public function get_ChartColor_Start() {
  247. return $this->Parser_Results->ChartColor_Start;
  248. }
  249. /**
  250. *Returns the finishing color of the chart area.If finishing
  251. *color is different from starting color then the chart area will be
  252. *filled with gradient color
  253. *@access public
  254. *@return string
  255. */
  256. public function get_ChartColor_Finish() {
  257. return $this->Parser_Results->ChartColor_Finish;
  258. }
  259. /**
  260. *@access public
  261. *@return integer
  262. *@throws ConfigParser_Exception
  263. */
  264. public function get_ChartColor_Alpha() {
  265. $ChartColorAlpha=$this->Parser_Results->ChartColor_Alpha;
  266. if (($ChartColorAlpha<0) || ($ChartColorAlpha>127))
  267. throw new ConfigParser_Exception("ConfigParser: Invalid ChartColor_Alpha value");
  268. return $ChartColorAlpha;
  269. }
  270. /**
  271. *Returns the full path of chart's background image. If the value
  272. *returned is null then no background image will be used
  273. *@access public
  274. *@return string
  275. *@throws ConfigParser_Exception
  276. */
  277. public function get_ChartBgImage() {
  278. if ($this->Parser_Results->ChartBgImage!=NULL) {
  279. if (!file_exists($this->Parser_Results->ChartBgImage))
  280. throw new ConfigParser_Exception("ConfigParser: Background image not found");
  281. }
  282. return $this->Parser_Results->ChartBgImage;
  283. }
  284. /**
  285. *Returns the full path of the FreeType2 font the chart will use for drawing
  286. *characters in the chart image
  287. *@access public
  288. *@return string
  289. *@throws ConfigParser_Exception
  290. */
  291. public function get_FontFileLocation() {
  292. if ($this->Parser_Results->FontFileLocation!=NULL) {
  293. if (!file_exists($this->Parser_Results->FontFileLocation))
  294. throw new ConfigParser_Exception("ConfigParser: Font file not found");
  295. }
  296. return $this->Parser_Results->FontFileLocation;
  297. }
  298. /**
  299. *Returns the font color
  300. *@access public
  301. *@return string
  302. */
  303. public function get_FontColor() {
  304. return $this->Parser_Results->FontColor;
  305. }
  306. /**
  307. *Returns the width of the built-in font
  308. *@access public
  309. *@return string
  310. */
  311. public function get_FontWidth() {
  312. return $this->Parser_Results->FontWidth;
  313. }
  314. /**
  315. *Returns the height of the built-in font
  316. *@access public
  317. *@return string
  318. */
  319. public function get_FontHeight() {
  320. return $this->Parser_Results->FontHeight;
  321. }
  322. /**
  323. *Returns the font size of the selected FreeType2 font
  324. *@access public
  325. *@return string
  326. */
  327. public function get_FontSize() {
  328. return $this->Parser_Results->FontSize;
  329. }
  330. /**
  331. *Returns an array holding the legend colors
  332. *@access public
  333. *@return string[]
  334. */
  335. public function get_LegendColors() {
  336. return $this->Parser_Results->LegendColors;
  337. }
  338. /**
  339. *Returns the alpha value of the legend's colors
  340. *@access public
  341. *@return integer[]
  342. */
  343. public function get_LegendColors_Alpha() {
  344. return $this->Parser_Results->LegendColors_Alpha;
  345. }
  346. /**
  347. *Returns the number of the grids phpchartPlus will use
  348. *for segmentating the chart area
  349. *@access public
  350. *@return integer
  351. *@throws ConfigParser_Exception
  352. */
  353. public function get_GridNum() {
  354. if ($this->Parser_Results->GridNum<=0)
  355. throw new ConfigParser_Exception("ConfigParser: Invalid GridNum value");
  356. return $this->Parser_Results->GridNum;
  357. }
  358. /**
  359. *Returns the minimum grid value
  360. *@access public
  361. *@return integer
  362. *@throws ConfigParser_Exception
  363. */
  364. public function get_GridMinValue() {
  365. if ($this->Parser_Results->GridMinValue<0) {
  366. if (abs($this->Parser_Results->GridMinValue)!=$this->get_GridMaxValue())
  367. throw new ConfigParser_Exception("ConfigParser: Sum of GridMinValue and GridMaxValue should be zero");
  368. }
  369. else if ($this->Parser_Results->GridMinValue>0)
  370. throw new ConfigParser_Exception("ConfigParser: GridMinValue should start from zero");
  371. return $this->Parser_Results->GridMinValue;
  372. }
  373. /**
  374. *Returns the maximum grid value
  375. *@access public
  376. *@return integer
  377. */
  378. public function get_GridMaxValue() {
  379. return $this->Parser_Results->GridMaxValue;
  380. }
  381. /**
  382. *Returns the grid color
  383. *@access public
  384. *@return string
  385. */
  386. public function get_GridColor() {
  387. return $this->Parser_Results->GridColor;
  388. }
  389.  
  390. }
  391.  
  392. ?>

Documentation generated on Sun, 3 Oct 2004 14:59:07 +0300 by phpDocumentor 1.3.0RC3