Source for file packagemanager.class.php

Documentation is available at packagemanager.class.php

  1. <?
  2. /**
  3. * packagemanager.class.php
  4. * this class loads all the package informations and defines the action path
  5. * this really helps deploying applications in zephyr and also seperate
  6. * applications totally from the main zephyr engine
  7. *
  8. * @author Hasin Hayder
  9. * @since 13th April, 2006
  10. * @package Zephyr
  11. * @version Beta 2.0
  12. * @copyright LGPL
  13. */
  14. session_start();
  15. class packagemanager
  16. {
  17. /**
  18. * constructor
  19. *
  20. * @param string
  21. * @return packagemanager
  22. */
  23. public function __construct($package=null, $logout=null)
  24. {
  25. if($package==null && empty($_SESSION['__package']))
  26. {
  27. throw new Exception("You must supply a package name for the first time", 20001);
  28. }
  29. elseif($package!=null)
  30. {
  31. //we got new package
  32. $_SESSION['__package']= $package;
  33. $package_definition = "packages/{$package}/package.xml";
  34. if($logout)
  35. {
  36. $package_definition = "../packages/{$package}/package.xml";
  37. }
  38. $xml = simplexml_load_file($package_definition);
  39.  
  40. $_SESSION['__root_template']= $xml->root_template[0]."";
  41. $_SESSION['__compile'] = $xml->compile[0]."";
  42. // load multiple pre_action_processor
  43. foreach ($xml->pre_action_processor as $pap)
  44. {
  45. $paps[] = $pap."";
  46. }
  47. if (count($paps)>0)
  48. $paps = implode(":", $paps);
  49. $_SESSION['__pre_action_processor']=$paps; //$xml->pre_action_processor[0]."";
  50. // load multiple javascript files
  51. foreach ($xml->javascript as $js)
  52. {
  53. $jss[] = $js."";
  54. }
  55. if (count($jss)>0)
  56. $jss = implode(":", $jss);
  57. $_SESSION['__javascript']=$jss;
  58. $_SESSION['__overlib']=$xml->system_packages[0]->overlib[0]."";
  59. $_SESSION['__jscalendar']=$xml->system_packages[0]->jscalendar[0]."";
  60. $_SESSION['__title']=$xml->name[0]."";
  61. $_SESSION['__version']=$xml->version[0]."";
  62. $_SESSION['__css']=$xml->css[0]."";
  63. $_SESSION['__root_action']=$xml->root_action[0]."";
  64. // load multiple pre_action_processor
  65. foreach ($xml->pear as $pear)
  66. {
  67. $pears[] = $pear."";
  68. }
  69. if (count($pears)>0)
  70. $pears = implode(":", $pears);
  71. $_SESSION['__pear'] = $pears;
  72. // load multiple php files
  73. foreach ($xml->php as $php)
  74. {
  75. $phps[] = $php."";
  76. }
  77. if (count($phps)>0)
  78. $phps = implode(":", $phps);
  79. $_SESSION['__php']=$phps; //$xml->php[0]."";
  80. $_SESSION['__use_smarty_plugin']=$xml->smarty_plugin[0]."";
  81. // load multiple input filters
  82. foreach ($xml->input_filter as $if)
  83. {
  84. $ifs[] = $if."";
  85. }
  86. if (count($ifs)>0)
  87. $ifs = implode(":", $ifs);
  88. $_SESSION['__ifs']=$ifs; //$xml->php[0]."";
  89. // load multiple output filters
  90. foreach ($xml->output_filter as $of)
  91. {
  92. $ofs[] = $of."";
  93. }
  94. if (count($ofs)>0)
  95. $ofs = implode(":", $ofs);
  96. $_SESSION['__ofs']=$ofs;
  97. }
  98. }
  99. /**
  100. * return the root template
  101. *
  102. * @access public
  103. * @return string
  104. */
  105. public function get_root_template()
  106. {
  107. return $_SESSION['__root_template'];
  108. }
  109. /**
  110. * return the input filters in a ":" delimited string
  111. *
  112. * @access public
  113. * @return string
  114. */
  115. public function get_input_filters()
  116. {
  117. return $_SESSION['__ifs'];
  118. }
  119. /**
  120. * return the output filters in a ":" delimited string
  121. *
  122. * @access public
  123. * @return string
  124. */
  125. public function get_output_filters()
  126. {
  127. return $_SESSION['__ofs'];
  128. }
  129. /**
  130. * is compilation necessary for this root_template
  131. *
  132. * @access public
  133. * @return boolean
  134. */
  135. public function is_compile_required()
  136. {
  137. if($_SESSION['__compile']=='true') return true;
  138. return false;
  139. }
  140. /**
  141. * return the name of pre_action_processor class
  142. * because we must call it's execute method before loading any action
  143. * this is extremely usefull when something have to be done before an
  144. * action loads. like privilege management. if the execute method returns
  145. * true then action loader will load the desired action. otherwise it will
  146. * die with a custom error message provided by this class.
  147. *
  148. * @access public
  149. * @return string
  150. */
  151. public function get_pre_action_processor()
  152. {
  153. return $_SESSION['__pre_action_processor'];
  154. }
  155. /**
  156. * return the base path for this application
  157. *
  158. * @access public
  159. * @return string
  160. */
  161. public function get_base_path()
  162. {
  163. return "{$_SESSION['__package']}";
  164. }
  165. /**
  166. * return the base path for this application
  167. *
  168. * @access public
  169. * @return string
  170. */
  171. public function get_javascript()
  172. {
  173. return "{$_SESSION['__javascript']}";
  174. }
  175. /**
  176. * return if overlib is needed or not
  177. *
  178. * @return boolean
  179. */
  180. public function require_overlib()
  181. {
  182. if ($_SESSION['__overlib']=='1')
  183. return true;
  184. return false;
  185. }
  186. /**
  187. * return if jscalendar is needed or not
  188. *
  189. * @return boolean
  190. */
  191. public function require_jscalendar()
  192. {
  193. if ($_SESSION['__jscalendar']=='1')
  194. return true;
  195. return false;
  196. }
  197.  
  198. /**
  199. * return package title
  200. *
  201. * @return string
  202. */
  203. public function get_title()
  204. {
  205. return $_SESSION['__title'];
  206. }
  207. /**
  208. * return package version
  209. *
  210. * @return string
  211. */
  212. public function get_version()
  213. {
  214. return $_SESSION['__version'];
  215. }
  216.  
  217. /**
  218. * return stylesheet
  219. *
  220. * @return string
  221. */
  222. public function get_stylesheet()
  223. {
  224. return $_SESSION['__css'];
  225. }
  226. /**
  227. * return root action
  228. *
  229. * @return string
  230. */
  231. public function get_root_action()
  232. {
  233. return $_SESSION['__root_action'];
  234. }
  235.  
  236. /**
  237. * return user defined php script
  238. *
  239. * @return string
  240. */
  241. public function get_php()
  242. {
  243. return $_SESSION['__php'];
  244. }
  245.  
  246. /**
  247. * return pear packages
  248. *
  249. * @return string
  250. */
  251. public function get_pear_packages()
  252. {
  253. return $_SESSION['__pear'];
  254. }
  255. /**
  256. * return whether to use package specific user defined smarty plugins or not
  257. *
  258. * @return boolean
  259. */
  260. public function use_smarty_plugin()
  261. {
  262. return $_SESSION['__use_smarty_plugin'];
  263. }
  264. /**
  265. * return the physical path of current package
  266. * this is extremely usefull when you want to manipulate file
  267. * specially sqlite database at the current package context
  268. *
  269. * @return string
  270. * @since beta 2.0
  271. */
  272. public function get_package_path()
  273. {
  274. $root_path= dirname(dirname(__FILE__))."/packages/".$this->get_base_path();
  275. //$root_path = str_replace("\\", "/", $root_path);
  276. return $root_path;
  277. }
  278.  
  279. }
  280. ?>

Documentation generated on Sat, 15 Apr 2006 22:10:30 +0600 by phpDocumentor 1.3.0RC3