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 | ||
e7e5ef2b | 8 | public static $_classes = [ |
6a488035 TO |
9 | 'Domain' => 'data', |
10 | 'Country' => 'singleton', | |
11 | 'County' => 'singleton', | |
12 | 'StateProvince' => 'singleton', | |
13 | 'GeoCoord' => 'singleton', | |
14 | 'IMProvider' => 'singleton', | |
15 | 'MobileProvider' => 'singleton', | |
e7e5ef2b | 16 | ]; |
6a488035 | 17 | |
e7e5ef2b CW |
18 | public static $_prefix = [ |
19 | 'business' => 'CRM_Core_BAO_', | |
20 | 'data' => 'CRM_Core_DAO_', | |
21 | ]; | |
6a488035 | 22 | |
a0ee3941 | 23 | /** |
100fef9d | 24 | * @param string $className |
a0ee3941 EM |
25 | * |
26 | * @return mixed | |
27 | * @throws Exception | |
28 | */ | |
e7e5ef2b | 29 | public static function create($className) { |
9c1bc317 | 30 | $type = self::$_classes[$className] ?? NULL; |
6a488035 TO |
31 | if (!$type) { |
32 | CRM_Core_Error::fatal("class $className not found"); | |
33 | } | |
34 | ||
e7e5ef2b | 35 | $class = self::$_prefix[$type] . $className; |
6a488035 | 36 | |
0e6e8724 DL |
37 | if ($type == 'singleton') { |
38 | $newObj = $class::singleton(); | |
39 | } | |
40 | else { | |
41 | // this is either 'business' or 'data' | |
e7e5ef2b | 42 | $newObj = new $class(); |
0e6e8724 | 43 | } |
6a488035 TO |
44 | |
45 | return $newObj; | |
46 | } | |
e7e5ef2b | 47 | |
6a488035 | 48 | } |