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