Server.class.php 1.24 KB
<?php
class Util_Server {
    
    /**
     * 定义驱动器
     * 
     * @var array
     */
	public static $drivers = array (
		'Db' => array ('Mysql' ), 
		'File' => array ('Mogile', 'Ext', 'Nfs' ), 
		'Cache' => array ('Memcache','Redis'), 
		'Ws' => array ('Httpcws' ), 
		'Se' => array ('Sphinx' ),
	    'Clouds' => array ('Gearman' ),
	);
	
	/**
	 * 得到后台服务器配置
	 *
	 * @param string $driver DB, FS, Cache
	 * @param array|null $options
	 * @return object
	 */
	public static function factory($maindriver, $subdriver, array $options = null) {
		/*
		 * File
		 * $options['config']
		 * 
		 * Cache
		 * $options['config']
		 * 
		 * Db
		 * $options['config'']
		 * $options['dbname']
		 * $options['readtag']
		 * 
		 */
		if (! isset ( self::$drivers [ucfirst ( $maindriver )] ))
			throw new Util_Server_Exception ( '您选择的系统架构不支持( ' . $maindriver . ' )!' );
		elseif (! in_array ( ucfirst ( $subdriver ), self::$drivers [ucfirst ( $maindriver )] ))
			throw new Util_Server_Exception ( '您选择的驱动架构不支持( ' . ucfirst ( $subdriver ) . ' )!' );
		else {
			$classname = 'Util_Server_Adapter_' . ucfirst ( $maindriver ) . '_' . ucfirst ( $subdriver );
			return new $classname ( $options );
		}
	}
}
?>