PageRenderTime 62ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/Zoop.php

http://zoop.googlecode.com/
PHP | 255 lines | 62 code | 21 blank | 172 comment | 8 complexity | 1a62bbb1ab7d87bddb167db6eaa04166 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. // do some bootstrapping
  3. if(!defined("zoop_dir"))
  4. define("zoop_dir", dirname(__file__));
  5. function define_once($name, $value)
  6. {
  7. if(!defined($name))
  8. define($name, $value);
  9. }
  10. // now we load the default config for zoop
  11. // include(zoop_dir . '/config.php'); // this file is now obsolete and depricated, in favor of the new config module
  12. include(zoop_dir . '/ZoopLibrary.php');
  13. include(zoop_dir . '/ZoopModule.php');
  14. include(zoop_dir . '/ZoopLoader.php');
  15. // we want to load this before we do anything else so that everything else is easier to debug
  16. // include(zoop_dir . '/core/app/Error.php');
  17. // include(zoop_dir . '/core/app/Globals.php');
  18. /**
  19. * This object is for basic framework management tasks, such as:
  20. * * Configuring auto-loading of zones and modules
  21. * * Loading libraries and domains
  22. */
  23. class Zoop
  24. {
  25. // static private $loaded = array(), $registered = array();
  26. static private $libs = array();
  27. /**
  28. * registers a library
  29. */
  30. static public function registerLib($libName, $path = null)
  31. {
  32. if(!$path)
  33. $path = zoop_dir . '/' . $libName;
  34. if(isset(self::$libs[$libName]))
  35. return;
  36. $libClassName = ucfirst($libName) . 'Library';
  37. include("$path/$libClassName.php");
  38. self::$libs[$libName] = new $libClassName($path);
  39. }
  40. /**
  41. * loads a library, which just means loading all of it's modules
  42. */
  43. static public function loadLib($libName)
  44. {
  45. // for check is for backwards compatibility
  46. // in the future we can depricate it and change the self::loadMod
  47. // call to a trigger_error("lib '$libName' not found") call
  48. if(isset(self::$libs[$libName]))
  49. self::$libs[$libName]->loadMods();
  50. else
  51. self::loadMod($libName);
  52. }
  53. /**
  54. * finds out what lib a module is in and then loads it
  55. */
  56. static public function loadMod($modName)
  57. {
  58. foreach(self::$libs as $lib)
  59. if($lib->hasMod($modName))
  60. return $lib->loadMod($modName);
  61. trigger_error("mod '$modName' not found");
  62. }
  63. static public function expandPath($path)
  64. {
  65. if($path[0] == '/')
  66. return $path;
  67. return app_dir . '/' . $path;
  68. }
  69. static public function getTmpDir()
  70. {
  71. return Config::getFilePath('zoop.tmpDir');;
  72. }
  73. // deprecated stuff
  74. /**
  75. * static -- Register a class for auto-loading with the name of the class
  76. * and the full path of the file that contains it.
  77. *
  78. * @param string $className
  79. * @param string $fullPath
  80. */
  81. static function registerClass($className, $fullPath)
  82. {
  83. ZoopLoader::addClass($className, $fullPath);
  84. }
  85. /**
  86. * Register a "domain" class for autoload (a domain class is a
  87. * class that is located in the "domains" directory under
  88. * the project root with the filename <classname>.php)
  89. *
  90. * @param unknown_type $className
  91. */
  92. static public function registerDomain($className)
  93. {
  94. self::registerClass($className, app_dir . '/domain/' . $className . '.php');
  95. }
  96. // static $libList = array();
  97. //
  98. // /**
  99. // * Key => Value list of registered classes and the full path of the file that contains them
  100. // *
  101. // * @var array
  102. // */
  103. // var $classList;
  104. //
  105. //
  106. // /**
  107. // * Register a class for auto-loading with the name of the class
  108. // * and the full path of the file that contains it.
  109. // *
  110. // * @param string $className
  111. // * @param string $fullPath
  112. // */
  113. // function _registerClass($className, $fullPath)
  114. // {
  115. // $this->classList[strtolower($className)] = $fullPath;
  116. // }
  117. //
  118. // /**
  119. // * Returns the full path and filename associated with the given registered class
  120. // *
  121. // * @param string $className
  122. // * @return string - full path and filename of the class
  123. // */
  124. // function _getClassPath($className)
  125. // {
  126. // $className = strtolower($className);
  127. // if(isset($this->classList[$className]))
  128. // return $this->classList[$className];
  129. //
  130. // return false;
  131. // }
  132. //
  133. // /**
  134. // * static -- Register a class for auto-loading with the name of the class
  135. // * and the full path of the file that contains it.
  136. // *
  137. // * @param string $className
  138. // * @param string $fullPath
  139. // */
  140. // static function registerClass($className, $fullPath)
  141. // {
  142. // global $zoop;
  143. // $zoop->_registerClass($className, $fullPath);
  144. // }
  145. //
  146. // /**
  147. // * static -- Returns the full path and filename associated with the given registered class
  148. // *
  149. // * @param string $className
  150. // * @return string - full path and filename of the class
  151. // */
  152. // function getClassPath($className)
  153. // {
  154. // global $zoop;
  155. // return $zoop->_getClassPath($className);
  156. // }
  157. //
  158. // /**
  159. // * Loads a library of specified name. Modules are located in the root
  160. // * directory of the framework, using the following naming scheme:
  161. // * <root>/<module>/<module>.php
  162. // *
  163. // * @param string $name
  164. // */
  165. // static function loadLib($name, $isVendor = false)
  166. // {
  167. // echo "$name<br>";
  168. // var_dump($isVendor);
  169. // // put some code in here to make sure we don't reload modules that have already been loaded
  170. // if(isset(self::$libList[$name]))
  171. // return;
  172. // self::$libList[$name] = 1;
  173. //
  174. // // temporary measure so I can test without having to convert all of the modules over to the new format right away
  175. // if(file_exists(zoop_dir . "/$name/module.php"))
  176. // {
  177. // include(zoop_dir . "/$name/module.php");
  178. // }
  179. // else
  180. // {
  181. // if($isVendor)
  182. // {
  183. // $moduleName = ucfirst($name) . 'Module';
  184. // include(zoop_dir . "/vendor/$moduleName.php");
  185. // $module = new $moduleName();
  186. // }
  187. // else
  188. // {
  189. // $moduleName = ucfirst($name) . 'Module';
  190. // include(zoop_dir . "/$name/$moduleName.php");
  191. // $module = new $moduleName();
  192. // }
  193. // }
  194. // }
  195. //
  196. /**
  197. * Automatic class loading handler. This automatically loads a class using the path
  198. * information that was registered using the Zoop::registerClass or ::registerDomain
  199. * method
  200. *
  201. * @param string $className Name of the class to load
  202. */
  203. /*
  204. moved to ZoopLoader.php
  205. static function autoload($className)
  206. {
  207. if(headers_sent())
  208. {
  209. echo_r($className);
  210. die('here');
  211. }
  212. $classPath = Zoop::getClassPath($className);
  213. if($classPath)
  214. {
  215. require_once($classPath);
  216. }
  217. if(substr($className, 0, 5) == 'Zend_')
  218. {
  219. $parts = explode('_', $className);
  220. $modName = $parts[1];
  221. require_once(zoop_dir . "/Zend/$modName.php");
  222. }
  223. }
  224. */
  225. }
  226. Zoop::registerLib('boot');
  227. Zoop::registerLib('core');
  228. Zoop::registerLib('experimental');
  229. Zoop::registerLib('vendor');
  230. Zoop::loadLib('boot');