Only use error handler and slowlog when debugging is enabled

This commit is contained in:
Kijin Sung 2016-02-13 11:29:09 +09:00
parent 6b4d69bcc2
commit 51f985c215
3 changed files with 56 additions and 32 deletions

View file

@ -308,7 +308,10 @@ class Debug
*/
public static function registerErrorHandlers($error_types)
{
set_error_handler('\\Rhymix\\Framework\\Debug::addError', $error_types);
if (Config::get('debug.enabled'))
{
set_error_handler('\\Rhymix\\Framework\\Debug::addError', $error_types);
}
set_exception_handler('\\Rhymix\\Framework\\Debug::exceptionHandler');
register_shutdown_function('\\Rhymix\\Framework\\Debug::shutdownHandler');
}
@ -346,6 +349,51 @@ class Debug
exit;
}
/**
* Check if debugging is enabled for the current user.
*
* @return bool
*/
public static function isEnabledForCurrentUser()
{
static $cache = null;
if ($cache !== null)
{
return $cache;
}
if (!Config::get('debug.enabled'))
{
return $cache = false;
}
$display_to = Config::get('debug.display_to');
switch ($display_to)
{
case 'everyone':
return $cache = true;
case 'ip':
$allowed_ip = Config::get('debug.allow');
foreach ($allowed_ip as $range)
{
if (Rhymix\Framework\IpFilter::inRange(RX_CLIENT_IP, $range))
{
return $cache = true;
}
}
return $cache = false;
case 'admin':
default:
$logged_info = \Context::get('logged_info');
if ($logged_info && $logged_info->is_admin === 'Y')
{
return $cache = true;
}
return $cache = false;
}
}
/**
* Get all debug information as an object.
*