From e7e5ef2b6c549d87ef23755f512c2fc2fd515413 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 31 Mar 2019 09:29:28 -0400 Subject: [PATCH] [NFC] Cleanup DAO factory classes for code standards --- CRM/Contact/DAO/Factory.php | 24 ++++++++++-------------- CRM/Core/DAO/Factory.php | 24 ++++++++++-------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/CRM/Contact/DAO/Factory.php b/CRM/Contact/DAO/Factory.php index 5f4432c2b5..8af2fc1ac4 100644 --- a/CRM/Contact/DAO/Factory.php +++ b/CRM/Contact/DAO/Factory.php @@ -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; } + } diff --git a/CRM/Core/DAO/Factory.php b/CRM/Core/DAO/Factory.php index 99242f9d38..519f4c4341 100644 --- a/CRM/Core/DAO/Factory.php +++ b/CRM/Core/DAO/Factory.php @@ -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; } + } -- 2.25.1