/
Cdn.php
73 lines (60 loc) · 2.01 KB
/
Cdn.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* W3 CDN Class
*/
if (! defined('W3_CDN_FTP')) {
define('W3_CDN_FTP', 'ftp');
}
if (! defined('W3_CDN_CF')) {
define('W3_CDN_CF', 'cf');
}
if (! defined('W3_CDN_S3')) {
define('W3_CDN_S3', 's3');
}
if (! defined('W3_CDN_MIRROR')) {
define('W3_CDN_MIRROR', 'mirror');
}
/**
* Class W3_Cdn
*/
class W3_Cdn
{
/**
* Returns W3_Cdn_Base instance
*
* @param string $engine
* @param array $config
* @return W3_Cdn_Base
*/
function &instance($engine, $config = array())
{
static $instances = array();
$instance_key = sprintf('%s_%s', $engine, md5(serialize($config)));
if (! isset($instances[$instance_key])) {
switch (true) {
case ($engine == W3_CDN_FTP):
require_once W3TC_LIB_W3_DIR . '/Cdn/Ftp.php';
$instances[$instance_key] = & new W3_Cdn_Ftp($config);
break;
case (W3TC_PHP5 && $engine == W3_CDN_CF):
require_once W3TC_LIB_W3_DIR . '/Cdn/Cf.php';
$instances[$instance_key] = & new W3_Cdn_Cf($config);
break;
case (W3TC_PHP5 && $engine == W3_CDN_S3):
require_once W3TC_LIB_W3_DIR . '/Cdn/S3.php';
$instances[$instance_key] = & new W3_Cdn_S3($config);
break;
case ($engine == W3_CDN_MIRROR):
require_once W3TC_LIB_W3_DIR . '/Cdn/Mirror.php';
$instances[$instance_key] = & new W3_Cdn_Mirror($config);
break;
default:
trigger_error('Incorrect CDN engine', E_USER_WARNING);
require_once W3TC_LIB_W3_DIR . '/Cdn/Base.php';
$instances[$instance_key] = & new W3_Cdn_Base();
break;
}
}
return $instances[$instance_key];
}
}