dev/core#128 Add deprecated warning helper function
[civicrm-core.git] / CRM / Core / Error.php
index a32df209640f523f957c6236db59c63459caf9db..ab491e8b81a2fe6daa0c2481881c0ba789478543 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.7                                                |
+ | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
@@ -1030,6 +1030,19 @@ class CRM_Core_Error extends PEAR_ErrorStack {
     return FALSE;
   }
 
+  /**
+   * Output a deprecated function warning to log file.  Deprecated class:function is automatically generated from calling function.
+   *
+   * @param $newMethod
+   *   description of new method (eg. "buildOptions() method in the appropriate BAO object").
+   */
+  public static function deprecatedFunctionWarning($newMethod) {
+    $dbt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
+    $callerFunction = isset($dbt[1]['function']) ? $dbt[1]['function'] : NULL;
+    $callerClass = isset($dbt[1]['class']) ? $dbt[1]['class'] : NULL;
+    Civi::log()->warning("Deprecated function $callerClass::$callerFunction, use $newMethod.", array('civi.tag' => 'deprecated'));
+  }
+
 }
 
 $e = new PEAR_ErrorStack('CRM');