Source for file sylar_loader.php

Documentation is available at sylar_loader.php

  1. <?php
  2. /*
  3. * This file is part of Sylar.
  4. *
  5. * Sylar is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Sylar is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with Sylar. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * @copyright Copyright Sylar Development Team
  19. * @license http://www.gnu.org/licenses/ GNU Public License V2.0
  20. * @see https://launchpad.net/sylar/
  21. * @see http://www.giano-solutions.com
  22. */
  23.  
  24.  
  25. /**
  26. * Sylar - Framework Loader
  27. * Load the Sylar Framework base settings
  28. *
  29. * @package Sylar
  30. * @version 1.0
  31. * @since 02-2008
  32. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  33. * @copyright Sylar Development Team
  34. */
  35.  
  36. #
  37. # Controls that this file is only and always included
  38. #
  39.  
  40. if( count(get_included_files())<=1 ){
  41. echo "Wrong Call. Sylar Die.";
  42. exit;
  43. }
  44.  
  45. /**
  46. * Sylar Settings
  47. * Load the configuration of Sylar Framework
  48. *
  49. * SYLAR_ROOT_FS must be defined for example in the application config file
  50. */
  51. include_once SYLAR_ROOT_FS.'settings/sylar.php';
  52.  
  53.  
  54. /** Imports */
  55.  
  56. import('sylar.common.system.ConfigBox');
  57. import('sylar.common.system.Logger');
  58. import('sylar.common.system.ExceptionInSylar');
  59. import('sylar.common.db.DataBaseConfiguration');
  60. import('sylar.common.locale.Locale');
  61.  
  62.  
  63.  
  64. // Sylar Loader Start
  65. //______________________________________________________________________________
  66.  
  67.  
  68.  
  69.  
  70.  
  71. try{
  72. /**
  73. * Default Db Configuration
  74. * the default configuration for the sylar db
  75. */
  76. $SYLAR_DEFAULT_DB_CONFIG = new Sylar_DataBaseConfiguration("SylarDefaultDb", $SYLAR_DB[SYLAR_USED_DB]);
  77. /**
  78. * Make session starts if needed
  79. */
  80. if(Sylar_ConfigBox::isSessionEnabled()){
  81. if (!isset($_SESSION[Sylar_ConfigBox::getSessionName()])){
  82. session_start();
  83. #
  84. # Sylar use an Hash to store session information
  85. #
  86. if (!isset($_SESSION[Sylar_ConfigBox::getSessionName()])){
  87. $_SESSION[Sylar_ConfigBox::getSessionName()] = array();
  88. }
  89. }
  90. #
  91. # Sylar Include Session manage in the applications
  92. #
  93. import('sylar.common.security.Session');
  94. }
  95. /**
  96. * system object for logger
  97. * an objet to use in the application
  98. */
  99. $Log = new Sylar_Logger();
  100. /**
  101. * system locale
  102. * an objet to use as default sylar Locale Config
  103. *
  104. * @see sylar.php
  105. *
  106. */
  107. $LocaleDef = new Sylar_LocaleConfiguration( Sylar_ConfigBox::getDefaultLocaleKey() );
  108.  
  109. }catch (ExceptionInSylar $ex){
  110. echo "Error in Sylar Loader! Check the system configuration.";
  111. // Show details only if debug mode is active
  112. if(Sylar_ConfigBox::isSylarInDebugMode()){
  113. echo "\n</br>\n</br>[DEBUG MODE: ON] Errore Desc: \n</br>";
  114. echo $ex->getMessage();
  115. }
  116. exit;
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. // Functions
  125. //______________________________________________________________________________
  126.  
  127. /**
  128. * import() function
  129. * This function includes php codes from other scripts (libraryes) to current environment
  130. * Folders separator is dot character '.' and base path (SYLAR_CLASSES_ROOT_FS)
  131. *
  132. * If $fileClass starts whith ~ it includes the classes from application defined
  133. * in SYLAR_APPLICATION_CLASSES_ROOT_FS
  134. *
  135. * @package Sylar
  136. * @version 1.0
  137. * @since 02/2008
  138. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  139. * @copyright Giano Solutions Srl
  140. *
  141. * @param string $fileClass the path of class separated by "." example: db.mysql.driver
  142. */
  143. function import($fileClass){
  144. $sOrigRequest = $fileClass;
  145. // Class name is the same of the filename whitout the extension
  146. //
  147. $className = explode(".", $fileClass);
  148. switch ($className[0]) {
  149. // import a sylar Class using the prefix sylar
  150. // import('sylar.common.base.db.mysql...');
  151. case "sylar":
  152. $fileClass = str_replace("sylar.", "", $fileClass);
  153. $fileClass = str_replace('.', '/', $fileClass);
  154. $fileClass = SYLAR_CLASSES_ROOT_FS.$fileClass;
  155. break;
  156. // import a application Class using the prefix app
  157. // import('app.presentation.user...');
  158. // equivalent to ~.presentation.user
  159. case "app":
  160. $fileClass = str_replace("app.", "", $fileClass);
  161. $fileClass = str_replace('.', '/', $fileClass);
  162. $fileClass = SYLAR_APPLICATION_CLASSES_ROOT_FS.$fileClass;
  163. break;
  164.  
  165. // Old Command ~. is equal to app.
  166. case "~":
  167. $fileClass = str_replace("~.", "", $fileClass);
  168. $fileClass = str_replace('.', '/', $fileClass);
  169. $fileClass = SYLAR_APPLICATION_CLASSES_ROOT_FS.$fileClass;
  170. break;
  171. // Default import is the application class path
  172. default:
  173. $fileClass = str_replace('.', '/', $fileClass);
  174. $fileClass = SYLAR_APPLICATION_CLASSES_ROOT_FS.$fileClass;
  175. break;
  176. }
  177. // add the file extension to the path
  178. //
  179. $fileClass .= ".php";
  180.  
  181. // Verify and include the php file
  182. //
  183. if(file_exists($fileClass)){
  184. require_once $fileClass;
  185. }else{
  186. // Class not found! Manage error
  187. //
  188. echo "import() error! Sylar Die. \n(".$sOrigRequest.")";
  189. exit;
  190. }
  191. }
  192.  
  193.  
  194. ?>

Documentation generated on Thu, 24 Apr 2008 16:14:23 +0200 by phpDocumentor 1.3.0RC3