Merge branch '4.4' into master
[civicrm-core.git] / CRM / Core / DAO / Factory.php
CommitLineData
6a488035
TO
1<?php
2class 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
0e6e8724 21 static function &create($className) {
6a488035
TO
22 $type = CRM_Utils_Array::value($className, self::$_classes);
23 if (!$type) {
24 CRM_Core_Error::fatal("class $className not found");
25 }
26
27 $file = self::$_prefix[$type] . $className;
28 $class = str_replace('/', '_', $file);
29
30 require_once ($file . self::$_suffix);
31
0e6e8724
DL
32 if ($type == 'singleton') {
33 $newObj = $class::singleton();
34 }
35 else {
36 // this is either 'business' or 'data'
37 $newObj = new $class;
38 }
6a488035
TO
39
40 return $newObj;
41 }
42}