Skip to content
Snippets Groups Projects
Unverified Commit 8458d4b0 authored by Andreas Gohr's avatar Andreas Gohr Committed by GitHub
Browse files

Merge pull request #2409 from splitbrain/deprecationevent

introduce INFO_DEPRECATION_LOG event
parents 724970e6 85331086
No related branches found
No related tags found
No related merge requests found
......@@ -234,6 +234,24 @@ class Doku_Event_Handler {
}
}
}
/**
* Check if an event has any registered handlers
*
* When $advise is empty, both BEFORE and AFTER events will be considered,
* otherwise only the given advisory is checked
*
* @param string $name Name of the event
* @param string $advise BEFORE, AFTER or empty
* @return bool
*/
public function hasHandlerForEvent($name, $advise = '') {
if($advise) {
return isset($this->_hooks[$name . '_' . $advise]);
} else {
return isset($this->_hooks[$name . '_BEFORE']) || isset($this->_hooks[$name . '_AFTER']);
}
}
}
/**
......
......@@ -441,26 +441,40 @@ function dbglog($msg,$header=''){
* Log accesses to deprecated fucntions to the debug log
*
* @param string $alternative The function or method that should be used instead
* @triggers INFO_DEPRECATION_LOG
*/
function dbg_deprecated($alternative = '') {
global $conf;
if(!$conf['allowdebug']) return;
global $EVENT_HANDLER;
if(!$conf['allowdebug'] && !$EVENT_HANDLER->hasHandlerForEvent('INFO_DEPRECATION_LOG')) {
// avoid any work if no one cares
return;
}
$backtrace = debug_backtrace();
array_shift($backtrace);
$self = array_shift($backtrace);
$call = array_shift($backtrace);
$called = trim($self['class'].'::'.$self['function'].'()', ':');
$caller = trim($call['class'].'::'.$call['function'].'()', ':');
$msg = $called.' is deprecated. It was called from ';
$msg .= $caller.' in '.$call['file'].':'.$call['line'];
if($alternative) {
$msg .= ' '.$alternative.' should be used instead!';
$self = $backtrace[0];
$call = $backtrace[1];
$data = [
'trace' => $backtrace,
'alternative' => $alternative,
'called' => trim($self['class'] . '::' . $self['function'] . '()', ':'),
'caller' => trim($call['class'] . '::' . $call['function'] . '()', ':'),
'file' => $call['file'],
'line' => $call['line'],
];
$event = new Doku_Event('INFO_DEPRECATION_LOG', $data);
if($event->advise_before()) {
$msg = $event->data['called'] . ' is deprecated. It was called from ';
$msg .= $event->data['caller'] . ' in ' . $event->data['file'] . ':' . $event->data['line'];
if($event->data['alternative']) {
$msg .= ' ' . $event->data['alternative'] . ' should be used instead!';
}
dbglog($msg);
}
dbglog($msg);
$event->advise_after();
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment