Merge pull request #2033 from JoeMurray/master
[civicrm-core.git] / CRM / Contact / DAO / Factory.php
1 <?php
2
3 class CRM_Contact_DAO_Factory {
4
5 static $_classes = array(
6 'Address' => 'data',
7 'Contact' => 'data',
8 'Email' => 'data',
9 'Household' => 'data',
10 'IM' => 'data',
11 'Individual' => 'data',
12 'Location' => 'data',
13 'LocationType' => 'data',
14 'Organization' => 'data',
15 'Phone' => 'data',
16 'Relationship' => 'data',
17 );
18
19 static $_prefix = array(
20 'business' => 'CRM/Contact/BAO/',
21 'data' => 'CRM/Contact/DAO/',
22 );
23
24 static $_suffix = '.php';
25
26 static function &create($className) {
27 $type = CRM_Utils_Array::value($className, self::$_classes);
28 if (!$type) {
29 return CRM_Core_DAO_Factory::create($className);
30 }
31
32 $file = self::$_prefix[$type] . $className;
33 $class = str_replace('/', '_', $file);
34
35 require_once ($file . self::$_suffix);
36
37 if ($type == 'singleton') {
38 $newObj = $class::singleton();
39 }
40 else {
41 // this is either 'business' or 'data'
42 $newObj = new $class;
43 }
44
45 return $newObj;
46 }
47 }