[NFC] Minor code cleanup
[civicrm-core.git] / CRM / Contact / DAO / Factory.php
1 <?php
2
3 /**
4 * Class CRM_Contact_DAO_Factory
5 */
6 class CRM_Contact_DAO_Factory {
7
8 public static $_classes = [
9 'Address' => 'data',
10 'Contact' => 'data',
11 'Email' => 'data',
12 'Household' => 'data',
13 'IM' => 'data',
14 'Individual' => 'data',
15 'Location' => 'data',
16 'LocationType' => 'data',
17 'Organization' => 'data',
18 'Phone' => 'data',
19 'Relationship' => 'data',
20 ];
21
22 public static $_prefix = [
23 'business' => 'CRM_Contact_BAO_',
24 'data' => 'CRM_Contact_DAO_',
25 ];
26
27 /**
28 * @param string $className
29 *
30 * @return mixed
31 */
32 public static function create($className) {
33 $type = self::$_classes[$className] ?? NULL;
34 if (!$type) {
35 return CRM_Core_DAO_Factory::create($className);
36 }
37
38 $class = self::$_prefix[$type] . $className;
39
40 if ($type == 'singleton') {
41 $newObj = $class::singleton();
42 }
43 else {
44 // this is either 'business' or 'data'
45 $newObj = new $class();
46 }
47
48 return $newObj;
49 }
50
51 }