<?php
/*--------------------------------------------------------- 
 * File:webPartsFactory.php
 * Author:Tomix
 * Description: WebParts 工廠類
 * Created:2009
 * -------------------------------------------------------
 * Modified history:2023/08/23
 * Copyright © 2023 蘋果世界股份有限公司 版權所有
 * -------------------------------------------------------
 */
require_once dirname(__FILE__)."/webPartBase.php";
class WebPartsFactory{
	//創建webpart實例入口
	public static function create($webPartName) {
		$instance = null;
		$fileName = dirname(__FILE__) . "/" . $webPartName . ".php";

		if (self::requireFile($fileName)) {
			$className = "_" . $webPartName;
			if (class_exists($className)) $instance = new $className();
		}

		return $instance;
	}

	private static function requireFile($fileName) {
		if (!file_exists($fileName)) return false;

		require_once $fileName;
		return true;
	}
}
?>