-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cache.class.php
58 lines (46 loc) · 1.68 KB
/
Cache.class.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
<?php
/**
* @author Matt Labrum <[email protected]>
* @license Beerware
* @link url
*/
namespace EasyCache;
abstract class EasyCache{
/**
* Creates an instance of the cache interface class and the backend class
* @param string $backend
* @param string $frontend
* @param array $backendOptions
* @param array $frontendOptions
* @return FrontendCache
*/
static public function Create($backend, $frontend, Array $backendOptions, Array $frontendOptions){
$backendDirectory = dirname(__FILE__) . DIRECTORY_SEPARATOR . "Backend" . DIRECTORY_SEPARATOR;
$frontendDirectory = dirname(__FILE__) . DIRECTORY_SEPARATOR . "Frontend" . DIRECTORY_SEPARATOR;
$backendClassName = "Backend_" . $backend;
$frontendClassName = "Frontend_" . $frontend;
$backendFile = $backendDirectory . $backendClassName . ".class.php";
$frontendFile = $frontendDirectory . $frontendClassName . ".class.php";
if(file_exists($backendFile)){
if(file_exists($frontendFile)){
// Load the interface files
require_once($backendDirectory . "Backend.interface.php");
require_once($frontendDirectory . "Frontend.interface.php");
//Load the frontend and backend class files
require_once($backendFile);
require_once($frontendFile);
//Initialize the classes
$backendClass = new $backendClassName($backendOptions);
$frontendClass = new $frontendClassName($frontendOptions, $backendClass);
return $frontendClass;
}else{
throw new CacheBackendDoesntExist($backendFile);
}
}else{
throw new CacheFrontendDoesntExist($backendFile);
}
}
}
class CacheBackendDoesntExist extends \exception{}
class CacheFrontendDoesntExist extends \exception{}
?>