| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class CRM_Contact_DAO_Factory |
| 5 | */ |
| 6 | class CRM_Contact_DAO_Factory { |
| 7 | |
| 8 | static $_classes = array( |
| 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', |
| 20 | ); |
| 21 | |
| 22 | static $_prefix = array( |
| 23 | 'business' => 'CRM/Contact/BAO/', |
| 24 | 'data' => 'CRM/Contact/DAO/', |
| 25 | ); |
| 26 | |
| 27 | static $_suffix = '.php'; |
| 28 | |
| 29 | /** |
| 30 | * @param string $className |
| 31 | * |
| 32 | * @return mixed |
| 33 | */ |
| 34 | static function &create($className) { |
| 35 | $type = CRM_Utils_Array::value($className, self::$_classes); |
| 36 | if (!$type) { |
| 37 | return CRM_Core_DAO_Factory::create($className); |
| 38 | } |
| 39 | |
| 40 | $file = self::$_prefix[$type] . $className; |
| 41 | $class = str_replace('/', '_', $file); |
| 42 | |
| 43 | require_once($file . self::$_suffix); |
| 44 | |
| 45 | if ($type == 'singleton') { |
| 46 | $newObj = $class::singleton(); |
| 47 | } |
| 48 | else { |
| 49 | // this is either 'business' or 'data' |
| 50 | $newObj = new $class; |
| 51 | } |
| 52 | |
| 53 | return $newObj; |
| 54 | } |
| 55 | } |