Merge pull request #128 from eileenmcnaughton/CRM-11915-comments
[civicrm-core.git] / CRM / Core / DAO / Factory.php
1 <?php
2 class CRM_Core_DAO_Factory {
3
4 static $_classes = array(
5 'Domain' => 'data',
6 'Country' => 'singleton',
7 'County' => 'singleton',
8 'StateProvince' => 'singleton',
9 'GeoCoord' => 'singleton',
10 'IMProvider' => 'singleton',
11 'MobileProvider' => 'singleton',
12 );
13
14 static $_prefix = array(
15 'business' => 'CRM/Core/BAO/',
16 'data' => 'CRM/Core/DAO/',
17 );
18
19 static $_suffix = '.php';
20
21 static $_preCall = array(
22 'singleton' => '',
23 'business' => 'new',
24 'data' => 'new',
25 );
26
27 static $_extCall = array(
28 'singleton' => '::singleton',
29 'business' => '',
30 'data' => '',
31 );
32
33
34 static
35 function &create($className) {
36 $type = CRM_Utils_Array::value($className, self::$_classes);
37 if (!$type) {
38 CRM_Core_Error::fatal("class $className not found");
39 }
40
41 $file = self::$_prefix[$type] . $className;
42 $class = str_replace('/', '_', $file);
43
44 require_once ($file . self::$_suffix);
45
46 $newObj = eval(sprintf("return %s %s%s();",
47 self::$_preCall[$type],
48 $class,
49 self::$_extCall[$type]
50 ));
51
52 return $newObj;
53 }
54 }
55