Server.class.php
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?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 );
}
}
}
?>