mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-30 05:09:06 +02:00
ENHANCEMENT: Include the caller of the deprecated method in the notice that it throws.
This commit is contained in:
parent
4c93c3be19
commit
ad9bc59d10
@ -85,10 +85,13 @@ class Deprecation {
|
|||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @param $backtrace array - a backtrace as returned from debug_backtrace
|
* @param $backtrace array - a backtrace as returned from debug_backtrace
|
||||||
|
* @param $level - 1 (default) will return immediate caller, 2 will return caller's caller, etc.
|
||||||
* @return string - the name of the method
|
* @return string - the name of the method
|
||||||
*/
|
*/
|
||||||
protected static function get_called_method_from_trace($backtrace) {
|
protected static function get_called_method_from_trace($backtrace, $level = 1) {
|
||||||
$called = $backtrace[1];
|
$level = (int)$level;
|
||||||
|
if(!$level) $level = 1;
|
||||||
|
$called = $backtrace[$level];
|
||||||
|
|
||||||
if (isset($called['class'])) {
|
if (isset($called['class'])) {
|
||||||
return $called['class'] . $called['type'] . $called['function'];
|
return $called['class'] . $called['type'] . $called['function'];
|
||||||
@ -133,6 +136,10 @@ class Deprecation {
|
|||||||
if (!$level) $level = defined(E_USER_DEPRECATED) ? E_USER_DEPRECATED : E_USER_NOTICE;
|
if (!$level) $level = defined(E_USER_DEPRECATED) ? E_USER_DEPRECATED : E_USER_NOTICE;
|
||||||
|
|
||||||
// Then raise the notice
|
// Then raise the notice
|
||||||
|
if(substr($string,-1) != '.') $string .= ".";
|
||||||
|
|
||||||
|
$string .= " Called from " . self::get_called_method_from_trace($backtrace, 2) . '.';
|
||||||
|
|
||||||
user_error($caller.' is deprecated.'.($string ? ' '.$string : ''), $level);
|
user_error($caller.' is deprecated.'.($string ? ' '.$string : ''), $level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user