Merge pull request #870 from colemanw/import
[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 $_preCall = array(
27 'singleton' => '',
28 'business' => 'new',
29 'data' => 'new',
30 );
31
32 static $_extCall = array(
33 'singleton' => '::singleton',
34 'business' => '',
35 'data' => '',
36 );
37
38
39 static
40 function &create($className) {
41 $type = CRM_Utils_Array::value($className, self::$_classes);
42 if (!$type) {
43 return CRM_Core_DAO_Factory::create($className);
44 }
45
46 $file = self::$_prefix[$type] . $className;
47 $class = str_replace('/', '_', $file);
48
49 require_once ($file . self::$_suffix);
50
51 $newObj = eval(sprintf("return %s %s%s();",
52 self::$_preCall[$type],
53 $class,
54 self::$_extCall[$type]
55 ));
56
57 return $newObj;
58 }
59 }
60