Merge pull request #18891 from civicrm/5.31
[civicrm-core.git] / CRM / Contact / DAO / Factory.php
CommitLineData
6a488035 1<?php
6a488035 2
86538308
EM
3/**
4 * Class CRM_Contact_DAO_Factory
5 */
6a488035
TO
6class CRM_Contact_DAO_Factory {
7
e7e5ef2b 8 public static $_classes = [
6a488035
TO
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',
e7e5ef2b 20 ];
6a488035 21
e7e5ef2b
CW
22 public static $_prefix = [
23 'business' => 'CRM_Contact_BAO_',
24 'data' => 'CRM_Contact_DAO_',
25 ];
6a488035 26
86538308 27 /**
100fef9d 28 * @param string $className
86538308
EM
29 *
30 * @return mixed
31 */
e7e5ef2b 32 public static function create($className) {
9c1bc317 33 $type = self::$_classes[$className] ?? NULL;
6a488035
TO
34 if (!$type) {
35 return CRM_Core_DAO_Factory::create($className);
36 }
37
e7e5ef2b 38 $class = self::$_prefix[$type] . $className;
6a488035 39
0e6e8724
DL
40 if ($type == 'singleton') {
41 $newObj = $class::singleton();
42 }
43 else {
44 // this is either 'business' or 'data'
e7e5ef2b 45 $newObj = new $class();
0e6e8724 46 }
6a488035
TO
47
48 return $newObj;
49 }
e7e5ef2b 50
6a488035 51}