<?php
/**
* フレームワーク用クラスローダ
*
* PHP version 5
*
* @package    core
* @author     stk2k <stk2k@sazysoft.com>
* @copyright  2008 stk2k, sazysoft
*/

class FrameworkClassLoader
{
	static $class_paths;

	/*
	 * クラスパスの初期化
	 */
	public static function initClassPath()
	{
		if ( self::$class_paths ){
			return self::$class_paths;
		}

		self::$class_paths = array(

		// core classes
				'Annotation'				=> 'core',
				'AnnotationUtil'			=> 'core',
				'Benchmark'					=> 'core',
				'CacheFile'					=> 'core',
				'CacheFileHeader'			=> 'core',
				'ClassLoader'				=> 'core',
				'ClassUtil'					=> 'core',
				'CommandLineUtil'			=> 'core',
				'Config'					=> 'core',
				'ConfigLoader'				=> 'core',
				'ConfigUtil'				=> 'core',
				'DB'						=> 'core',
				'DBRelation'				=> 'core',
				'DIContainer'				=> 'core',
				'DTO'						=> 'core',
				'EncodingConverter'			=> 'core',
				'EventQueue'				=> 'core',
				'EventQueueEntry'			=> 'core',
				'Factory'					=> 'core',
				'Framework'					=> 'core',
				'Integer'					=> 'core',
				'Logger'					=> 'core',
				'MemoryUsage'				=> 'core',
				'ProcedureContext'			=> 'core',
				'Profile'					=> 'core',
				'ResourceCache'				=> 'core',
				'ResourceLocator'			=> 'core',
				'Response'					=> 'core',
				'Session'					=> 'core',
				'SQLCriteria'				=> 'core',
				'String'					=> 'core',
				'System'					=> 'core',
				'URL'						=> 'core',

		// interface classes
				'IClassLoader'				=> 'interfaces',
				'IComponent'				=> 'interfaces',
				'IConfigProvider'			=> 'interfaces',
				'IDataSource'				=> 'interfaces',
				'IEvent'					=> 'interfaces',
				'IFilter'					=> 'interfaces',
				'IForm'						=> 'interfaces',
				'IFormModel'				=> 'interfaces',
				'ILayoutManager'			=> 'interfaces',
				'ILogger'					=> 'interfaces',
				'IModel'					=> 'interfaces',
				'IModule'					=> 'interfaces',
				'IProcedure'				=> 'interfaces',
				'IRenderer'					=> 'interfaces',
				'IRequest'					=> 'interfaces',
				'IResource'					=> 'interfaces',
				'ISessionHandler'			=> 'interfaces',
				'ISQLBuilder'				=> 'interfaces',
				'ITableModel'				=> 'interfaces',
				'ITask'						=> 'interfaces',
				'ITaskManager'				=> 'interfaces',
				'ITransformer'				=> 'interfaces',
				'IURLMapper'				=> 'interfaces',
				'IValidator'				=> 'interfaces',

		// HTML objects
				'HTMLChoiceGroupObject'		=> 'html_objects',
				'HTMLContainerObject'		=> 'html_objects',
				'HTMLFormFactory'			=> 'html_objects',
				'HTMLFormObject'			=> 'html_objects',
				'HTMLInputObject'			=> 'html_objects',
				'HTMLLeafObject'			=> 'html_objects',
				'HTMLListObject'			=> 'html_objects',
				'HTMLObject'				=> 'html_objects',
				'HTMLPanelObject'			=> 'html_objects',
				'HTMLSelectObject'			=> 'html_objects',
				'HTMLTextObject'			=> 'html_objects',
				'HTMLTextAreaObject'		=> 'html_objects',

		// event classes
				'DefaultEvent'				=> 'events',

		// logger classes
				'FileLogger'				=> 'loggers',
				'ScreenLogger'				=> 'loggers',

		// constant classes
				'ComponentScope'			=> 'constants',

		// exception classes
				'AnnotaionException'				=> 'exceptions',
				'ArrayFormatException'				=> 'exceptions',
				'BooleanFormatException'			=> 'exceptions',
				'ClassLoaderConfigException'		=> 'exceptions',
				'ClassNotFoundException'			=> 'exceptions',
				'ComponentConfigException'			=> 'exceptions',
				'ComponentNotRegisteredException'	=> 'exceptions',
				'ConfigFileNotFoundException'		=> 'exceptions',
				'DBException'						=> 'exceptions',
				'EncodingConverterException'		=> 'exceptions',
				'CharcoalException'					=> 'exceptions',
				'HttpException'						=> 'exceptions',
				'InterfaceImplementException'		=> 'exceptions',
				'IntegerFormatException'			=> 'exceptions',
				'InvalidClassNameException'			=> 'exceptions',
				'InvalidDBRelationException'		=> 'exceptions',
				'LayoutException'					=> 'exceptions',
				'LoggerConfigException'				=> 'exceptions',
				'ModuleGraphConfigException'		=> 'exceptions',
				'ModuleGraphTransitionException'	=> 'exceptions',
				'ModuleGraphNodeException'			=> 'exceptions',
				'NonArrayException'					=> 'exceptions',
				'NonObjectException'				=> 'exceptions',
				'NullPointerException'				=> 'exceptions',
				'ParameterException'				=> 'exceptions',
				'ProcedureConfigException'			=> 'exceptions',
				'ProfileException'					=> 'exceptions',
				'RendererException'					=> 'exceptions',
				'StringFormatException'				=> 'exceptions',
				'TableModelException'				=> 'exceptions',
				'TableModelConfigException'			=> 'exceptions',
				'TemplateFileNotFoundException'		=> 'exceptions',
				'UnexpectedRunModeException'		=> 'exceptions',
				'URLMapperConfigException'			=> 'exceptions',



		// config provider classes
				'SpycConfigProvider'				=> 'config_providers',
				'CachedSpycConfigProvider'			=> 'config_providers',

		// layout manager classes
				'DefaultLayoutManager'				=> 'layout_managers',

		// task manager classes
				'DefaultTaskManager'				=> 'task_managers',

		// table model classes
				'DefaultTableModel'					=> 'table_models',

		// form model classes
				'DefaultFormModel'					=> 'form_models',

		// data source classes
				'PearDbDataSource'					=> 'data_sources',

		// request classes
				'ShellRequest'						=> 'requests',
				'HttpRequest'						=> 'requests',

		// session hanlder classes
				'DefaultSessionHandler'				=> 'session_handlers',

		// SQL Builder classes
				'DefaultSQLBuilder'					=> 'sql_builders',
				'MySQL_SQLBuilder'					=> 'sql_builders',
				'PostgreSQL_SQLBuilder'				=> 'sql_builders',

		// form classes
				'SimpleForm'						=> 'forms',

		// procedure classes
				'HttpProcedure'						=> 'procedures',
				'ShellProcedure'					=> 'procedures',

		// renderer classes
				'SmartyRenderer'					=> 'renderers',
				'PHPTALRenderer'					=> 'renderers',

		// filter classes
				'FormOutputFilter'					=> 'filters',
				'FormReadOnlyOutputFilter'			=> 'filters',
				'EncodingInputFilter'				=> 'filters',
				'EncodingOutputFilter'				=> 'filters',
				'CharcoalPagerOutputFilter'			=> 'filters',

		// component classes
				'Linker'							=> 'components/charcoal',
				'BreadcrumbList'					=> 'components/charcoal',
				'CharcoalPager'						=> 'components/charcoal',
				'Calendar'							=> 'components/charcoal',
				'CharcoalMail'						=> 'components/mail/CharcoalMail.class.php',

		// transformer classes
				'SimpleTransformer'					=> 'transformers',

		// URL Mapper classes
				'SimpleURLMapper'					=> 'url_mappers',

		);

		return self::$class_paths;
	}

	/*
	 * クラスをロード
	 */
	public static function loadClass( $class_name )
	{
		// クラスパスの初期化
		$class_paths = self::initClassPath();

		// フレームワークのクラスではない場合はFALSEを返却
		if ( !isset($class_paths[ $class_name ]) ){
			return FALSE;
		}

		// クラス名からクラスパスを取得
		$class_path = $class_paths[ $class_name ] . "/$class_name.class.php";

		// ソース読み込み
		require_once( 'ClassUtil.class.php' );

		$loaded = ClassUtil::loadClass( $class_path, $class_name );

		return $loaded;
	}
}
