Merge pull request #5179 from eileenmcnaughton/CRM-15798-master
[civicrm-core.git] / CRM / Core / BAO / Setting.php
index 185274762d1cd673b3d167f44f2e0635a4c86afb..c42b444a9927b6e0d4187ab095d1228aa77b6831 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -44,7 +44,7 @@
 class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
 
   /**
-   * Various predefined settings that have been migrated to the setting table
+   * Various predefined settings that have been migrated to the setting table.
    */
   const
     ADDRESS_STANDARDIZATION_PREFERENCES_NAME = 'Address Standardization Preferences',
@@ -79,11 +79,10 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param int $domainID
    * @param bool $force
    *
-   * @return boolean
+   * @return bool
    *   true if item is already in cache
-   * @static
    */
-  static function inCache(
+  public static function inCache(
     $group,
     $name,
     $componentID = NULL,
@@ -116,7 +115,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Allow key o be cleared
+   * Allow key o be cleared.
    * @param string $cacheKey
    */
   public static function flushCache($cacheKey) {
@@ -134,7 +133,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return string
    */
-  static function setCache(
+  public static function setCache(
     $values,
     $group,
     $componentID = NULL,
@@ -164,7 +163,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return CRM_Core_DAO_Domain|CRM_Core_DAO_Setting
    */
-  static function dao(
+  public static function dao(
     $group,
     $name = NULL,
     $componentID = NULL,
@@ -202,7 +201,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Retrieve the value of a setting from the DB table
+   * Retrieve the value of a setting from the DB table.
    *
    * @param string $group
    *   (required) The group name of the item.
@@ -217,10 +216,10 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @param int $domainID
    *
-   * @return mixed The data if present in the setting table, else null
-   * @static
+   * @return mixed
+   *   The data if present in the setting table, else null
    */
-  static function getItem(
+  public static function getItem(
     $group,
     $name = NULL,
     $componentID = NULL,
@@ -261,16 +260,14 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Store multiple items in the setting table
+   * Store multiple items in the setting table.
    *
    * @param array $params
    *   (required) An api formatted array of keys and values.
-   * @param null $domains
+   * @param array $domains Array of domains to get settings for. Default is the current domain
    * @param $settingsToReturn
    *
-   * @domains array an array of domains to get settings for. Default is the current domain
-   * @return void
-   * @static
+   * @return array
    */
   public static function getItems(&$params, $domains = NULL, $settingsToReturn) {
     $originalDomain = CRM_Core_Config::domainID();
@@ -306,15 +303,14 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
           }
         }
         else {
-          $setting =
-            CRM_Core_BAO_Setting::getItem(
-              $fields['values'][$name]['group_name'],
-              $name,
-              CRM_Utils_Array::value('component_id', $params),
-              NULL,
-              CRM_Utils_Array::value('contact_id', $params),
-              $domainID
-            );
+          $setting = CRM_Core_BAO_Setting::getItem(
+            $fields['values'][$name]['group_name'],
+            $name,
+            CRM_Utils_Array::value('component_id', $params),
+            NULL,
+            CRM_Utils_Array::value('contact_id', $params),
+            $domainID
+          );
         }
         if (!is_null($setting)) {
           // we won't return if not set - helps in return all scenario - otherwise we can't indentify the missing ones
@@ -328,7 +324,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Store an item in the setting table
+   * Store an item in the setting table.
    *
    * _setItem() is the common logic shared by setItem() and setItems().
    *
@@ -347,9 +343,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param int $domainID
    *
    * @return void
-   * @static
    */
-  static function setItem(
+  public static function setItem(
     $value,
     $group,
     $name,
@@ -369,7 +364,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Store an item in a setting table
+   * Store an item in a setting table.
    *
    * _setItem() is the common logic shared by setItem() and setItems().
    *
@@ -383,7 +378,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param int $createdID
    * @param int $domainID
    */
-  static function _setItem(
+  public static function _setItem(
     $metadata,
     $value,
     $group,
@@ -402,7 +397,12 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
 
     if (isset($metadata['on_change'])) {
       foreach ($metadata['on_change'] as $callback) {
-        call_user_func($callback, unserialize($dao->value), $value, $metadata);
+        call_user_func(
+          Civi\Core\Resolver::singleton()->get($callback),
+          unserialize($dao->value),
+          $value,
+          $metadata
+        );
       }
     }
 
@@ -463,7 +463,6 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @throws api_Exception
    * @domains array an array of domains to get settings for. Default is the current domain
    * @return array
-   * @static
    */
   public static function setItems(&$params, $domains = NULL) {
     $originalDomain = CRM_Core_Config::domainID();
@@ -593,8 +592,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
       return TRUE;
     }
     else {
-      list($class, $fn) = explode('::', $fieldSpec['validate_callback']);
-      if (!$class::$fn($value, $fieldSpec)) {
+      $cb = Civi\Core\Resolver::singleton()->get($fieldSpec['validate_callback']);
+      if (!call_user_func_array($cb, array(&$value, $fieldSpec))) {
         throw new api_Exception("validation failed for {$fieldSpec['name']} = $value  based on callback {$fieldSpec['validate_callback']}");
       }
     }
@@ -641,16 +640,16 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return array
    *   the following information as appropriate for each setting
-   * - name
-   * - type
-   * - default
-   * - add (CiviCRM version added)
-   * - is_domain
-   * - is_contact
-   * - description
-   * - help_text
+   *   - name
+   *   - type
+   *   - default
+   *   - add (CiviCRM version added)
+   *   - is_domain
+   *   - is_contact
+   *   - description
+   *   - help_text
    */
-  static function getSettingSpecification(
+  public static function getSettingSpecification(
     $componentID = NULL,
     $filters = array(),
     $domainID = NULL,
@@ -695,7 +694,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Load the settings files defined in a series of folders
+   * Load the settings files defined in a series of folders.
    * @param array $metaDataFolders
    *   List of folder paths.
    * @return array
@@ -714,7 +713,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Load up settings metadata from files
+   * Load up settings metadata from files.
    */
   public static function loadSettingsMetadata($metaDataFolder) {
     $settingMetaData = array();
@@ -755,7 +754,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
   }
 
   /**
-   * Look for any missing settings and convert them from config or load default as appropriate
+   * Look for any missing settings and convert them from config or load default as appropriate.
    * This should be run from GenCode & also from upgrades to add any new defaults.
    *
    * Multisites have often been overlooked in upgrade scripts so can be expected to be missing
@@ -836,7 +835,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    *
    * @return array
    */
-  static function valueOptions(
+  public static function valueOptions(
     $group,
     $name,
     $system = TRUE,
@@ -895,7 +894,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
    * @param int $userID
    * @param string $keyField
    */
-  static function setValueOption(
+  public static function setValueOption(
     $group,
     $name,
     $value,
@@ -1115,7 +1114,7 @@ AND domain_id = %3
   /**
    * Civicrm_setting didn't exist before 4.1.alpha1 and this function helps taking decisions during upgrade
    *
-   * @return boolean
+   * @return bool
    */
   public static function isUpgradeFromPreFourOneAlpha1() {
     if (CRM_Core_Config::isUpgradeMode()) {
@@ -1126,4 +1125,5 @@ AND domain_id = %3
     }
     return FALSE;
   }
+
 }