Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b5c2afd0 EM |
2 | |
3 | /** | |
4 | * Class CRM_Core_DAO_Factory | |
5 | */ | |
6a488035 TO |
6 | class CRM_Core_DAO_Factory { |
7 | ||
8 | static $_classes = array( | |
9 | 'Domain' => 'data', | |
10 | 'Country' => 'singleton', | |
11 | 'County' => 'singleton', | |
12 | 'StateProvince' => 'singleton', | |
13 | 'GeoCoord' => 'singleton', | |
14 | 'IMProvider' => 'singleton', | |
15 | 'MobileProvider' => 'singleton', | |
16 | ); | |
17 | ||
18 | static $_prefix = array( | |
19 | 'business' => 'CRM/Core/BAO/', | |
20 | 'data' => 'CRM/Core/DAO/', | |
21 | ); | |
22 | ||
23 | static $_suffix = '.php'; | |
24 | ||
a0ee3941 | 25 | /** |
100fef9d | 26 | * @param string $className |
a0ee3941 EM |
27 | * |
28 | * @return mixed | |
29 | * @throws Exception | |
30 | */ | |
0e6e8724 | 31 | static function &create($className) { |
6a488035 TO |
32 | $type = CRM_Utils_Array::value($className, self::$_classes); |
33 | if (!$type) { | |
34 | CRM_Core_Error::fatal("class $className not found"); | |
35 | } | |
36 | ||
37 | $file = self::$_prefix[$type] . $className; | |
38 | $class = str_replace('/', '_', $file); | |
39 | ||
40 | require_once ($file . self::$_suffix); | |
41 | ||
0e6e8724 DL |
42 | if ($type == 'singleton') { |
43 | $newObj = $class::singleton(); | |
44 | } | |
45 | else { | |
46 | // this is either 'business' or 'data' | |
47 | $newObj = new $class; | |
48 | } | |
6a488035 TO |
49 | |
50 | return $newObj; | |
51 | } | |
52 | } |