[NFC] Cleanup DAO factory classes for code standards
authorColeman Watts <coleman@civicrm.org>
Sun, 31 Mar 2019 13:29:28 +0000 (09:29 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 31 Mar 2019 13:29:28 +0000 (09:29 -0400)
CRM/Contact/DAO/Factory.php
CRM/Core/DAO/Factory.php

index 5f4432c2b50fd3298cdc4d312bfcdd376aaf61bc..8af2fc1ac41662a5fb504f9bcbe18e8cad239541 100644 (file)
@@ -5,7 +5,7 @@
  */
 class CRM_Contact_DAO_Factory {
 
-  static $_classes = array(
+  public static $_classes = [
     'Address' => 'data',
     'Contact' => 'data',
     'Email' => 'data',
@@ -17,39 +17,35 @@ class CRM_Contact_DAO_Factory {
     'Organization' => 'data',
     'Phone' => 'data',
     'Relationship' => 'data',
-  );
+  ];
 
-  static $_prefix = array(
-    'business' => 'CRM/Contact/BAO/',
-    'data' => 'CRM/Contact/DAO/',
-  );
-
-  static $_suffix = '.php';
+  public static $_prefix = [
+    'business' => 'CRM_Contact_BAO_',
+    'data' => 'CRM_Contact_DAO_',
+  ];
 
   /**
    * @param string $className
    *
    * @return mixed
    */
-  static function &create($className) {
+  public static function create($className) {
     $type = CRM_Utils_Array::value($className, self::$_classes);
     if (!$type) {
       return CRM_Core_DAO_Factory::create($className);
     }
 
-    $file = self::$_prefix[$type] . $className;
-    $class = str_replace('/', '_', $file);
-
-    require_once($file . self::$_suffix);
+    $class = self::$_prefix[$type] . $className;
 
     if ($type == 'singleton') {
       $newObj = $class::singleton();
     }
     else {
       // this is either 'business' or 'data'
-      $newObj = new $class;
+      $newObj = new $class();
     }
 
     return $newObj;
   }
+
 }
index 99242f9d38dfd9c24d1ad22205de702f22c212f4..519f4c4341aa6355d059f0809f0c0d42892027dd 100644 (file)
@@ -5,7 +5,7 @@
  */
 class CRM_Core_DAO_Factory {
 
-  static $_classes = array(
+  public static $_classes = [
     'Domain' => 'data',
     'Country' => 'singleton',
     'County' => 'singleton',
@@ -13,14 +13,12 @@ class CRM_Core_DAO_Factory {
     'GeoCoord' => 'singleton',
     'IMProvider' => 'singleton',
     'MobileProvider' => 'singleton',
-  );
+  ];
 
-  static $_prefix = array(
-    'business' => 'CRM/Core/BAO/',
-    'data' => 'CRM/Core/DAO/',
-  );
-
-  static $_suffix = '.php';
+  public static $_prefix = [
+    'business' => 'CRM_Core_BAO_',
+    'data' => 'CRM_Core_DAO_',
+  ];
 
   /**
    * @param string $className
@@ -28,25 +26,23 @@ class CRM_Core_DAO_Factory {
    * @return mixed
    * @throws Exception
    */
-  static function &create($className) {
+  public static function create($className) {
     $type = CRM_Utils_Array::value($className, self::$_classes);
     if (!$type) {
       CRM_Core_Error::fatal("class $className not found");
     }
 
-    $file = self::$_prefix[$type] . $className;
-    $class = str_replace('/', '_', $file);
-
-    require_once($file . self::$_suffix);
+    $class = self::$_prefix[$type] . $className;
 
     if ($type == 'singleton') {
       $newObj = $class::singleton();
     }
     else {
       // this is either 'business' or 'data'
-      $newObj = new $class;
+      $newObj = new $class();
     }
 
     return $newObj;
   }
+
 }